How to Repair Corruption in the Windows Operating System

When a Windows system is affected by storage corruption, you can use several Windows-based tools and techniques to make repairs.

Brien Posey

November 4, 2022

7 Min Read
How to Repair Corruption in the Windows Operating System
Alamy

When a Windows system suffers some level of storage corruption, it’s almost always better to replace the hard disk and reinstall the operating system from scratch rather than try to correct the corruption.

Of course, in the real world, countless logistical issues can prevent you from rebuilding a system from scratch. That being the case, I want to share some of my favorite techniques for fixing storage corruption.

For the purposes of this article, I am going to solely reference tools included in the Windows operating system. There are some great third-party repair tools available, but such tools are beyond the scope of this article.

Back Up the System

Before you even think about trying to repair a corrupt Windows machine, it is extremely important to back up the machine. Any of the repair techniques could conceivably cause further damage.

Additionally, the hard disk is for all practical purposes in an unknown state and further data loss could occur without warning. As such, it is imperative that you back up the system before taking any corrective action.

Addressing the Initial Corruption

I don’t want to get too deep into the subject of addressing initial corruption because it is something that I have written about at length on ITPro Today. Although my primary focus will be to address corruption that directly affects the Windows operating system, it is important to check for and fix disk errors prior to attempting to repair the operating system itself.

Related:Windows 11 Migration Guide: 4 Best Practices When Upgrading

When it comes to assessing the volume’s heath, there are two main commands that you should run (from an elevated PowerShell session):

Get-VolumeCorruptionCount CCHKDSK C: /F

The first of these commands checks the volume to see how many errors Windows knows about. Hopefully, this command will return a value of zero. If errors are reported, then at least you will have an idea about the state of the volume.

The second command uses the CHKDSK utility to repair various types of disk errors. It is worth noting that you may have to run CHKDSK multiple times because it does not always fix everything on the first try. Also note that CHKDSK cannot repair the system volume while Windows is running. As such, you will likely receive a message like the one shown in Figure 1, indicating that CHKDSK will run when the system is rebooted.

PowerShell screenshot indicates that CHKDSK will run when the system is rebooted

Windows Corruption 1-1

Figure 1. These are the two PowerShell commands that you should use to assess low-level corruption.

Resetting Windows

If you are having trouble with Windows (particularly if corruption has occurred), Microsoft commonly recommends that you reset Windows. The problem with resetting Windows is that some level of data loss almost always occurs.

Related:How to Reset Windows 10 on Decommissioned PCs

For example, in Figure 2, you can see that there are two options for resetting the PC. The first option (“Keep my files”) will retain most of your data (although some data loss is possible depending on where the data is stored). However, that option removes all your apps and your settings. The second option removes absolutely everything and is essentially the same as formatting your hard disk and starting over.

 Keep my files or remove everything

Windows Corruption 1-2

Figure 2. Resetting a PC will cause you to lose all your apps, and possibly your data.

Even though the two options do have good uses, they aren’t suitable when you need to fix the system without losing anything in the process. In such a situation, the best choice is probably to use the Deployment Image Service and Management Tool.

Using the Deployment Image Service and Management Tool

The Deployment Image Service and Management Tool (DISM.exe) is probably best known for its ability to create system images that can be used for unattended Windows installations. However, that’s not the DISM tool’s only job. It can also repair a corrupt Windows installation on Windows Server or on any system running Windows 7 or higher.

To use DISM to repair Windows, open an elevated PowerShell prompt and enter the following command:

DISM.exe /Online /Cleanup-Image /RestoreHealth

You can see what the repair process looks like in Figure 3. Incidentally, it is relatively common for this tool to stop responding and seem as though it has stopped working. This is especially true on slow computers, computers with a slow internet connection, or systems that are heavily damaged. My experience has been that the repair process will eventually resume. You simply need to give it however much time it needs to complete.

Screenshot of Deployment Image Service and Management tool and what the repair process looks like

Windows Corruption 1-3

Figure 3. This is how you use the DISM tool to fix windows.

Hopefully, the DISM tool was able to repair the corruption and your results look like what you see in Figure 4.

Screenshot of DISM tool showing that it has successfully cleaned up the Windows system

Windows Corruption 2-1

Figure 4. The DISM tool successfully cleaned up the system.

The problem with using the DISM tool to repair Windows corruption is that Windows must be at least somewhat functional for the repair process to work. If Windows is too badly damaged for a normal DISM cleanup operation, there is a workaround you can try: the System File Checker.

Running the System File Checker

The System File Checker is designed to go through all the Windows system files and detect corruption. If corruption is detected, it will pull a clean copy of the corrupt file from the system cache (C:WindowsSystem32dllcache) and use that clean file copy to replace the corrupt file.

You should not run the System File Checker until after the DISM tool has successfully run. It is also important to make sure that you do not close PowerShell while the System File Checker is running. Otherwise, you could cause further corruption.

To run the System File Checker, open an elevated PowerShell session and enter the following command:

SFC /ScanNow

You can see what the System File Checker looks like in Figure 5. Windows is displaying a message saying that the System File Checker found corrupt files and successfully repaired them. Had the tool not found any problems, it would have instead displayed a message saying that there were no integrity violations.

Screenshot of System File Checker showing that it found corrupt or missing Windows system files

Windows Corruption 2-2

Figure 5. The System File Checker found corrupt or missing Windows system files.

I recommend reviewing the log file (C:WindowsLogsCBSCBS.log) to see what the System File Checker repaired. It would also be a good idea to run the System File Checker again just to make sure that there are no additional errors present.

When Using DISM Isn’t an Option

Although the Deployment Image Servicing and Management Tool normally works well, there are some Windows problems that can prevent it from functioning properly. This can be especially true if the system’s problems are preventing an internet connection or if Windows Update is not working. The DISM tool uses Windows Update during the repair process.

If Windows is so badly damaged that DISM can’t repair it, there is a workaround available. For this you will need a second PC that is running the same version of Windows (including the same cumulative updates) as the PC that has failed. It also goes without saying that this “donor PC” will need to be in a healthy state.

Now download the Windows Media Creation tool that corresponds to the version of Windows you are using (there are separate tools for Windows 10 and Windows 11). When the tool launches, select the option to create Windows 11 Installation Media (do not select the Download Windows 11 Disk Image option). Next, accept the license agreement and make sure the “Use the Recommended Options for This PC” checkbox is selected, as shown in Figure 6. Click Next, then choose whether you want to create an ISO file or create the media on a USB flash drive. When you have made your selection, the tool will begin creating the Windows installation media.

Screenshot of Windows Media Creation Tool

Windows Corruption 2-3

Figure 6. This is what the Windows Media Creation Tool looks like.

When the installation media creation process finishes, you will need to insert the media into the PC that has problems. Now, you can rerun the DISM tool. The trick, however, is that you must tell the tool to use the installation media that you have just created rather than use Windows Update.

The actual command that you will need to use varies depending on where your installation media is located. For example, if the installation media were mounted in the PC’s D: drive, this would be the command:

DISM /Online /Cleanup-Image /RestoreHealth /Source:D:Sourcesinstall.wim

About the Author

Brien Posey

Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.

http://brienposey.com/

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like