Edit this Page

GothPanda

Sometimes, I make things. Even rarer, I manage to write things down.


Using DISM/SFC to repair a corrupted Windows install

Sometimes, your computer just runs into an issue that doesn't seem to make any sense. When all else fails, it can help to try to repair any damaged or corrupted files in your Windows install. Thankfully, the tools to do this have become built into Windows.

The Commands

If you're just here for the commands, they are:

dism /Online /Cleanup-Image /RestoreHealth
sfc /scannow

You'll want to run them from Windows Terminal, run as an Administrator. You can get one real quick by right-clicking on the Start Button, and clicking on "Terminal (Admin)".

How it all works

DISM

The Deployment Image Servicing and Management tool, or DISM for short, is a tool that's been built into Windows starting from about Windows Server 2012 that's used to service and prepare Windows system images.

When you run this tool on the running copy of Windows, it instead works with the Component Store directly. The Component Store might also be called the Windows "Side-by-Side" folder, and is usually located at C:/Windows/WinSxS. This folder has multiple versions of every DLL file and library that Windows has installed so that programs can use whatever version of a library that they need. Fortunately, this store of files are also the files that system itself uses to run. DISM is able to go through all of the files in this directory, and see if any files might be damaged or corrupted. By default, it will reacquire any of those files by redownloading them through the Windows Update service.

The /Online option tells DISM to check the Component Store on the copy of Windows that's currently running. If you need to reference an offline image, or that's mounted to a drive or folder, you can use the /Image:C:\offline option, where "C:\offline" is the drive and folder where the copy of Windows is mounted.

The /Cleanup-Image option tells DISM that we'd like to do maintenance and repair operations on the image.

The /RestoreHealth option tells DISM that we'd like to try to make repairs to the image, if possible. You can also use the options /CheckHealth to just scan to see if anything in the image has already been marked as damaged or corrupted, or use the /ScanHealth option to actually go through and check for corruption, but without actually repairing it. These options can be useful if an application has already run into a problem, or if you're just wanting to check the image real quick without going through the full repair process.

If for some reason you're not able to access Windows Update, like the computer is offline, or the Windows Update service is broken, you can instead point DISM to an alternate source of known good files. Usually, this will be something like an Install ISO, DVD, or USB. In order to do that, you'll use the option /Source:D:\sources\, where "D:\sources" is the drive that has the ISO or USB installer mounted, and sources is the folder with the files. Microsoft also points out that you can use this with:

Finally, if for some reason you need to prevent DISM from using Windows Update as a source, like if the Windows Update service isn't working properly on the computer, use can use the /LimitAccess command to tell it to ignore Windows Update.

SFC

The System File Checker, or SFC is a much older tool, dating back to as early as Windows 98. This tool checks the actual system files that Windows is using, and will replace them from a known good copy if they're found to be damaged or altered. In modern versions of windows, this known good copy might come from the Side by Side folder, so that's why you'll usually run into the recommendation to run this tool after DISM.

Usually, you'll just want the /scannow option, but you might also need to use the /offbootdir=d: or /offwindir=d:\windows to specify the boot drive and Windows installation if you're running it against a copy of Windows that's not actively running.

See Also

https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/repair-a-windows-image?view=windows-11

https://support.microsoft.com/en-us/topic/use-the-system-file-checker-tool-to-repair-missing-or-corrupted-system-files-79aa86cb-ca52-166a-92a3-966e85d4094e

« Previous