Open In App

How to Remove Virus Using CMD?

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

1

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.

2

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:

3

Output 2:

4

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:

5

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:

6

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.

7

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 )

8

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


Article Tags :

Similar Reads