How to Remove Virus Using CMD?
Last Updated :
23 Jul, 2025
Viruses and malware can wreak havoc on your computer, causing slow performance, data loss, and security breaches. While there are numerous antivirus programs available, using Command Prompt offers a powerful and direct method to remove viruses without the need for additional software. CMD is a built-in tool in Windows that can help you identify and eliminate malicious files effectively. Let's dive in and learn how to use CMD for virus removal.
Methods to Remove Virus Using Command Prompt
In this short guide for beginners, you'll learn straightforward steps to leverage CMD to scan for and erase malicious software. With some basic commands, you can keep your computer safe.
Method 1: Remove the Virus Using Del Command
Step 1: Open the Command Prompt
In the search bar, type "CMD" then right-click on "Command Prompt" and choose "Run as administrator". Running Command Prompt as an administrator gives it extended permissions needed to access all files and folders.

Step 2: Select the Infected Drive
Type the drive letter of the infected drive followed by a colon (for example "E:") and press "Enter". This will switch you to the drive that contains the virus or malware. Replace 'X' with the appropriate infected drive letter.

Step 3: Key Attributes
Type "attrib -s -h -r -a /s /d" and press "Enter". This will remove key attributes from files that might prevent deletion. The attributes that are removed are system, hidden, read-only, archive, files in subfolders, and empty folders. Removing attributes allows infected files and folders to be deleted.
Command: attrib -h -s -r /s /d *.*
Output 1:

Output 2:

Step 4: Delete the Program
Now type "del autorun.inf" and press Enter. This deletes the autorun.inf file which is commonly used by viruses and malware to execute automatically. Getting rid of this can disable some infections. Find the Suspicious file or Program that doesn't belong to your computer to delete the file enter the following command.
Command: del ( Enter_the_Program_name_here )
Output:

Method 2: Remove the Virus Using Taskkill Command
Step 1: Open the Command Prompt
Open Command Prompt as an administrator like before by searching for CMD, right-clicking Command Prompt, and select "Run as administrator".
Step 2: List the Files using Tasklist Command
Type "tasklist" and hit enter. This displays a list of currently running processes and programs on your computer.
Command: tasklist
Output:

Step 3: Check for the Suspicious Programs
Carefully look through the list and identify any suspicious processes that could be caused by a virus infection. These may have random or unusual names. In my case, I don't have any viruses so for a demonstration I'm gonna Choose some of my unnecessary Programs.

Step 4: Delete the Program
In my case, I don't have any viruses so for a demonstration I'm gonna Choose some of my unnecessary Programs and delete them by using the taskkill Command.
Read this to know more about Taskkill Command here
Command: taskkill /F /IM ( Enter_Your_Program_Name_Here )

After, entering the command you will see the message like SUCCESS: The process has been terminated which means that our virus is been Successfully deleted.
Conclusion
Using CMD commands to remove viruses is a powerful and efficient method to enhance your computer's security. By following the steps outlined in this guide, you can effectively identify and eliminate malicious files without relying on third-party software. Run antivirus scans for extra protection. Even without being an expert, these basic steps help safeguard your computer effectively.
Also Read
Similar Reads
How to Remove RAR/WinRAR Password Using CMD? Forgetting the password to your RAR or WinRAR file can be incredibly frustrating, especially when you need to access important data quickly. Fortunately, Command Prompt in Windows provides a powerful and effective way to remove the password from your RAR/WinRAR files without the need for third-party
5 min read
How to Uninstall Software via CMD Uninstalling programs through the Command Prompt (CMD) can be a powerful method, especially when you can't access the standard Windows settings or need to automate the process. Whether you prefer using text-based commands or need a quick solution to remove software from your system, this guide will
3 min read
How to Rename Files and Folders Using CMD? Renaming files and folders is a fundamental task for system organization. While it's simple through the graphical interface, using CMD provides more flexibility, particularly for batch operations or when the interface is unavailable.In this guide, youâll master the ren (or rename) command, a built-i
4 min read
How to Remove Rootkit Windows 10? Rootkits are malevolent software programs designed to give programmers with unauthorized privileges to your computer system. They operate stealthily, permitting attackers to spy on your activities, take individual data, and even install extra malware without your information. Given their stealthy na
6 min read
How To Perform a Chrome Virus Scan? Google Chrome Virus Scan generally runs automatically whenever you download a file or if it suspects some malicious activity. It just scans your system when it is needed and asks, and it does not perform real-time background checks like other advanced anti-malware software. In the digital age, web
10 min read
How to Repair Windows 10 Using Command Prompt - 5 Methods Is your Windows 10 not working right? Maybe itâs slow, keeps crashing, or wonât start properly. These problems can be annoying, but you donât have to do something big like reinstalling Windows yet. Thereâs a handy tool called Command Prompt that can fix many Windows issues, and itâs already on your
6 min read