How To Remove Virus From Any Drive Using Command Prompt (CMD) In Windows 10

In How To

How To Remove Virus From Any Drive Using Command Prompt

For starters a virus is a self- replicating computer program that infects your computer. These viruses are a menace and can spread across multiple computers via USB/flash drives, external media and other means. As we all know, there is a multitude of anti-virus software. To our dismay, not all of them can do the trick. Sometimes, even your antivirus can fail to detect some sort of viruses. Well, in such case, CMD prompt may be the solution to help you solve the virus issues. Most of us grapple with viruses like Autorun.inf, newfolder.exe, ravmon.exe, svchost.exe etc. They usually present themselves as files and sometimes they can even be files hidden from you.

To remove a virus using CMD, we shall use a CMD known as “attrib” command. Therefore first we have an obligation to know a few basics of the attrib command.

– represents the read only attribute of a file or folder. Read only means the file can’t be written or executed.

H – H stands for the hidden attribute.

A – Similarly A stands for Archiving and this prepares a file for archiving.

S – This attribute changes the selected files or folders in a system file from a user file by assigning the “system” attribute of that particular file.

Here we have the “attrib” syntax à ATTRIB{+attribute/-attribute}{pathname}[/S[/D]}

And with the above command there are different parameters and switches so lets see what they are.

+/- à to enact or to cancel the specified attribute.

à include any process folder.

à   searching through the entire path. Sub-folders inclusive.

Attribute à ( already explained above)

Pathnameà path where target folder is located.

This here is the proper syntax for the attribute command:

ATTRIB{+R/-R}{+A/-A}{+S/-S}{+H/-H}{+I/-I}{drive:}{path}{/S[/D][/L]}
After knowing all of the basics, now let’s give it a shot and try to see how we can remove a virus from  USB, SD card etc.  using CMD prompt.

For example, let’s transfer an autorun.inf virus from my USB to my D drive and delete the virus from the D drive.

Step 1. Open command prompt from search and run as administrator.

run-cmd

Step 2. Type D and hit enter

change-drive-using-cmd

Step 3. Type “attrib” and press enter. This command lists out all files inside the current drive and you will clearly see autorun.inf virus listed.

type-attrib

Step 4. At this stage to remove the virus using CMD, type into command prompt “attrib –r –a –s –h . “ And press enter. This in turn will remove the read only, archive, system and hidden file attribute from all the files.

-r is for removing read only files

-a is for removing the archive file

-s is for removing system file

-h is for removing hidden file

. is for files with all different types of file extensions.

attrib-command

Keep in mind that this command only removes the different attributes from different files. However, the files will still exist. And therefore we must delete the virus permanently. To delete the virus, type “delete autorun.inf” and press enter. The file will get deleted from the current drive immediately.

Delete virus using CMD

I hope this guide was informative to you. Your feedback is gladly appreciated. Please leave us a comment in the comments section if you have any other tips and tricks you want to share with us.

facebook-profile-picture

Arnav Patel

Arnav Patel is the Co-Founder of  Techxerl and aspiring entrepreneur. He likes to  write how-to guides, digital tips and all tech stuff. You can follow me on Facebook and Twitter.

You may also like...