Sub topic 8
Repairing system files with sfc and DISM
This chapter assumes you can open an elevated Command Prompt, read a command's help with /?, and run chkdsk from the previous chapter. You should also know that Windows keeps protected system files and a component store, and that a damaged system file can cause crashes, failed updates, or missing features.
What these tools repair
Two tools repair Windows system files, and they work at different layers.
- System File Checker (sfc) scans protected system files and replaces any that are corrupt or changed. It takes the good copies from the component store.
- Deployment Image Servicing and Management (DISM) repairs the component store itself, which is the local source of good file copies. It can also reach out to Windows Update or a Windows image to fetch replacements.
The dependency matters. If the component store is damaged, sfc has no clean source to copy from. In that case sfc fails or reports problems it cannot fix. You repair the store with DISM first, then run sfc again.
Running sfc
Open Command Prompt as administrator. Without elevation, sfc stops with a message that you must be an administrator.
sfc /scannowThe scan can take several minutes, so let it finish. The final message tells you what happened. The table lists the common results.
| Message | Meaning | Next step |
|---|---|---|
| Windows Resource Protection did not find any integrity violations | No damaged protected files were found | Look for another cause |
| Windows Resource Protection found corrupt files and successfully repaired them | Files were replaced from the component store | Restart and retest |
| Windows Resource Protection found corrupt files but was unable to fix some of them | The component store may be damaged, or the file is in use | Run DISM, then `sfc` again |
| Windows Resource Protection could not perform the requested operation | The scan could not start | Run from an elevated prompt, or try Safe Mode or the recovery environment |
Details of the scan go to C:\Windows\Logs\CBS\CBS.log. That file is large because it holds every servicing action. To pull out only the sfc lines, filter it:
findstr /c:"[SR]" %windir%\Logs\CBS\CBS.log > "%userprofile%\Desktop\sfclogs.txt"Other sfc switches exist, and sfc /? lists them.
/verifyonlyscans and reports but does not repair anything./scanfile=<path>scans one file and repairs it if needed./verifyfile=<path>verifies one file without repairing it.
Running DISM
DISM has many functions, such as managing images for deployment. For exam purposes, you need three servicing options under /Cleanup-Image. They run in order from light to thorough.
DISM /Online /Cleanup-Image /CheckHealth
DISM /Online /Cleanup-Image /ScanHealth
DISM /Online /Cleanup-Image /RestoreHealth/Onlinemeans the running operating system. Offline images use/Image:<path>instead./CheckHealthis quick. It only reports whether earlier operations already flagged the image as corrupt. It does not scan./ScanHealthscans the component store for corruption. It takes longer and does not fix anything./RestoreHealthscans and repairs. By default it downloads good files from Windows Update, so the computer needs a working internet connection.
/RestoreHealth can appear stuck at around 20 percent or another fixed value for a long time. This is normal. Wait unless there is no disk activity for a very long period.
Using a different repair source
If the computer is offline, or Windows Update cannot supply the files, point DISM at a known-good source with /Source. The source is usually a mounted Windows installation image. /LimitAccess stops DISM from contacting Windows Update.
DISM /Online /Cleanup-Image /RestoreHealth /Source:WIM:D:\sources\install.wim:1 /LimitAccessHere D: is the mounted installation media, and :1 is the image index inside the file. The source must match the installed Windows version and edition. A mismatched source is a common reason for a repair to fail.
Recommended order and common errors
- Run
sfc /scannowfrom an elevated prompt. - If it reports unfixable files, run
DISM /Online /Cleanup-Image /RestoreHealth. - Run
sfc /scannowagain, since it now has a good source. - Restart and test the original problem.
Common errors and what causes them:
- "You must be an administrator running a console session": the prompt is not elevated.
- DISM error 0x800f081f, "source files could not be found": Windows Update could not supply the files. Use
/Sourcewith matching media. - "Another servicing operation is in progress" or a pending-restart message: restart, then retry.
- Repeated
sfcfailures after DISM succeeds: suspect a failing disk. Runchkdsk C: /fas covered in the previous chapter, and check Event Viewer for disk errors.
Beyond the command line
If both tools fail, the exam expects you to know the next options. Windows can be reset or reinstalled through the recovery environment, and System Restore can roll back recent changes if a restore point exists. Back up user data before any reset. A repair install keeps files and apps, while a clean install does not.
Exercise
A technician runs sfc /scannow and gets "Windows Resource Protection found corrupt files but was unable to fix some of them." What should the technician run next, and what should be run after that?
Show answer
Run DISM /Online /Cleanup-Image /RestoreHealth to repair the component store, which is the source sfc uses. Then run sfc /scannow again and restart.
Exercise
A computer has no internet access, and DISM /Online /Cleanup-Image /RestoreHealth fails with error 0x800f081f. How can the technician supply good files?
Show answer
Use the /Source option with a mounted Windows installation image of the same version and edition, for example /Source:WIM:D:\sources\install.wim:1, and add /LimitAccess so DISM does not try Windows Update.
Exercise
Which DISM option only reports whether the image was already flagged as corrupt, without scanning or repairing?
Show answer
/CheckHealth. /ScanHealth scans without repairing, and /RestoreHealth scans and repairs.