Tip of the day: Learn to use environment variables

Environment variables contain information about the environment for the system and for the user who’s currently logged on. Knowing how to use these variables can save you time and keystrokes in batch files and shortcuts and at the command line. In addition, some programs use environment variables to determine where to store user data and temporary files. To use an environment variable in a command or a dialog box, you surround the variable name with percent signs; this tells Windows to look up the current value for that variable in the registry and use that value in the command or path where you entered it.

Two environment variables that I use regularly are %appdata% and %userprofile%. By typing either of these strings in the Run dialog box and pressing Enter, I can jump straight to the Application Data folder or the root of the User Profile folder for the currently logged-on user. I don’t need to know what drive Windows is installed on, and I don’t need to know the name of the current user. Similarly, typing cd %allusersprofile% at a command prompt switches to the All Users profile folder, where shared documents and settings are stored. In a default installation, the full path name is nearly twice as long: C:\Documents and Settings\All Users. You can also use environment variables to create shared shortcuts that work differently for each user. A shortcut that points to the %UserProfile%\My Documents folder, for instance, will always open the My Documents folder of the user who’s currently logged on.

Windows XP creates a group of default system variables, including several that define the location of Windows system files. Only an administrator can change a system variable. However, any user can add, edit, or remove user variables, which are exclusive to the user who created them and can be used in scripts and batch files.

To view and edit all variables, open the System option in Control Panel, and click the Environment Variables button on the Advanced tab. Click the New button to add a variable name and value, click the Edit button to change an existing variable, or click the Delete button to remove a variable.

Env_variables

You can also see a list of all currently defined environment variables by opening a Command Prompt window and entering the set command.

One more time: do not clean out your Prefetch folder!

Yet another Web site posted yet another “tip” today recommending that you clean out your Prefetch folder to improve performance of Windows. Arrrggghhh! I’ve written about this repeatedly (here and here and here, for instance), but the message doesn’t seem to be spreading very fast. Maybe this quote from “Misinformation and the Prefetch Flag” by Ryan Myers, a developer on Microsoft’s Windows Client Performance Team, will help:

XP systems have a Prefetch directory underneath the windows root directory, full of .pf files — these are lists of pages to load. The file names are generated from hashing the EXE to load — whenever you load the EXE, we hash, see if there’s a matching (exename)-(hash).pf file in the prefetch directory, and if so we load those pages. (If it doesn’t exist, we track what pages it loads, create that file, and pick a handful of them to save to it.) So, first off, it is a bad idea to periodically clean out that folder as some tech sites suggest. For one thing, XP will just re-create that data anyways; secondly, it trims the files anyways if there’s ever more than 128 of them so that it doesn’t needlessly consume space. So not only is deleting the directory totally unnecessary, but you’re also putting a temporary dent in your PC’s performance. [emphasis in original]

Bottom line: You will not improve Windows performance by cleaning out the Prefetch folder. You will, in fact, degrade Windows performance by cleaning out the Prefetch folder. I’ve done performance testing that establishes this definitively. In all the many sites that offer this bogus tip, I have yet to see a single piece of actual performance testing.

Oh, and for anyone who cites this TechRepublic article as a source, let me just say that it contains more serious factual errors than I can count. For instance:

As you boot your workstation or access programs on your workstation, XP’s prefetcher copies portions of those files to the Prefetch area of your hard drive.

That’s completely wrong. The files in the Prefetch folder contain lists of pages that that should be loaded when a program starts. Each file is essentially an index. Windows XP doesn’t copy portions of any files to the Prefetch folder.

When your workstation boots, XP prefetches portions of the files you use most frequently and has any application you’ve recently run waiting and ready to go.

This is equally absurd. If this were true, it would mean that Windows was actually loading into memory every program you’ve ever used, every time you start Windows. That’s not the way it works at all. When your PC starts up, Windows looks in the Prefetch folder to determine how best to load Windows. It doesn’t do a thing with the .pf files for applications (unless, of course, you’ve configured one of those apps to start up with Windows).

If you’re frequently using the same few applications over and over again, prefetching can greatly increase the apparent speed of a system. Rather than waiting for you to click an icon to start a program, and then loading all of the associated files, libraries, and pointers necessary to run the program, XP has all the components of your programs preloaded. When you click an icon to start the program, most of the hard work is already done.

The author just made this up. The .pf files don’t get used at all until you run a program. What actually happens when you click an icon is that Windows uses the information in the Prefetch folder to decide which program segments to load and in what order to load those pages. There’s plenty of documentation for this, including Ryan Myers’ article and this definitive article by Mark Russinovitch and David Solomon, Windows XP Kernel Improvements Create a More Robust, Powerful, and Scalable OS.

The drawback to prefetching is that XP will prefetch a program even if you use it only once or twice. XP will retain a copy of a portion of it in the Prefetch folder. From there, it will prefetch the program, taking resources from your workstation even though you may have no intention of ever using the program again.

Again, the author just pulled this out of who-knows-where. When you run a program, Windows creates a .pf file for it in the Prefetch folder. When you run the program again, Windows looks for this .pf file and uses it to determine how to load the program. The hash doesn’t contain any portion of the original program code. If you never run the program again, that .pf file never gets used, and in fact it gets deleted eventually.

I used to write for TechRepublic. I’ve tried to contact someone there to get them to correct this silly article but have yet to receive a response. It would be really, really great if some of the other sites that have propagated this urban legend would also correct it.

Tip of the day: Move your music, pictures, or video folders

In yesterday’s tip, I explained how to move the My Documents folder. To move the default folders that Windows XP uses for music, pictures, or video, you use a slightly different technique: Select the folder you want to move (My Music, My Pictures, My Video), hold down the right mouse button, and drag it to its new location. When you release the mouse button, choose Move Here. Windows XP automatically updates all references to the folder, including those in the Start menu.

This tip is especially useful if you have a large music or video collection. By moving the My Music or My Videos folder (or both) out of My Documents, you greatly reduce the size of your documents folder and make the task of backing it up faster and easier. A separate drive is the ideal location for bulky music and video files.

Tip of the day: Move the My Documents folder

The My Documents folder is the default location for your data files. If disk space is at a premium, you might choose to relocate this folder. For instance, if you add a second hard drive to your system, you might decide to use it exclusively for document storage. Here’s how to relocate all your data files to the new drive.

In Windows XP, click the Start button and then right-click the shortcut for My Documents. Click Properties. On the Target tab, click Move and choose the new location for the folder. (If necessary, you can create a new folder using the Browse dialog box.)

Move_my_docs

When you click OK, your document files are moved to the new location. Clicking the My Documents icon on the Start menu or in a common dialog box now takes you to this folder instead of the original location.

One caution: Be aware that some programs (notably Microsoft Outlook and Outlook Express) continue to store data in the hidden Application Data folders within your user profile. When you move your My Documents folder, these files remain in their original location. Make sure your backup strategy includes all your data files, not just those in the My Documents folder.

Frustrated by power supplies for your gadgets? Here are three easy fixes

The Your Tech Weblog (whose author really needs to provide some bio information) recently served up this mini-rant, which I found courtesy of Ernest Miller at Corante:

My current tech pet peeve: gadget power adapters that aren’t properly labeled.

An iRiver AC adapter, for instance, should read “iRiver” somewhere on its surface so it’s more easily associated with an iRiver music player. For tech journalists or geeks with multiple gadgets, this is a potentially nightmarish situation.

PalmOne, for shame; Sony-Ericsson, kudos; etc.

I understand how this happens. Cost-conscious hardware makers buy generic power supplies from low-cost providers. If they have the same power supplies custom made, including the company name and logo, the price goes up. A company that is struggling to be profitable or to avoid losses is going to be tempted to shave 50 cents off the cost of every device as a way to keep its bottom line under control.

The rest of this item contains a solution to this problem, a piece of troubleshooting advice that can help you match a generic power supply to its device, and a bonus tip that might help you reduce the number of power supplies you have to deal with.

Solution: Add your own labels to power supplies. When I get a new device that includes its own AC adapter, I slap a small sticker on it and use a Sharpie to write the device name. (The small labels for file folders usually work well for this purpose.) Update: The PC Doctor notes that the adapter block can get hot and cause the adhesive on the label to give up; he recommends attaching the sticker to the power cord instead.

Troubleshooting advice: Every AC adapter has to be labeled with some key information, which can help you sort out which device it goes with. You may need a bright light and a magnifying glass to read this information, but it’s there. Look for the following data points:

  • Input voltage. Most devices manufactured today for worldwide markets accept 110-240V AC, 50/60Hz, which means they can be used in just about any country with the proper plug adapter.
  • Output voltage. This will be expressed as a measurement in volts DC. The adapters for my Audiovox SMT5600 phone, my iRiver H120 music player, and my wife’s Creative Zen Micro all put out 5V DC. The battery charger for my Canon S500 digital camera puts out 4.2V DC.
  • Output current. This will be expressed in amperes or milliamperes (typically abbreviated A and mA, respectively). The labels on the adapters for the four devices I listed above show output currents of 1A, 2A, 1000mA, and 0.7A, respectively. (Note that 1A is the same as 1000mA, and 0.7mA could also be expressed as 700mA.)

Update: The PC Doctor recommends checking the polarity of the output jack as well. He has a good diagram here.

Armed with that information, I can check the technical specifications section of the manual for my device (Look it up online if you can’t find the printed manual) and find out what its input power requirements are. Those requirements, not surprisingly, should be a perfect match for the output of the power supply. When you find a generic power supply whose power output specs match your device’s input requirements, with a plug that is compatible with the jack on the device, you’ve got a winner. Slap a label on it.

Caution: Don’t assume that any AC-to-DC power converter with a matching plug will work in your portable device. Plugging in a mismatched converter is the surest way I know of to destroy a valuable device.

Bonus Tip: Don’t carry around multiple power supplies if you don’t need them. My wife’s Creative Zen Micro and my Audiovox SMT5600 Smartphone have custom power adapters that carry the company’s logo. But each one has absolutely identical power output specs (5V at 1000mA) and identical USB connectors. I can plug the music player into the phone’s power supply, or vice-versa.

Likewise, the adapters for my iRiver music player and my Creative Labs portable speakers are functionally identical. So, on my recent trip to Europe I carried only two power supplies for these four devices. After the music player was fully charged, I unplugged it and plugged in the phone. That simple step cut the hassle of carrying adapters (and constantly plugging/unplugging them) in half.

Tip of the day: Disabling “personalized” Office menus

Office XP and Office 2003 share a feature that is supposed to reduce clutter but instead increases confusion. I’m referring, of course, to the dreaded personalized menus and toolbars feature.

Using default settings, Office menus and toolbars change dynamically as you use each program. If there isn’t enough room on the screen for all the buttons on a toolbar, the program hides some buttons, making sure to display those you’ve used most recently. In the case of menus, the idea is to reduce clutter by showing you only the choices you’re likely to use instead of overwhelming you with a long menu containing many choices. Here’s what it looks like:

Personal_menus

See the chevron – the double arrow at the bottom of the menu? That’s your clue that there are more choices available on this menu than you can see. Click the chevron and the full menu drops down.

In practice, personalized menus are confusing to novices and experts. Why do the choices on the menus keep disappearing? Where is the option that’s supposed to be on the current menu? I recommend you configure Office to show full menus all the time. The good news is that one setting applies to all Office programs, so the fix is quick and easy. Here’s what to do:

  1. In any Office program, choose Tools, Customize.
  2. Click the Options tab in the Customize dialog box and select the Always show full menus check box.
  3. Click Close.

You’re done. (For a more complete discussion of the ins and outs of this feature and other aspects of the Office interface, pick up a copy of Special Edition Using Office 2003 or Special Edition Using Office XP and read Chapter 2, “Customizing the Office Interface.”)

What if you find yourself working at someone else’s computer, where you’re reluctant to tamper with their settings? Just double-click a top-level menu choice (File, Edit, and so on) when you use an Office program. This shortcut immediately opens the full menu, just as if you had clicked the chevron.

Sometimes there’s a reason things are hidden

Marc Orchant passes along a tip from PC Magazine that explains how to edit the registry to add “Send” and “Copy” commands to Windows Explorer and concludes with this comment:

After performing this tweak, you’ll have two new context menu commands: “Move to Folder” and “Copy to Folder”. Apparently this stuff is built into Windows but hidden for some mysterious reason.

Mysterious perhaps, but the reason is explained by no less an authority than Raymond Chen, the author of the original power toy for Windows, Tweak UI, in his February 2004 blog post, “What goes wrong when you add “Copy To” to the context menu”:

The “Copy to Folder” and “Move to Folder” options weren’t designed to be on the context menu. They were only meant to be placed in Explorer’s toolbar. (Right-click a blank space on your toolbar, select Customize, and pick “Move To” or “Copy To” from the list of available buttons.) If you add them to the context menu, you may notice that the “Copy To” and “Move To” dialogs start showing up when you really aren’t expecting them, for example, whenever you double-click an attachment in Outlook.

If you do the customization that Raymond suggests, you end up with toolbar buttons that look like this:

Move_copy_buttons

There are other tweaks widely publicized on various tip sites that have unpleasant side-effects as well. In this case, the effects are only annoying. If you want to add the context menus to Explorer, nothing bad will happen, but be prepared for an occasional annoyance!

(Oh, and Marc, how come I’m not in your blogroll?!)

Tip of the day: Enter international currency symbols in Office

Money makes the world go around, so why is there only one currency symbol (the dollar sign) on a standard U.S. keyboard?

To enter an international currency symbol in Word, Excel, or PowerPoint (or in Outlook’s message editor), you’ll need to memorize its four-digit ANSI character code and enter that code using the numeric keypad. Here are the codes for some common symbols:

Symbol Code
Euro ( € ) Alt+0128
Yen ( ¥ ) Alt+0165
Pound ( £ ) Alt+0163
Cent ( ¢ ) Alt+0162

To enter one of these symbols, first make sure that Num Lock is turned on. Then hold down the Alt key and enter the four-digit code using the numeric keypad. (If you use the numbers along the top of the keyboard, this won’t work.) When you release the Alt key, your symbol appears in the location you selected.

Want to see the codes for more symbols? From Word, Excel, or PowerPoint, choose Insert, Symbol. Select a symbol from the available list and look at the bottom of the dialog box to see its ANSI code.

(By the way, this technique works in any Windows program that supports ANSI characters. If you need to enter symbols in a non-Office program, try these codes and see if they work.)

Tip of the day: My three favorite Excel shortcuts

You don’t have to be an accountant to use Excel. It’s an ideal tool for managing any kind of data that falls into a neat rows-and-columns format, including everything from simple lists to complex budget reconciliations. These are my three favorite Excel shortcuts that most people don’t know about:

  1. Quick formatting Press Ctrl+1 to open the Format Cells dialog box, where you can change the way Excel displays text or numbers in a single cell or a range of cells. Even if you normally never use keyboard shortcuts, you should learn this one, which is universal and can save you a startling number of mouse clicks.
  2. Easy fractions Did you know you can enter a fraction in Excel? Normally, if you enter a numeric value that includes a forward slash, Excel converts it to a date or leaves it formatted as text. So, if you enter 3/8, Excel displays 8-Mar in the cell and stores the call’s value as the most recent occurrence of that date – in this case, 3/8/2005. If you enter 13/64, Excel just stores your entry as text, and you’re unable to use it in calculations. The secret for entering a fraction is to preface it with a zero. If you enter 0 3/8 in the cell, Excel drops the leading zero and displays the result in the cell as a fraction while storing its decimal equivalent, 0.375, as I’ve shown here.

    Excel_fraction

    If you enter a compound fraction that includes a whole number followed by a space and a fraction, Excel does the same. So 12 3/8 displays in the cell exactly as you enter it but becomes 12.375 in your worksheet. In either case, you can now use the entered value as part of any mathematical calculation.

  3. Instant zoom Use your mouse wheel to zoom in and out of your worksheet. Hold down the Ctrl key and spin the wheel down to zoom out; spin the wheel up to zoom back in. This shortcut has the same effect as using the Zoom control on the Standard toolbar or on the View menu. You can shrink the worksheet to as small as 10% of its actual size (good for getting a bird’s-eye view of the structure of a very large sheet, but lousy for editing) or up to 400% of actual size.

If you like these tips, you’ll find more just like them in Special Edition Using Microsoft Office 2003 and Special Edition Using Microsoft Office XP.

Tip of the day: Recover gracefully when an Office program crashes

If an Office XP or Office 2003 program (such as Word, Excel, or PowerPoint) stops responding to input, don’t panic. And don’t kill its entry in the Windows Task List. If you do that, you’ll lose any unsaved work. Instead, take a deep breath and use a well-hidden tool that even most experienced Office users don’t know about: the Application Recovery console.

Leave the stalled program running, click Start, and open the All Programs menu. Click Microsoft Office, Microsoft Office Tools, and finally Microsoft Office Application Recovery. This opens the Application Recovery console, which shows you all Office programs that are currently running.

App_recovery
[Click picture to see larger image]

For Word, Excel, PowerPoint, and other programs that you use to create and save individual documents, you’ll see the Recover Application button. When you click this button, you force the program to fail; the built-in recovery tools save any currently open files and then close the hung program, giving you the option to report the error to Microsoft. For programs such as OneNote and Outlook, which save data on the fly, this button isn’t available and you’re given the Restart Application option instead.

This feature can take most of the sting out of a sudden crash, especially when you use it in conjunction with the AutoRecover features in Word, Excel, and PowerPoint. AutoRecover saves a backup copy of your current document, worksheet, or presentation at intervals you specify (the default is every 10 minutes). To set AutoRecover options for one of these three programs, click Tools, Options and find its checkbox on the Save tab.