Skip to content Skip to sidebar Skip to footer

How to Remove Viruses With CMD on Flashdisk and Hardisk

Cleaning viruses are one of the effective steps to speed up Windows 10, which starts to feel heavy and hangs frequently. Viruses can infect flash and

Konten [Tampil]

Cleaning viruses are one of the effective steps to speed up Windows 10, which starts to feel heavy and hangs frequently. Viruses can infect flashdisk and hardisk on the computers we use and cause various problems.

One of the most annoying viruses is a shortcut virus that hides all files and makes the flashdisk full but empty, aka invisible files in it. To clean it up we can use Command Prompt (CMD).

How to remove a virus using CMD in Windows

1. Open CMD with administrator permissions

The trick is to click on the Start button, then type cmd => on the Command Prompt menu that appears click on Run as administrator.


2. Type F: then press enter

You must replace F with a flashdisk letter or hardisk in your computer that is infected with a virus. If done correctly, it will appear that CMD has moved to F: \>.


3. Type attrib -s -h -r / s / d *. *

The next step is to change the attributes of all the files on the flashdisk by typing the command attrib -s -h -r / s / d *. * Then press enter.


  • Attrib: stands for attribute, a command to change system attributes of a file or folder.
  • -s: command to remove attributes of the file system.
  • -h: command to remove hidden attributes in a file.
  • -r: command to remove the read only attribute in a file.
  • / s: command to apply all the attributes that have been set on each folder, file, and subfolder in it.
  • / d: command to apply attributes to each folder on the disk
  • *. * is a wildcard character that functions to execute commands on all files with any name and any extension.

4. Type dir to see all files

Then type the dir command to display all the files on the flashdisk or hardisk affected by the virus, then press enter.

5. Delete files that are suspected of being a virus

You will see all the files including the ones that were originally hidden there. All you need to do is find the file that is suspected of being a virus.

Look for files with strange names, usually viruses has an. inf or. lnk extension. The virus on the flashdisk very often infects the autorun.inf file , if you find it then you can delete it.

The shortcut virus, which is one of the most common viruses attacking flashdisk, will usually duplicate lots of files with the. lnk extension.

You can delete all files with the. lnk tip, which is the result of the shortcut virus.

Resolved "Access denied" when running commands in CMD

When trying to run a command on the command line you may get a message in the form of "Access denied", this means that the command cannot be executed on a virus-infected flashdisk or hardisk.

Some of the causes and how to overcome them:
  1. You are running CMD not with administrator access. The solution, make sure you open CMD  administrator access. When opening it select Run as administrator.
  2. There are files or folders that are still in use. If there are files on the flashdisk that are still in use, for example, there are still edited images in the image editor or word files that are still open in Microsoft Word.
  3. User permission problems. The solution is to make sure you log into Windows 10 using an account with administrator access.
  4. Error in flashdisk and hardisk logical file system. The fix is ​​by running the CHKDSK tool.
  5. You entered the wrong command. Make sure you use the exact same commands described above.

Can using CMD erase all types of viruses?

Not all viruses can be removed using the command line, especially viruses that infect and hide in files. To clean it maybe you can use an antivirus.

Viruses that can be removed using CMD are viruses that have hidden attributes and cannot be displayed with normal settings.

Usually this kind of virus has a hidden master file, so using CMD is to bring it up. We also have to be able to identify the file and then delete it.

Will deleting a virus using CMD will erase data on flashdisk and hardisk?

Not. In fact, this method is done as an alternative to cleaning viruses on a flashdisk or other storage media without losing data.

Even if you can identify the virus master file and delete it, then we don't need to format or delete any other files, because the virus no longer stops working because the parent file has been cleaned.

To prevent the virus from infecting your computer in the future, you must update Windows 10 to the latest version.

Updates not only function to install the latest features, but also to get the latest security patches and virus databases so that our computer security is even more solid.

This is the tutorial on how to remove and clean viruses on a flashdisk and hardisk using CMD. Good luck and good luck!