Follow the steps below to delete viruses from your computer or storage device using CMD.

Step 1. Type cmd in the search bar, right-click "Command Prompt" and choose "Run as an administrator".

Step 2. Type F: and press "Enter". (Replace "F" with the drive letter of the infected partition or device.)

Step 3. Type attrib -s -h -r /s /d *.* and hit "Enter".

Step 4. Type dir and hit "Enter". Now you will see all the files under the assigned drive. (The dir command displays a list of a directory's files and subdirectories.)

Step 5. For your information, a virus name may contain words like "autorun" and with ".inf" as the extension. Thus, if you find such suspicious files, type del autorun.inf to remove the virus.

use cmd to remove virus in Windows 10

Here are the basic attributes of the 'attrib' command:

R – represents the "Read-only" attribute of a file or folder. Read-only means the file cannot be written on or executed.
H – the "Hidden" attribute.
– stands for "Archiving" which prepares a file for archiving.
– the "System" attribute changes the selected files or folders from user files into system files.
- "not content indexed file" attribute.

The "attrib" Syntax:

ATTRIB [+ attribute | – attribute] [pathname] [/S [/D]]

In the above command, let's see what the different parameters and switches are:

'+ / –': To enact or to cancel the specified attribute.
'attribute': As explained above.
'/S': Searching throughout the entire path including subfolders.
'/D':  Include any process folder.
'pathname': Path where the target file or folder is located.

Here is the proper syntax order for attrib command:

ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [+I | -I] [drive:][path][filename] [/S [/D] [/L]]


If you receive the message "Access denied", you should:

  • Make sure you have run Command Prompt as an administrator
  • Make sure the file/folder is not in use
  • Check the permission of the current account and make sure you have full control over the file/folder (right-click the file/folder/partition and go to "Security")
  • Use CHKDSK command to check for file system errors (run Command prompt and enter chkdsk /f [drive letter]:)