How to Remove Virus On Computer With CMD

By nagib

PUBLISHED 8:34 pm GMT+0700 Fri September 2021

Generally, a PC or laptop infected with a virus will experience several problems, one of which is performance that suddenly becomes very bad.

Even the presence of this virus can make you lose data on your PC or laptop. So it should be addressed immediately by cleaning all the virus.

In this article, we will discuss how to remove a laptop virus using CMD. Here’s the discussion.

How to Remove Virus With CMD

Usually to clean the virus, you can use an anti virus such as, Smadav, Norton, Kapersky and so on.

But there is something more practical and efficient, namely by using CMD ( command prompt ) only.

The steps are this:

1. Open CMD

First you can open CMD ( Command Prompt ) first on the PC.

The trick is to press the Windows key + R on the keyboard > then type CMD > Enter .

CMD Windows 10

2. Type the name of the drive that has a virus

Then you have to configure the CMD to access the drive that has the virus in it.

For example, you suspect that there is a virus on drive D, so please type D: in CMD > press Enter.

Go to Drive in CMD

Also Read: How to increase Drive C capacity in Windows.

3. Ketik Attrib -s -h -r /s /d *.*

After that type Attrib -s -h – r /s /d *.* in CMD > press Enter.

The goal is to change the attributes on all files on the D drive.

CMD Commands To Eliminate Viruses


  1. –r is for deleting read-only files
  2. –a is for deleting archive files
  3. –s is for deleting system files
  4. -H is to delete the files that are hidden or hidden files
  5. *.* is for all files with all types of file extensions

4. Type Dir To View Files

Then you can type dir in CMD > then press Enter which aims to see all the files detected by the virus on the drive .

Set to Directory in CMD

5. Delete Suspicious Files

Finally, after viewing all the files, you can delete the suspicious ones. Usually the virus extension is like autorun.inf which usually attacks the drive on the flash drive .

In addition, the virus may have an .exe extension which once installed can be very dangerous on the PC.

Note: This method can be used to remove bat viruses, exe viruses, ransomeware viruses, rammnit viruses and so on.

You can also use a few steps on how to remove this virus on a flash drive . Usually the virus shortcut on the drive , but can be removed with CMD.

Also check, for you External HDD users, how to solve the Unreadable External Hard Drive on the laptop.

CMD Muncul Access Denied

If in CMD you appear access denied like this:

Overcoming Access Denied

You can fix the problem with the Windows Compability Troubleshooter , and wait for the process to see if the problem can be solved or not.

Otherwise, follow the steps below to use CMD with admin rights. Here are the steps:

  1. Click Start
Windows 10 Start
  1. Type CMD . Then, right click and select Run as Administrator
Run as Administrator CMD
  1. After that, type the command net user Administrator/active: yes to activate the built-in administrator account.
Setting CMD Administrator Laptop
  1. Run the program that was previously Access Denied .

You can use this method for Windows 10, Windows 8 and Windows 7 operating systems.

And effective for dealing with various types of viruses, such as:

  • Win32 virus
  • Mgr
  • Shortcut
  • And others

Will the file be lost after we remove the virus with CMD?

Usually only files that have been infected with viruses will be lost on the drive . But this way is better than you losing all the data on the drive .

Of course, if you manage to delete the virus file, then you don’t have to worry anymore that it will spread to other files, even to the system.

Also you should hurry to improve the security system on your PC. For example, updating the operating system, using premium antivirus and others.


That’s the way you can do if you are infected with a virus on your computer. Namely by using CMD.

Good luck.

Leave a Comment