All commands should be used from an elevated command prompt, i.e. with administrator rights.
Windows xp main user was usually an administrator (IIRC).
From windows vista onwards, you need to perform a special sequence to open an elevated command prompt, even in an administrator account.
The simpler method that should work for all windows versions (I didn't tried with xp ) should be: click windows start, in the searchbox type cmd, press and hold ctrl and shift keys, press enter, release all keys, respond yes to the user account control window that should appear (from vista onwards).
You will find here a brief panoramic of windows tools that allow you to perform a basic clean-up, check-up and repair of your machine.
Cleanmgr (Clean manager?)
(Command available since windows 2000)
Also known as Disk Cleanup (its GUI version), this tool exists since windows 2000 (at least) and its aim is to remove unnecessary files from your drives.
You can run it anytime you desire. In the command prompt, type
A cleanmgr window will be presented, in which you can choose the items to be deleted.
I'd select them all, but you can choose to avoid some options.
To start the cleanup, you need to launch this other command:
And the cleanup will start: wait until it finishes.
The sageset/sagerun options allow up to 65535 combinations and their aim is to be used in a scheduled task, that should be run with the highest privileges.
Windows 10 Storage Sense
(Command available since windows 10 version 1709)
This is the new tool to remove unnecessary files on windows 10 machines only.
It seems it is available since Windows 10 Fall Creators Update - Windows 10 version 1709 (2017 September = 1709) - Redstone 3 - 10 version 1709 build 16299.
With Windows 10 October 2018 Update - Windows 10 version 1809 (2018 September = 1809) - Redstone 5 - 10 version 1809 build 17763, the cleanmgr tool is declared as deprecated (abandoned).
You can find it in settings, system, storage, free up space now: windows will scan the drive and you will choose what items have to be deleted.
It is also possible to make it run automatically on its own, changing the sliding bar under storage sense from off to on; and change some basic settings about it in Change how we free up space automatically.
DISM - check, scan, restore the health of your OS
(switches available from Windows 8 onwards)
The following command lasts a few of seconds (or even less) and check your OS health:
Dism /Online /Cleanup-Image /CheckHealth
- healthy: "No component store corruption detected."
- repairable: "The component store is repairable."
- non-repairable: "The component store is not repairable." (I'm not sure if this is the exact error message)
The following command lasts some tenth of minutes and scan your OS health (without trying a repair):
Dism /Online /Cleanup-Image /ScanHealth
The following command lasts some tenth of minutes and restore your OS health (if possible):
Dism /Online /Cleanup-Image /RestoreHealth
SFC (System File Checker)
(Command available since windows 98)
This tool allows you to "scan Windows and restore your files" (quoted from Microsoft webpage about sfc).
Launch the following command and windows will check and eventually will repair system files:
If it will find no integrity violations or if it will repair all system files, no problem.
Otherwise, post a new topic in our windows update sub-forum and the windows update experts will help you to fix the corrupted files.
(Command available since windows 95)
This command sorts the files in your drives.
You'll rarely should use this command given that windows (since Vista) automatically defrag each partitions every week.
You might use it when you feel slowdowns in your machine (it is "sluggish"), after you used the previous tools.
It changed from windows xp to windows 10; currently, the following command works (for sure) in windows 10:
defrag c: /h
It means "Sort files in c: with a higher priority" (it runs usually in low priority, the /h switch will make it run at normal).
CHKDSK (Check Disk)
(Command available since DOS)
Some years ago (circa, in DOS era up to Win2000 era), a partition and a disk were almost the same thing.
But now, it checks the partitions.
You might use it after the defragmenter, when you perceive that there are problems in your machine.
Launch the following command and windows will check and eventually will repair the partition inconsistencies:
chkdsk c: /b
It means "Check the c: partition (the main partition, usually), fix its errors, locate bad sectors and recover readable information, re-evaluate bad clusters on the volume.
I.e., /f and /r switches are implied by the /b switch.
It will ask to reboot the machine (to start, run and complete this check).