O'Reilly Network    
 Published on O'Reilly Network (http://www.oreillynet.com/)
 See this if you're having trouble printing code examples

O'Reilly Book Excerpts: Windows XP Hacks

Hacking Windows XP, Part 2

Related Reading

Windows XP Hacks
100 Industrial-Strength Tips & Tools
By Preston Gralla

by Preston Gralla

Editor's note: In this second installment in a two-part series of excerpts from Windows XP Hacks, author Preston Gralla demonstrates a Registry hack that adds the "Copy To Folder" and "Move To Folder" options to the right-click context menu--a timesaving trick for all you powers users out there. Preston also shows you how to surf anonymously without a trace, and how to tweak DNS settings for faster Internet access. These are just three of the one hundred such hacks you'll find in Windows XP Hacks.

Hack #29: A Power User's Hidden Weapon: Improve the Context Menu

The context menu is an often underused tool. But with these four additions and edits to the menu, it'll turn into a powerhouse that you'll use every day.

Windows Explorer's right-click context menu is one of the most basic of all XP tools; it provides many shortcuts for whenever you want to take action on a file or a folder. But the right-click menu is missing several basic options, such as choosing a specific folder to which you want to move or copy the file you've highlighted, rather than just cutting or copying the file. And when you install new applications, they have a nasty habit of adding their own options that you'll rarely use in the right-click menu.

The end result: a right-click context menu cluttered with options and lacking several basic useful ones. But you can extend the power of the menu with these four hacks.

Add "Copy To Folder" and "Move To Folder" Context Menu Options

I spend a lot of time copying and moving files between folders. More often than not, when I click on a file in Explorer, I want to copy or move it to another folder. That means I spend a good deal of time dragging files around or copying and pasting them.

But with a Registry hack, you can save yourself time: you can add Copy To Folder and Move To Folder options to the right-click context menu. When you choose one of the options from the menu, you browse to any place on your hard disk to copy or move the file to, and then send the file there. To add the option, run the Registry Editor [Hack #68] and go to HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers. shellex tells you it's a shell extension key that lets you customize the user shell or the interface. Create a new key called Copy To. Set the value to {C2FBB630-2971-11d1-A18C-00C04FD75D13}. Create another new key called Move To. Set the value to {C2FBB631-2971-11d1-A18C-00C04FD75D13}. Exit the Registry. The changes should take effect immediately. The Copy To Folder and Move To Folder options will appear. When you right-click on a file and choose one of the options, you'll be able to move or copy the file using a dialog box like the one shown in Figure 3-20.

Figure 3-20. Specifying a destination using the Copy To Folder option

Add and Remove Destinations for the "Send To" Option

The right-click context menu does have one useful option, Send To, which allows you to send the file to any one of a list of programs or locations-for example, to a drive, program, or folder.

It would be nice to edit that list, adding new locations and programs and taking away existing ones that you never use. How locations and programs show up on the menu appears to be somewhat of a mystery, but, in fact, it's easy to hack. Go to C:\Documents and Settings\<User Name>\SendTo, where <User Name> is your user name. The folder will be filled with shortcuts to all the locations you find on your Send To context menu. To remove an item from the Send To menu, delete the shortcut from the folder. To add an item to the menu, add a shortcut to the folder by highlighting the folder, choosing File → New → Shortcut, and following the instructions for creating a shortcut. The new setting will take effect immediately; you don't have to exit Windows Explorer for it to go into effect.

Open the Command Prompt from the Right-Click Menu

I began computing in the days of DOS, and I still can't give up the command prompt. When it comes to doing down-and-dirty tasks like mass deleting or renaming of files, nothing beats it. I find myself frequently switching back and forth between Windows Explorer and the command prompt.

Often, when using Windows Explorer, I want to open the command prompt at the folder that's my current location. That takes too many steps: opening a command prompt and then navigating to my current folder. However, there's a quicker way: add an option to the right-click context menu that will open a command prompt at your current folder. For example, if you were to right-click on the C:\My Stuff folder, you could then choose to open a command prompt at C:\My Stuff.

To add the option, run the Registry Editor [Hack #68], then go to HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell. Create a new key called Command Prompt. For the default value, enter whatever text you want to appear when you right-click on a folder-for example, Open Command Prompt. Create a new key beneath the Command Prompt key called Command. Set the default value to Cmd.exe /k pushd %L. That value will launch Cmd.exe, which is the XP command prompt. The /k switch puts the prompt into interactive mode. That is, it lets you issue commands from the command prompt; the command prompt isn't being used to issue only a single command and then exit. The pushd command stores the name of the current directory, and %L uses that name to start the command prompt at it. Exit the Registry. The new menu option will show up immediately. Note that it won't appear when you right-click on a file; it shows up only when you right-click on a folder.

TIP: While many of us like fussing around with the Registry rather than doing things the easy way, there's also a way to add this option to your right-click context menu without editing the Registry. Download and install a free copy of Microsoft's "Open Command Window Here" PowerToy from http://www.microsoft.com/windowsxp/pro/downloads/powertoys.asp. There are many other PowerToys on that page as well, and we cover them in other places in the book.

Clean Up the "Open With" Option

When you right-click on a file, one of the menu options is Open With, which provides a list of programs for you to open the file with. This list changes according to the type of file you're clicking. Depending on the file type, the lists can get long, because programs frequently add themselves to this list when you install them. Making things worse, there are times when the listed programs aren't applicable. For example, do you really want to open a .bmp bitmap graphics file with Microsoft Word? I think not.

You can clean up the Open With list by using a Registry hack. Run the Registry Editor and go to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts. Look for the file extension whose Open With list you want to edit and find its OpenWithList subkey-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.bmp\OpenWithList, for example. The subkey will have an alphabetical list of String values. Open each value and examine the value data. It will be the name of one of the programs on the Open With list (Winword.exe, for example). Delete any entry you don't want to appear. Don't delete the value data; delete the String value listing. In other words, if the value data for the a String value is Winword.exe, delete the entire string rather than just the value data. Exit the Registry.

Hack #39: Surf Anonymously Without a Trace

Feel like someone is watching you? On the Web, they probably are. Protect your privacy by using anonymous proxy servers.

Whenever you surf the Web, you leave yourself open to being snooped upon by web sites. They can track your online travels, know what operating system and browser you're running, find out your machine name, peer into your clipboard, uncover the last sites you've visited, examine your history list, delve into your cache, examine your IP address and use that to learn basic information about you such as your geographic location, and more. To a great extent, your Internet life is an open book when you visit.

Don't believe me? Head to http://www.anonymizer.com/snoop/test_ip.shtml. This page, run by the Anonymizer.com web service, tells you what your IP address and machine name are. And that's just a start. Click on the links on the left side, such as "Exposed Clipboard" and "Geographical Location." You'll see just a small sampling of what web sites can learn about you. Figure 4-10 shows a web site reporting on my geographic location. It's close enough; I live in Cambridge rather than Boston, and we generally require that people turn over their passports at the border.

Figure 4-10. The Anonymizer.com web service, exposing my current geographic location

Much of the reason why web sites can find out this information about you is due to the trusting nature of the Internet's infrastructure and is inherent in the open client/server relationship between your web browser and the servers on the sites you visit. But a lot of it also has to do with the ability to match up information from your PC to information in publicly available databases-for example, databases that have information about IP addresses.

The best way to make sure web sites can't gather personal information about you and your computer is to surf anonymously; use an anonymous proxy server to sit between you and the web sites you visit. When you use an anonymous proxy server, your browser doesn't contact a web site directly. Instead, it tells a proxy server which web site you want to visit. The proxy server then contacts the web site, and when you get the web site's page you don't get it directly from the site. Instead, it's delivered to you by the proxy server. In that way, your browser never directly contacts the web server whose site you want to view. The web site sees the IP address of the proxy server, not your PC's IP address. It can't read your cookies, see your history list, or examine your clipboard and cache, because your PC is never in direct contact with it. You're able to surf anonymously, without a trace.

There are two primary ways to use anonymous proxy servers. You can run client software on your PC, which does the work of contacting the server for you, or you can instead visit a web site, which then does the work of contacting the server.

Web-Based Anonymizer

If you don't want to go to the hassle of installing a client-and if you don't want to pay for software-to surf anonymously, go to Anonymizer.com (http://www.anonymizer.com/). In the box near the top of the page, type the name of the site to which you want to surf, and you'll head there anonymously. The proxy server will grab the page for you, and you'll get the page from the proxy server. You can also download a free version that runs as a toolbar in Internet Explorer. Surf as you would normally, and you'll visit those web sites directly. When you want to visit a site anonymously, click on a button and the anonymous proxy server will do the work for you.

A fuller version of the program is available on a subscription basis for $29.95 per year or $9.95 for three months. It blocks banner ads, stops pop ups, encrypts the URLs you type so that they can't be read by your ISP or network administrator, and adds a few other features as well. I don't find the extra features worth the money, but if these kinds of things are important to you, go ahead and spend the money. (To learn how to block pop-ups, turn to [Hack #33].)

WARNING: When you use this site, some sites will appear broken, with text and graphics displaying oddly. But it's a small price to pay for your privacy.

Get Software for Anonymous Surfing

If you prefer to install software, get Steganos Internet Anonym 5 (http://www.steganos.com/en/sia). In addition to anonymous proxy serving, it kills pop ups and manages cookies. You can try it for free, but if you want to keep it you'll have to pay $29.95.

See Also

Hack #44: Tweak DNS Settings for Faster Internet Access

A handful of DNS hacks for speeding up access to web sites.

You use the Web by typing in hostnames such as www.oreilly.com, but web servers and Internet routers can't understand plain English words, so they need those letters translated into numeric IP addresses. Whenever you type in a hostname, such as www.oreilly.com, it needs to be resolved to its IP address, such as DNS servers provide that name resolution automatically and behind the scenes as you surf the Web.

There are several ways you can hack your DNS settings so that you can get faster web access.

Speed Up Web Access with a HOSTS File

It takes time to send your request to a DNS server, have the server look up the proper IP address to resolve the name, and then send the IP address back to your PC. You can eliminate that delay by creating or editing a local HOSTS file on your own PC that contains hostnames and their corresponding IP addresses. When you create one, XP will first look into the HOSTS file to see if there's an entry for the hostname, and, if it finds it, it will resolve the address itself. That way, you won't have to go out to a DNS server and wait for the response before visiting a web site. The HOSTS file is a plain text file you can create or edit with a text editor like Notepad.

You'll find an existing HOSTS file in C:\System32\Drivers\Etc\HOSTS. The file has no extension; it is named only HOSTS. Open it in Notepad and enter the IP addresses and hostnames of your commonly visited web sites, like this:       oreilly.com
216.92131.107        simtel.net

Each entry in the file should be on one line. The IP address should be in the first column, and the corresponding hostname in the next column. At least one space should separate the two columns. You can add comments to the file by preceding the line with a #, in which case the entire line will be ignored by the file, or by putting a # after the hostname, in which case only the comment after will be ignored. You might want to comment on individual entries-for example:              gralla.com    #still in beta

When you're finished editing the file, save it to its existing location.

WARNING: Make sure to check your HOSTS file regularly and keep it up to date, or else you may deny yourself access to certain web sites. For example, if the http://www.gralla.com/ web site were to change its IP address, but your HOSTS file kept the old, incorrect address, your browser would not be able to find the site, because it would be given the wrong addressing information.

Adjust XP's DNS Cache Settings

As a way of speeding up DNS, when you visit a site, XP puts the DNS information into a local DNS cache on your PC. So, when you want to go to a site, XP first looks in its local DNS cache, called the resolve cache, to see whether the DNS information is contained there. That way, if it finds the information locally, it doesn't have to query a remote DNS server to find IP information. The cache is made up of recently queried names and entries taken from your HOSTS file.

The cache contains both negative and positive entries. Positive entries are those in which the DNS lookup succeeded, and you were able to connect to the web site. When XP looks in the cache, if it finds a positive entry, it immediately uses that DNS information and sends you to the requested web site.

Negative entries are those in which no match was found, and you end up getting a "Cannot find server or DNS Error" in your browser. Similarly, when XP looks in the cache and finds a negative entry, it gives you the error message without bothering to go out to the site.

Negative entries can lead to problems. When you try to make a connection to a site that has a negative entry in your cache, you'll get an error message, even if the site's problems have been resolved and it's now reachable.

You can solve this problem, though, using a Registry hack. By default, XP caches negative entries for five minutes. After five minutes, they're cleared from your cache. But if you'd like, you can force XP not to cache these negative entries, so that you'll never run into this problem. Run the Registry Editor [Hack #68] and go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters. Create a new DWORD value with the name NegativeCacheTime and give it a value of 0. (The value may already exist. If it does, edit its value to 0.) The DWORD determines how much time, in seconds, to keep negative entries in the DNS cache. If you like, you can have the entries stay alive for one second by giving it a value of 1.

After you're done editing, exit the Registry. To make the change take effect, restart your computer, or flush your cache by issuing the command ipconfig /flushdns at a command prompt.

TIP: For more information about using ipconfig, see [Hack #52].

That command will flush your DNS cache-all the entries, both positive and negative, will be flushed, and it will be empty until you start visiting web sites. Negative entries, however, will not be added to the cache if you've given the DWORD a value of 0.

You can also use the Registry to control the amount of time that positive entries are kept in the DNS cache. By default, they are kept for 24 hours. To change the default, go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters again and create a DWORD value called MaxCacheEntryTtlLimit. (If it's already present, just edit the value.) For the value, enter the amount of time you want the entry to remain, in seconds, making sure to use Decimal as the base.

Fix DNS Problems

Sometimes when you can't connect to a web site, the cause is a DNS problem. There are things you can do to solve these problems, though. If you're having trouble connecting, to find out if DNS is a potential culprit first ping [Hack #52] the site to which you can't connect, by issuing the ping command like this at the command prompt or Run box, like this:

ping www.zdnet.com

If the site is live, you'll get an answer like this:

Pinging www.zdnet.com [] with 32 bytes of data:

Reply from bytes=32 time=119ms TTL=242
Reply from bytes=32 time=79ms TTL=242
Reply from bytes=32 time=80ms TTL=242
Reply from bytes=32 time=101ms TTL=242

Ping statistics for
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 79ms, Maximum = 119ms, Average = 94ms

If it's not, you'll get a response like this:

Ping request could not find host. Please check the name and try again.

If you ping a site and it's live, but you can't connect to it with your browser, a DNS problem might be the reason. If you suspect you're having a DNS problem, take the following actions:

Preston Gralla is the author of Windows Vista in a Nutshell, the Windows Vista Pocket Reference, and is the editor of WindowsDevCenter.com. He is also the author of Internet Annoyances, PC Pest Control, Windows XP Power Hound, and Windows XP Hacks, Second Edition, and co-author of Windows XP Cookbook. He has written more than 30 other books.

Return to the O'Reilly Network.

Copyright © 2009 O'Reilly Media, Inc.