How to Use the CMD Virus Scan Command & Remove Malware
To run a full scan, type MpCmdRun.exe -Scan -ScanType 2
3 min. read
Updated on
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
Windows Defender is Windowsโ primary security tool, and while it has a graphical interface, you can also perform a CMD (Command Prompt) virus scan by using the methods from this guide.
How can I run a virus scan from CMD?
Use the MpCmdRun.exe -Scan command
- Press the Windows key + S, type in command prompt, right-click on the displayed result, and select Run as Administrator.
- In the User Account Control window, select Yes.
- In the CMD window, type in the following command to navigate to the Microsoft Antivirus Directory:
cd C:\ProgramData\Microsoft\Windows Defender\Platform\4.18*
- After navigating to the Windows Defender directory, type in the following to run a quick scan:
MpCmdRun.exe -Scan -ScanType 1
- If you want to run a full scan, type the following command and press Enter:
MpCmdRun.exe -Scan -ScanType 2
- If you need to stop the scan mid-way, press Ctrl + C to quit the scan.
You can also perform a scan of a custom path with the following command:
MpCmdRun.exe -Scan -ScanType 3 -File C:\Users\YOURNAME\Desktop
Just be sure to enter the desired path after -File in the command.
How do I run a Boot Sector scan
- Windows key + S, type in command prompt, right-click on the displayed result, and select Run as Administrator.
- Type in the following command and press Enter:
MpCmdRun.exe -Scan -ScanType -BootSectorScan
Running this command from the command prompt will scan your PCโs boot sector and remove any suspicious files found in the system. Here is a detailed guide on how to fix a corrupt boot sector.
How do I restore quarantined files using Command Prompt?
- While in the command prompt, type in the following to view the list of quarantined files:
MpCmdRun.exe -Restore -ListAll
- Then type the following command: MyApp.exe along with the name of the file you want to restore, and press Enter.
Can CMD remove a virus?
CMD can help you remove viruses. By using the command MpCmdRun.exe -Scan -ScanType 2, Microsoft Defender will perform a full scan of your system, quarantining any detected threats.
You can also delete them manually:
- Press Win + R, type
cmd
, and press Enter to open Command Prompt. - Go to the Folder. You’ll have to enter the following command and the folder’s path.
For this example, weโll use the Downloads folder.cd C:\Users\YourUsername\Downloads
. - To see all files, including hidden ones, type
dir /a
. - Once the file is visible, delete it by typing
del filename.ext
. Replace filename.ext with the actual file name. This command deletes the file from the folder.
How do I scan my PC for malware with Windows Security?
- Press Windows key + S, type windows security and click on Open.
- Select Virus & threat protection.
- Now choose Quick scan.
Alternatively, you can use the command line to start the scan more quickly.
Do keep in mind that issues with Defender can occur, and we wrote about what to do if Windows Defender real-time protection won’t turn on.
Many also reported that Windows Defender is not working at all, but that can be easily fixed.
With the steps outlined above, you can run any virus scan directly from CMD. For any other questions or potential solutions, let us know in the comments section below.
User forum
2 messages