How did things get this messed up? Windows has slowed to a crawl. Programs won't run. The free firewall you installed last year won't update or uninstall itself.

System Restore hasn't helped; neither have your assorted cleanup and antimalware programs. Only one option remains: Reinstall Windows and start from scratch.

I'm not going to lie to you--this is a scary and time-consuming job. Your PC may be unusable for a day or more. You could even lose all of your data.

And let's face it: You'd be wise to avoid this chore if at all possible. If someone in tech support tells you to do it, get a second opinion, and then a third.

If you have to reinstall--and sometimes it is necessary--here's how to make the process as safe and painless as possible.

Gather What You Need

You'll have to collect a few things before you can begin.

First, you'll need your recovery tool. What's that? If you're using the version of Windows that came on your PC, it's probably in a hidden partition on the computer's hard drive. That partition contains the information necessary to restore the hard drive to its factory condition.

Obviously, a hard-drive partition is not something you have to gather. But if your PC is a few years old, the recovery tool may be on one or more CDs or DVDs instead. Find the discs that came with your PC and see if anything looks promising. Alternatively, check the PC's manual to learn what kind of recovery tool came with the machine, and, if it's on a partition, how to access it.

If you upgraded Windows since you bought the PC--for instance, going from XP or Vista to Windows 7--the upgrade disc is now your recovery tool.

If you can't find a recovery disc, and the PC has no hidden partition (or offers no workable way to access that partition), contact the system manufacturer to see what they can do for you. Read "How Do I Restore Windows If I've Lost My Restore CD?" for details.

After Windows installs, you'll have to reinstall all of your programs. Collect all the original discs or downloaded installation files, and all of your license numbers.

You'll want an empty external hard drive with a capacity at least as large as your existing hard drive. Another external hard drive will come in handy later. That one doesn't have to be empty; you'll need only a part of it.

Finally, you'll need time. The best-case scenario for a reinstall is a day. The worst case: three or four days. You'll be spending a lot of that time waiting, so get a good book, too.

Back Up Everything

Things could go horribly wrong, so you need to make a backup of your entire drive. That way, you can at least return to where you were before the reinstall.

You also have to create a backup of your data, because the reinstall might destroy everything on your hard drive.

To manage both tasks, use cloning software to turn the empty external drive into an exact copy of your internal hard drive. I recommend EASEUS Todo Backup, which performs both image backups and cloning. For this job, I recommend the cloning because it will make the later job of restoring the data files easier. On the other hand, an image backup doesn't require an external drive all to itself (although it will require a large piece of one). Either option will work.

Be sure to create an emergency boot disc with EASEUS or whatever program you use to do the cloning. Without that, you may not be able to recover from a disaster.

Having a second backup of your data wouldn't hurt, especially since you're about to erase the original. If you don't already have another up-to-date backup, create one with whatever backup program you regularly use.

The Windows Reinstall

Exactly how you replace an old Windows installation with a new one depends on your recovery tool. If your PC came with a recovery partition on the hard drive, find the instructions for booting into the repair environment. Watch the screen as you turn on the computer; it might show a message such as 'Press F10 for Repair'. If it doesn't, check the manual or call technical support.

If your recovery tool is a disc, boot the PC from it.

Either way, follow the prompts.

If your recovery tool is an actual Microsoft Windows disc, the tool will ask what kind of installation to perform. You want the kind that gives you a fresh version of Windows. For Windows 7 or Vista, when the wizard asks about the type of installation, select the Custom (advanced) option. For XP, at the 'Welcome to Setup' screen, press Enter to Continue, not R for Repair.

Setting Up Windows

Congratulations: You have a fresh Windows installation. Now the hard work starts.

Remember that Windows will need updating. The patching will happen automatically, but if you want to get it out of the way, launch Windows Update and take care of it.

You'll have to reinstall at least some of your drivers. You can go back to the discs that came with your PC, printer, scanner, and so on, or you can download newer versions off the Internet. Alternatively, you can install the drivers off the clone you made before reinstalling.

If you reinstalled Windows from a vendor-supplied tool--one that returns your hard drive to its factory condition--you probably have a lot of junk on your computer. You'll have to uninstall the stuff you don't want.

The uninstallers that come with Windows applications are notoriously sloppy, leaving all sorts of remnants behind. I recommend either Revo Uninstaller or Total Uninstall. These programs run the application's own uninstaller, and then clean up the remaining mess.

The difference? Revo is free, but Total does a better job with uninstalls that require a reboot. Also, Revo doesn't work with 64-bit programs, while Total does.

Now that you've cleaned Windows of unwanted applications, you have to reinstall the programs you do want. Start with your security tools, and go from there. Don't try to install two programs at the same time, and if an installation requires a reboot, don't put that reboot off. Just do it.

Once everything is installed, take some time to make Windows your own. Pick your wallpaper, change your power and screensaver settings, and so on.