How to Remove Virus Using CMD in Windows 11 or 10

Published by Nyau Wai Hoe - Updated on

Viruses and malware are big problems for computers. They try to sneak in, cause damage, or steal private info without you knowing. Even though there are many antivirus programs out there to fight off these threats, sometimes you might need to deal with a suspicious file or folder on your own. It’s important to know that using the Command Prompt (CMD) in Windows 11 or 10 to get rid of these files is mainly for when you already think something’s fishy in certain spots of your computer, not for checking the whole system for bad stuff.

This method is more like an extra step, not the main way to keep viruses away. The first thing you should always do is use Windows Defender or another trusted antivirus to scan your whole computer. Knowing that, let’s talk about how to use CMD to remove viruses from specific places on your computer.

How to Remove Virus Using CMD in Windows 11 or 10

Why use command prompt for manual virus removal?

Before we get into the steps, let’s talk about why CMD is useful for getting rid of viruses manually. CMD lets you talk directly to your computer’s operating system and its files. If a virus is messing with your antivirus program, or if your antivirus doesn’t yet know about this virus, CMD can be a great tool. It lets you go straight to the suspicious files and change them so you can delete them more easily.

But be careful, this method needs you to know what you’re doing. A wrong move could mess up your computer.

Also see: How to Scan an .exe File for Viruses to Check If It’s Safe

Prerequisites before deleting virus files with CMD

Before you start deleting files with Command Prompt, there are a few important things to keep in mind:

  1. Always make sure you’ve back up and saved important stuff from your computer somewhere else. Playing around with CMD has its risks, and it’s smart to have backups.
  2. This method is for dealing with specific files or folders you’re suspicious about, not just looking anywhere. Make sure you know what you’re going after.
  3. Starting your computer in Safe Mode can help a lot when removing viruses. Safe Mode only runs the essential parts of Windows, making it harder for viruses to defend themselves.Enter Safe Mode Windows 11
  4. You need to be the boss of your computer (have administrator rights) to do certain things and change file attributes.
  5. If you’re not sure about a command or what to do next, it’s better to stop and ask someone who knows or look it up. Doing something wrong can cause problems.

Common virus: What is Trojan:Win32/Casdet!rfn and How to Remove it

Steps to remove virus files using CMD in Windows 11/10

Now that we know what we’re aiming for and understand the risks, here are the steps to delete a virus file using CMD in Windows 11 or 10:

  1. Launch CMD with administrator rights:
  2. Navigate to the suspected directory:
    • In CMD, you’ll usually start in your user folder. Use the “cd” command to move around. For example, cd Downloads takes you to the Downloads folder.
    • To go back a level, type cd ...Change directory to suspected virus folder
  3. Display files and directories:
    • Type “dir” to see what files and folders are there. This helps if you’re not sure of the file’s name you want to delete.
    • Use dir /a to show all files, including the ones hiding. Bad files often hide to avoid being found.Remove Virus using Command Prompt
  4. Modify file attributes:
    • If you’ve found a suspicious file, you might want to change its settings. Use the “attrib” command for this.
    • For instance, to make “autorun.exe” not hidden and ready to be changed, type attrib -h -r autorun.exe.Command line to unhide virus or malware files
    • This makes the file visible and allows you to edit it.
    • Related resource: How to Unhide a File or Folder in Windows 11
  5. Delete the suspected file:
    • When you’re sure the file is bad, and after backing up, use “del” to remove it. For example, del autorun.exe.
    • You can also use: del /F /Q autorun.exe. “/F” forces the deletion of protected files, and “/Q” means it won’t ask you before deleting.Delete virus using CMD in Windows 11 or 10
    • If a message says the file is being used, you might have to start your computer in Safe Mode and try again. Safe Mode stops most programs from running, which can help delete the file.
    • Learn more: How to Force Delete a File in Use by Another Program on Windows 11/10
  6. Inspecting startup programs:
    • Some bad programs try to start up with Windows. You can use “wmic” to see these startup programs.
    • Type wmic startup list full to see everything that starts with Windows. If something looks odd, write down where it is.Show all startup programs and services using CMD
    • See also: How to Disable Startup Services on Windows 11 or 10
  7. Clean temporary directories:
    • Bad stuff often hides in temp folders. It’s smart to clean these out now and then.
    • Go to the temp folder with cd %temp%.
    • Type del *.* to get rid of all temp files. Be careful, though. This deletes everything in there, but usually, it’s okay.Delete all temp files using CMD in Windows 11
    • Useful tip: How to Delete a Ghost File or Folder in Windows 11/10

Emphasizing again: While CMD can be a powerful tool against specific threats, it shouldn’t be your only defense. Always use regular scans with Windows Defender or another trusted antivirus as your main way to keep malware away.

What we’ve learned

The Command Prompt gives you a unique way to deal with malware and viruses that might sneak past your antivirus. But, using CMD comes with its risks, like possibly damaging your system or losing data. Always be careful and make sure you know what you’re doing.


Nyau Wai Hoe
Nyau Wai Hoe is the Founder and Chief Editor of WindowsDigitals.com. With a degree in software engineering and over 12 years of experience in the tech support industry, Nyau has established himself as an expert in the field, with a primary focus on the Microsoft Windows operating system. As a tech enthusiast, he loves exploring new technologies and leveraging them to solve real-life problems.

Share via
Copy link