How to use the command sfc (with examples)
- Windows
- December 25, 2023
The sfc
command is a built-in Windows command that scans the integrity of Windows system files. It can be used to check for and fix any corruption or missing files in the Windows operating system. This article will provide examples of various use cases of the sfc
command.
Use case 1: Display information about the usage of the command
Code:
sfc
Motivation: This use case is useful when you want to quickly check the general usage and available options of the sfc
command without performing any specific scan or repair operation.
Explanation: Running the sfc
command with no additional arguments will display general information about the usage, options, and expected behavior of the command.
Example output:
Microsoft Windows [Version 10.0.19042.1165]
(c) Microsoft Corporation. All rights reserved.
Usage: sfc [/scannow] [/verifyonly] [/scanfile=<file>] [/verifyfile=<file>]
[/offbootdir=<offline-boot-directory>] [/offwindir=<offline-windows-directory>]
Scans integrity of all protected system files and repairs files with
problems when possible.
/scannow Scans integrity of all protected system files and repairs files
with problems when possible.
/verifyonly Scans integrity of all protected system files. No repair
operation is performed.
/scanfile Scans integrity of the specified file and repairs a file with
problems when possible.
/verifyfile Scans integrity of the specified file. No repair operation is
performed.
/offbootdir Specifies the offline boot directory containing the
system to be repaired. The default is the current system.
/offwindir Specifies the offline windows directory containing the
system to be repaired. The default is the current system.
Use case 2: Scan all system files and, if possible, repair any problems
Code:
sfc /scannow
Motivation: This use case is useful when you suspect that there are corrupted or missing system files in your Windows operating system. Running sfc /scannow
will scan all protected system files and automatically attempt to repair any issues found.
Explanation: The /scannow
argument tells the sfc
command to scan all protected system files and attempt to repair any problems encountered.
Example output:
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.
Windows Resource Protection found corrupt files and successfully repaired them.
For online repairs, details are included in the CBS log file located at
windir\logs\CBS\CBS.log. For example, C:\Windows\Logs\CBS\CBS.log. For offline
repairs, details are included in the log file provided by the /OFFLOGFILE flag.
Use case 3: Scan all system files without attempting to repair any
Code:
sfc /verifyonly
Motivation: This use case is useful when you want to check the integrity of all protected system files without making any changes or repairs. Running sfc /verifyonly
will perform a thorough scan without modifying any files.
Explanation: The /verifyonly
argument tells the sfc
command to only scan all protected system files but not perform any repair operations.
Example output:
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.
Windows Resource Protection did not find any integrity violations.
Use case 4: Scan a specific file and, if possible, repair any problems
Code:
sfc /scanfile=C:\Windows\System32\file.dll
Motivation: This use case is useful when you suspect that a specific system file is corrupted or missing. Running sfc /scanfile
with the file path as an argument will scan the specified file and attempt to repair any issues found.
Explanation: The /scanfile
argument followed by the path to the file tells the sfc
command to scan the specified file and attempt to repair any problems encountered.
Example output:
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.
Windows Resource Protection found corrupt files and successfully repaired them.
For online repairs, details are included in the CBS log file located at
windir\logs\CBS\CBS.log. For example, C:\Windows\Logs\CBS\CBS.log. For offline
repairs, details are included in the log file provided by the /OFFLOGFILE flag.
Use case 5: Scan a specific file without attempting to repair it
Code:
sfc /verifyfile=C:\Windows\System32\file.dll
Motivation: This use case is useful when you want to check the integrity of a specific system file without making any changes or repairs. Running sfc /verifyfile
with the file path as an argument will perform a scan on the specified file without modifying it.
Explanation: The /verifyfile
argument followed by the path to the file tells the sfc
command to only scan the specified file and not perform any repair operations.
Example output:
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.
Windows Resource Protection did not find any integrity violations.
Use case 6: When repairing offline, specify the boot directory
Code:
sfc /offbootdir=D:\ /scannow
Motivation: This use case is useful when you need to repair the Windows operating system offline, such as when it fails to boot normally. Running sfc /offbootdir
with the boot directory path as an argument will allow the sfc
command to repair the offline system.
Explanation: The /offbootdir
argument followed by the path to the offline boot directory sets the directory where the offline system to be repaired is located.
Example output:
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.
Windows Resource Protection found corrupt files and successfully repaired them.
For online repairs, details are included in the CBS log file located at
windir\logs\CBS\CBS.log. For example, C:\Windows\Logs\CBS\CBS.log. For offline
repairs, details are included in the log file provided by the /OFFLOGFILE flag.
Use case 7: When repairing offline, specify the Windows directory
Code:
sfc /offwindir=D:\Windows /scannow
Motivation: This use case is similar to the previous one, but it allows you to specify the location of the offline Windows directory. Running sfc /offwindir
with the Windows directory path as an argument will help repair the offline system.
Explanation: The /offwindir
argument followed by the path to the offline Windows directory sets the directory where the offline system to be repaired is located.
Example output:
Beginning system scan. This process will take some time.
Beginning verification phase of system scan.
Verification 100% complete.
Windows Resource Protection found corrupt files and successfully repaired them.
For online repairs, details are included in the CBS log file located at
windir\logs\CBS\CBS.log. For example, C:\Windows\Logs\CBS\CBS.log. For offline
repairs, details are included in the log file provided by the /OFFLOGFILE flag.
Conclusion:
The sfc
command is a powerful tool for scanning and repairing corrupted or missing system files in the Windows operating system. It provides several options to target specific files or repair offline systems. Understanding the various use cases of the sfc
command can help users effectively troubleshoot and maintain the integrity of their Windows systems.