How did things get this messed up? Windows has slowed to a crawl. Programs won't run. The free firewall that you installed last year won't update or uninstall itself. System Restore hasn't helped; neither have your assorted clean-up and anti-malware programs. Only one option remains: reinstall Windows and start from scratch. Yes, this is a scary, time-consuming job. Your PC may be unusable for a day or more. You could even lose all your data.

Let's face it: you would be wise to avoid this chore if it's at all possible. If someone in tech support tells you to do it, get a second opinion, and then a third. But sometimes reinstalling Windows is necessary, so here's our guide to making the process as safe and painless as possible.

Windows installation toolkit

You'll have to collect a few things before you can begin. The first is your recovery tool. If you're using the version of Windows that came preinstalled on your PC, that tool is probably in a hidden partition on the hard drive. That partition has the information necessary to restore the hard drive to its factory condition.

If your PC is a few years old, the recovery tool may instead be on one or more CDs or DVDs. Find the discs that came with your PC. The system's manual should say what kind of recovery tool came with the machine and, if it's on a partition, how to access it.

If you've upgraded Windows since you bought the machine, the upgrade disc is now your recovery tool.

If you can't find a recovery disc, and the PC has no hidden partition, contact the manufacturer to see what it can do for you. See How to install Windows without the restore CD on the next page.

After Windows installs, you'll have to reinstall all your programs. Collect the original discs or downloaded installation files, and all your licence numbers. You'll need an external hard drive with a capacity at least as large as your internal drive, and possibly a second one.

Finally, you'll need time. The best-case scenario for a Windows reinstall is a day; the worst: three or four days.

Back up everything

Things could go horribly wrong, so you need to make a backup of your hard drive and all the data stored on it.

Use cloning software to turn the external drive into an exact copy of your internal hard drive. We recommend cloning the drive using EaseUs Todo Backup. Alternatively, you can create an image backup if you prefer.

Easeus Todo Backup

Easeue Todo Backup is a program that lets you clone your hard drive. It also lets you create an image backup

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

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

Also take a look at our guide to the most suitable type of backup.

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, find the instructions for booting into the repair environment. Watch the screen as you turn on the PC; it might show a message such as 'Press F10 for Repair'. If it doesn't, check the manual or call your PC maker's tech 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. In Windows 7 or Vista, select the 'Custom (advanced)' option. In XP, at the 'Welcome to Setup' screen, press Enter to continue, not R for Repair.

Setting up Windows

You have a fresh Windows installation. This is where the hard work starts.

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

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 from the web. Alternatively, you can install the drivers from the clone you made.

If you reinstalled Windows from a disc that came from your PC maker and it's one that returns your hard drive to its factory condition, you probably have a lot of junk that you'll want to uninstall.

Windows 7 DVD

Windows 7 DVD: Your recovery disc will ask what kind of installation you want (advanced)

The uninstallers that come with Windows applications often leave remnants behind. Use Revo Uninstaller or Total Uninstall. These run the program's own uninstaller, then clean up the remainder.

Revo Uninstaller is free, but Total Uninstall does a better job with uninstalls that require a reboot. Revo Uninstaller doesn't work with 64bit programs, but Total Uninstall does.

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

Once you have everything installed, take some time to make Windows your own. Choose a new wallpaper, change your power and screensaver settings, and so on.

Upgrade Advisor

The final countdown

At this point, use image-backup software and an external hard drive to create an image of your internal hard drive's contents in its current everything-but-data state. Should you ever have to reinstall Windows again, you can use this backup as your recovery tool. Again, we recommend EaseUs Todo Backup, although other good programs are available. Whatever you use, be sure to create an emergency boot disc with it.

Restore your data

Now it's time to bring back your data. If you used a Windows 7 retail or upgrade DVD, the data is in a folder called C:\Windows.old. If you used a manufacturer's recovery tool, your files might be in a special folder, perhaps called C:\Backup. Otherwise, your data may no longer be on your hard drive.

If such a folder exists on your hard drive, open it in Windows Explorer and navigate to its User (Windows 7 and Vista) or 'Documents and Settings' folder (XP).

If the folder doesn't exist, you'll have to get it from the clone or image backup. Create a folder on the internal drive called Backup (it should be C:\Backup). Plug in the external drive with the clone, and copy the contents of that drive's User folder (Windows 7 and Vista) or 'Documents and Settings' folder (XP) to C:\Backup. Once the copying is done, unmount the external drive (using the System Tray's Safely Remove Hardware tool). Leave Windows Explorer open to the C:\Backup folder.

You should now have a Windows Explorer window open and displaying multiple folders, one for each user account. For convenience, let's call this window the 'backup location'.

Open a second Windows Explorer window and navigate to C:\Users in Windows 7 and Vista or C:\Documents and Settings in XP. We'll call this window the 'proper location', because it's where your data should be - and eventually will be.

Drag the folders you want to keep. Open the User folders in both the backup and proper locations. You will see additional folders, mostly the same ones, inside each. Drag some of the folders from backup to proper: Documents, Music, Pictures, and Videos. Their names may be prefaced with 'My'. Windows XP users needn't worry about the lack of Music, Pictures and Videos folders; they're in My Documents.

Don't move AppData (Windows 7 and Vista) or 'Application Data and Local Settings' (Windows XP), although you probably won't see these hidden folders anyway. Use your own judgment about the other folders, but be careful when merging any folders.

Eventually, you'll be able to delete your backup or Windows.old folder. But don't rush. Wait a few months until you're sure it contains nothing that you'll need again.

How to restore Windows without the restore CD

When Windows misbehaves and nothing else works, restoring the operating system via your restore CD or hidden hard-drive partition may be the last resort. So what do you do if you can't find the disc, or if a program that wrote to the boot sector scrubbed the special keyboard sequence for recovering everything and it no longer works?

The first thing to do is get in touch with your system's manufacturer and find out its policies. Some of the biggest PC manufacturers will sell you a recovery CD for around £20 to £30. Recovery media may not be available for older computers, but you should find software on the PC itself for creating a new recovery disc and you might be able to create an installation CD from files on your PC.

If your copy of Windows is currently in good working order, but you don't have a recovery tool, create your own with a good backup program. The resulting recovery disc is arguably better than a factory-issued backup tool, because it will restore a version of Windows that includes all your personalised settings.

See our guide to Best backup practice.