14

I have two computers (win10x64 and win7x86) that completely freeze from time to time (black screen), and the only solution is to unplug them.

If I use DISM /Online /Cleanup-Image /RestoreHealth, how will it affect the currently installed software, or any windows configuration I might have changed. Will I need to start over ?

alfred
  • 555
  • 6
  • 13
  • 24
  • 1
    Any corrupt system files will be repaired. – Ramhound Jun 11 '18 at 13:54
  • 2
    The `/RestoreHealth` commands checks the backups of all system files contains within `%WinDir%\WinSxS` against known good copies from Windows Update servers. `SFC /ScanNow` checks all system files within `%WinDir%` _(excl. `WinSxS`)_ against the known good backup copies contained with `WinSxS`. There are times when `/RestoreHealth` may fail due to a dirty component store - run `DISM /Online /Cleanup-Image /StartComponentCleanup` prior to `/RestoreHealth`; however `/RestoreHealth` should always be ran prior to running `SFC`. – JW0914 Sep 21 '19 at 13:20

3 Answers3

14

Will I need to start over?

No, please see the below.

If I use Dism /Online /Cleanup-Image /RestoreHealth, how will it affect the currently installed software or any Windows configuration I might have changed?

It doesn't affect any installed software, as /Cleanup-Image deals with the Windows Component Store, not third-party programs, nor any customizations made to the OS:

  • The Component Store [%WinDir%\WinSxS] maintains a backup copy of all Windows system files and SFC and DISM manage two separate, vital pieces of the Component Store and OS, with SFC relying entirely upon what DISM manages:
    • DISM has two functions SFC relies upon, /StartComponentCleanup and /RestoreHealth, with /RestoreHealth relying solely upon /StartComponentCleanup
      • /StartComponentCleanup: Cleans the Component Store of any broken hard links
        It's imperative folks on Insider Builds run this regularly due to the frequent updates
      • /RestoreHealth: Verifies and fixes any corruption in the Component Store by verifying its system file backups against known good copies from the Windows Update servers through hash comparison; while an offline method does exist [below], it may not always fix the corruption
        • Windows 7: SUR [System Update Readiness] tool is used in lieu of this, as DISM did not have this functionality until Windows 8

    • SFC always assumes the Component Store is not corrupted and is why the DISM /RestoreHealth parameter (Windows 7: SUR) should always be run prior to SFC; not doing so allows a corrupted Component Store to potentially replace a good system file with a corrupted one or fail to fix corruption within %WinDir% altogether
      • /ScanNow: Verifies and fixes any corruption within %WinDir% by verifying against the known good copies within the Component Store through hash comparison

  • DISM and SFC must be executed in the order listed, as each relies upon the preceding step:
    (Windows 7: skip to #3)
    1. WinKey+ROpen: PowerShellCtrl+Shift+OK
      # Windows ≥8:
        # Online (while booted to Windows):
          Dism /Online /Cleanup-Image /StartComponentCleanup
      
        # Offline (while booted to WinPE/WinRE):
          Dism /Image:"D:\Windows" /Cleanup-Image /StartComponentCleanup
          # C: is usually not the drive letter in WinPE/WinRE
          # To ascertain: DiskPart → Lis Vol → Exit
      
      The Component Store should always be cleaned prior to running Windows Update, after an issue with Windows Update, and at least once a month, as it becomes dirty over time from updates occasionally breaking hard links

    2.  # Windows ≥8:
         # Online (while booted to Windows):
           Dism /Online /Cleanup-Image /RestoreHealth
      
         # Offline (while booted to WinPE/WinRE):
           Dism /Image:"D:\Windows" /Cleanup-Image /RestoreHealth
      
      Requires an internet connection, else the offline method will be required:
      • Use the install.esd||install.wim from the Windows Install ISO for the installed version (v1909, v2004, etc.):
        1. Create Windows 10 installation mediaDownload tool nowinstall on another PC
        2. Mount the ISO and determine the installed OS index [image] from the install.esd||install.wim:
          Dism /Get-ImageInfo /ImageFile:"Z:\sources\install.esd"
          
        3. Specify the index number at the end of the /Source parameter:
          # Online (while booted to Windows):
            # ESD:
             Dism /Online /Cleanup-Image /RestoreHealth /Source:esd:"Z:\sources\install.esd":6 /LimitAccess
          
            # WIM:
              Dism /Online /Cleanup-Image /RestoreHealth /Source:wim:"Z:\sources\install.wim":6 /LimitAccess
          
          # Offline (while booted to WinPE/WinRE):
            Dism /Image:"D:\Windows" /Cleanup-Image /RestoreHealth /Source:esd:"Z:\sources\install.esd":6 /LimitAccess
          

    3. Windows 7: Run the SUR tool
    4. Reboot; if errors are found, review %WinDir%\Logs\DISM\dism.log from the bottom up
      (Log files are easier to read and sift through via the Log syntax in VS Code)
      • Windows ≥8: %WinDir%\Logs\DISM\dism.log
      • Windows 7: %WinDir%\Logs\CBS\CheckSUR.log (How to fix SUR errors)

    5. # Online (while booted to Windows):
        Sfc /ScanNow
      
      # Offline (while booted to WinPE/WinRE):
        Sfc /ScanNow /OffBootDir=D:\ /OffWinDir=D:\Windows
        # C: is usually not the drive letter in WinPE/WinRE
        # To ascertain: DiskPart → Lis Vol → Exit
      

    6. Reboot; if errors are found, review %WinDir%\Logs\CBS\CBS.log from the bottom up

JW0914
  • 7,052
  • 7
  • 27
  • 48
  • It's the other way around. Sfc should be run *before* DISM. There have been multiple instances where sfc would wipe or corrupt a component, which is why DISM should be run afterward to restore it. – gargoylebident May 23 '21 at 08:00
  • @stackexchange_account1111 You clearly didn't read the man pages linked to or the first portion of the answer, as I explained in detail precisely how the process works, with your fundamental misunderstanding of what `Dism` and `Sfc` do being baffling considering this answer. – JW0914 May 23 '21 at 11:59
  • Good luck with corrupt dlls. – gargoylebident May 26 '21 at 08:59
  • You linked the man pages, an absolutely irrelevant piece of info because nowhere do they succeed in being the sources to your [overly prescriptive] claims. I want an MS man page that states dism should come before sfc. Anything less than that is pure speculation, which means you're not in the position be making the claims that you're making. – gargoylebident May 26 '21 at 09:03
  • First of all, I do not believe in "common" sense, and there are no implications there. I prefer to rely on empirical evidence and what's explicitly stated instead of mere speculations. Second of all, nowhere does it state sfc relies solely on component store in any of your links; heck it doesn't even mention winsxs anywhere in the sfc link or visa versa. Third of all, "it's simply more efficient to run Dism first" is a far cry from "should *always* be run prior to SFC" or "You should *never* run SFC /ScanNow before running DISM." – gargoylebident May 26 '21 at 23:01
  • @stackexchange_account1111 You're welcome to your opinion, however I've provided you with the facts and I'm not going to argue with you. Please do your due diligence by researching what the Component Store is, how it operates, and what occurs on the back end when running `Sfc` and `Dism` `/Cleanup-Image`, consulting the `CBS.log` and `DISM.log` for further evidence. If you still don't understand why it's important to run `Dism` `/Cleanup-Image` parameters prior to `Sfc`, I can offer you no further help and would recommend directly contacting Microsoft. – JW0914 May 27 '21 at 01:02
  • I'm not sure what opinions you're referring to (I for one have not expressed any). The fact is, your answer relies on pure speculation. And what was your response when someone questioned your speculations? "Do your research". "Just google it bro" is essentially what you said. You shouldn't flood your answer with links as if they are sources to your claims, because that creates a false sense that your claims are somehow backed by evidence. Instead, you should **source your claims**. Provide source to your claims or give the logical chain that you relied on to arrive at your conclusion. – gargoylebident May 27 '21 at 01:40
  • @stackexchange_account1111 It appears Microsoft does explicitly [state](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) the information provided in this answer is the correct way and concludes this conversation. – JW0914 May 27 '21 at 12:51
1

Run first sfc /scannow before doing DISM.

Theoretically, your configuration should not be affected by either of these commands. But in case of advanced degradation of your system, the repair itself might cause further damage. The chances for that are very slim, but do not skimp on backups before starting.

I suggest having a look at this answer of mine.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • 2
    You should _never_ run `SFC /ScanNow` before running `DISM /Online /Cleanup-Image /RestoreHealth` due to the fundamental purposes of both commands. `/RestoreHealth` checks the backups of all system files contains within `%WinDir%\WinSxS` against known good copies from Windows Update servers. `SFC /ScanNow` checks all system files within `%WinDir%` _(excl. `WinSxS`)_ against the known good backup copies contained with `WinSxS`. There are times when `/RestoreHealth` may fail due to a dirty component store - run `DISM /Online /Cleanup-Image /StartComponentCleanup` prior to `/RestoreHealth` – JW0914 Sep 21 '19 at 13:17
  • @JW0914: Although Microsoft also [recommends](https://support.microsoft.com/en-us/help/929833/use-the-system-file-checker-tool-to-repair-missing-or-corrupted-system) running DISM first, I'm not sure that I wouldn't first attempt to use the drivers on the computer before letting Microsoft modify them from its servers. My link also recommends running DISM only if SFC is unable to complete. – harrymc Sep 21 '19 at 15:33
  • DISM does nothing with drivers - its purpose is to ensure WinSxS houses known good copies of all system files contained within `C:\Windows`, which is what SFC uses for comparison & replacement. There's multiple reasons DISM should be ran prior to SFC, such as not doing so risks creating a larger problem that may not be immediately apparent if the component store is dirty _(i.e if it houses backups of the same file(s) for multiple Windows versions, which can occur with more regularity due to the bi-annual updates of Windows 10 - this will generally cause DISM to fail, but it's not guaranteed)_ – JW0914 Sep 22 '19 at 10:58
  • I haven't been able to find a single link on Microsoft Docs that provides an in-depth explanation of WinSxS, but [this article](https://www.thewindowsclub.com/winsxs-folder-windows-7-8) on The Windows Club does a decent job, whereas [this](https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/manage-the-component-store) Microsoft Docs article gives a basic explanation. – JW0914 Sep 22 '19 at 11:18
  • @JW0914: Thanks for this wealth of information, but I would still prefer not to let Windows modify anything in WinSxS before I tried SFC. I would try first to check against the Windows setup that used to work before improving it. – harrymc Sep 22 '19 at 11:28
  • 1
    I'm not understanding that logic, as WinSxS isn't there to improve Windows, it's there _(in this context)_ to maintain a backup of every Windows system file within the `%WinDir%`. For example, by running SFC first, the user has no idea if the backup files in WinSxS, which is what SFC relies upon for hash comparison to check for corruption, are not corrupted (DISM is what ensures this). DISM isn't going to upgrade Windows, it's just going to ensure the WinSxS backup matches the hash they should for the version of Windows installed (checked against Windows Update servers or a Windows image). – JW0914 Sep 22 '19 at 11:45
-1

Dism /Online /Cleanup-Image /RestoreHealth

and /or

sfc /scannow

Both will restore modified & corrupted system files. So, you can lose your overzealous windows customizations. Ideally, it should not change non-Microsoft programs & settings, still depending on the level of corruption!

  1. If you are so concerned about your customizations, You can just run scans

sfc /verifyonly

and /or

Dism /Online /Cleanup-Image /ScanHealth

They will just check the files without any repair process ( as here & here ). Analyze the log/ report & decide.

  1. DISM /Online /Cleanup-Image /RestoreHealth

is not available for win 7. ( DISM commands are very limited on win 7)

  1. & You can always make System Image ( Macrium Reflect ) before that!
  • **TO ADD** : One should run **sfc /scannow** multiple times & if the problem is not solved, he should consider running **DISM Restore Health** command. Then again run **sfc /scannow** to make sure that everything has got well. – Vineet Garg Jan 27 '20 at 06:32
  • This answer contains numerous factual inaccuracies - please see the following man pages: **(1)** [Manage the Component Store](https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/manage-the-component-store); **(2)** [Clean Up the WinSxS Folder](https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/clean-up-the-winsxs-folder); **(3)** [`/Cleanup-Image`](https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/repair-a-windows-image); and **(4)** [`/ScanNow`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/sfc) – JW0914 Nov 06 '20 at 14:23