How to Run a Virus Scan from CMD

You can run various scans to locate virus on CMD

Reading time icon 4 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

Key notes

  • If you want to run a virus scan from CMD, you will see that it’s pretty easy.
  • Ensure you type in the correct commands into the Command Prompt app else youโ€™ll trigger the command not recognized error.
  • Running full scans provide broader information on the security state of your system.
command prompt virus scan

Windows Defender is Windowsโ€™ primary security tool. Sometimes, you might not have access to your GUI and must access Windows Defender directly from the Command Prompt. This article will provide you with the best ways to run a virus scan from CMD.

Can I locate the virus using Command Prompt?

The short answer is yes; you can determine if your system is infected with a virus directly from Command Prompt. Virtually, all actions you carry out in your GUI can be done using the command line e.g Resetting your IP Address, searching for files, changing DNS servers, etc.

Locating viruses and malware using Command Prompt isnโ€™t as intuitive as when done on the GUI. However, with the right steps and guidance, you can achieve exact results on the terminal you usually get on the GUI. 

One thing to note about operating your antivirus tool from the command line is that scans generated from the terminal will only provide you with a report of the viruses found in the system; it wonโ€™t delete or quarantine them, unlike on the GUI.

After discovering the virus from the Command Prompt app, you must delete it manually.

How can I run a virus scan from CMD?

  1. Press the Windows key + S, type in command prompt, right-click on the displayed result, and select Run as Administrator.
  2. In the User Account Control window, select Yes.
  3. 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*
  4. After navigating to the Windows Defender directory, type in the following to run a quick scan: MpCmdRun.exe -Scan -ScanType 1
  5. If you want to run a full scan, type the following command and press Enter: MpCmdRun.exe -Scan -ScanType 2
  6. If you need to stop the scan mid-way, press Ctrl + C to quit the scan.

Just like on the GUI app, youโ€™ll see the progress report of the scan. Like on the Windows Defender app, running a quick scan should only take a few minutes, depending on the size of the files stored on your computer.

There are cases where youโ€™d like to run a full virus scan. Running a full virus scan ensures that all sectors of your computers are fully scanned. Scans like this take up way much time but are more efficient.

How do I run a custom scan from CMD?

  1. Click the Start button, type cmd, and select Run as administrator to open an elevated Command Prompt window.
  2. Type in the following command and press Enter: MpCmdRun.exe -Scan -ScanType 3 -File PATH
  3. Ensure you replace PATH with the path to the folder you want to scan. For example, if you want to scan your desktop for viruses, youโ€™ll use the command: MpCmdRun.exe -Scan -ScanType 3 -File C:\Users\YOURNAME\Desktop
  4. Ensure you change the YOURNAME to your username.

How do I run a Boot Sector scan

  1. Windows key + S, type in command prompt, right-click on the displayed result, and select Run as Administrator.
  2. 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?

  1. While in the command prompt, type in the following to view the list of quarantined files: MpCmdRun.exe -Restore -ListAll
  2. Then type the following command: MyApp.exe along with the name of the file you want to restore, and press Enter.

When Windows Defender detects malicious files, it quarantines them. Oftentimes, the antivirus might mistakenly quarantine legitimate files.

Running a virus scan from the command prompt is less intuitive than the GUI. However, when youโ€™ve been completely locked out of your GUI due to malware, you must run Windows Defender directly from the Command Prompt app.

For this, you will need an elevated Command Prompt window. We have a guide on what to do if you can’t open Command Prompt as administrator.

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.

More about the topics: command prompt