Remove Virus from Computer or USB Drive by Command Prompt

The word  “Virus” is a threat to users of Windows. Users feel uneasy to connect others USB or pen drive to their Computer for the inflections made by Virus. Viruses spread in Computer to Computer through the pen drive or any removable disk drive. Mainly Autorun.inf or many .exe  files like newfolder.exe, ravmon.exe etc affect the documents of your computer. If you try to delete the file from the directory they come back automatically every time and it easily spreads in the computer.

Tip: Clean Your Computer Removing Antivirus Live Application.

These Autorun or .exe files are written in such a manner that when we try to open or rename a drive a specific program starts as a result we can’t do those works.You can remove viruses from Task Manager. You have to stop the affecting process from “Task Manager” by choosing that process as “End Task” in Task Manager. But the virus programmer are much aware about that so when you want to open “Task Manager” by pressing “Ctrl+alt+del” you will see that the “Task Manager has been disabled by your administrator“.

Also read: How to make a folder undeletable

In this situation there is another process to remove autorun.inf from Command Prompt. That seems more effective. You have go through some commands only. But the Command Prompt may be disabled by the virus. You can download a replacement of the Command Prompt.

However after getting the access of Command Prompt you can apply the following tricks to remove the virus from your computer.

Related: Remove Virus Manually From Your Computer.

First click the “Start” button and go to “Run“. You can also press “Windows+R“. Type “cmd” there.

Type the following commands in the Command Prompt

  • Type “<Drive_name>:” in the command prompt and hit “Enter“. (“Drive_name” is where the problem occurs, it may be any USB drive)
  • Type “attrib” and hit “Enter“. (This shows the files that are present in the currently working directory. You can also use the command “dir/w/o/a/p“)
  • If there are any file named autorun.inf then go for next steps else the drive is not affected with any autorun.inf file.
  • Type “attrib -h -r -s -a *.* ” then hit “Enter“.  (This command removes the Hidden, Read Only, System and Archive attributes over any file)
  • After unhiding and removing attributes you can see the files.  So you can delete the file now.
  • Type “del <filename>” in the Command Prompt and hit “Enter“. (As for example del autorun.inf)

Now your computer is virus free. Enjoy! Feel free to share your experience with us.

Related Posts


  1. Ajinkya :

    nice guide.

    Also, if your computer is infected with a RAT (Remote admin tool – that gives full access to the hacker… e.g. you see your mouse moving automatically. LOL )

    Do this >

    1. open CMD (Start > RUN > type: cmd )

    2. Type in: netstat – ano
    (it shows all ur network accessing process with their Process identification codes = PID )

    3. if you see a Text like this > ESTABLISHED with a foreign IP, note down its PID.

    It will also show the EXE accessing it.

    4. go to TASK MANAGER (CLTR + ALT + DEL)
    – then go to VIEW > Tick PID

    5. in the Proccess TAB > just click that PID process EXE file.

    6. now disconnect your internet & scan your whole Computer with SpyBot SD 1.6 & NOD32 v.4

    7. your are virus free now.

    NOTE: you will say why didnt i disconnected internet at Start !! thats cus teh RAT virus will also get exit, will come again whn u access the net & netstat needs internet connection ON to show PID.

  2. Tanmay :

    Very nice tips. Thanks for sharing.

  3. Raj Kumar :

    Pen Drive Format Error write protect

    Pls give me Solution

  4. Umesh.u :

    You have worm in a pendrive or system .get a antivirus which is updated.I Prefer avast

  5. Shaun Phaladi :

    i want to know the code to cleaning my machine of any viruses and how to check them also mainly using command prompt.

  6. mko abiola :

    tnks but a question would deleting those files result in lose of files?

  7. mko abiola :

    sory pls are my going to include the quotes when writing the the command prompt bcos when i typed””, it said the command is incorrect.PLS

  8. Tanmay :

    @Mko Abiola: NO..don’t include ” signes.

  9. mko abiola :

    @tanmy pls when i typed drive_name it said the command is an incorrect command

  10. Tanmay :

    type drive_name means that you type the drive letter. As for example you should type d: and hit enter.

  11. Nirmal :

    plz solve my pen drive problem which shown ‘remove the write protection’, I am tired about my problem, I can’t use pen drive, what is solution ?


  12. kenneth :

    i learn a lot of things in this website….and i was thankful for that…

  13. d.datta bhuloka rao :

    i have a 8gb pendrive that not formt that is having virus plese give me solution.

  14. kankasha :

    guys, when inserting my flush in machine and try 2 open it, it said the drive is empty. cud u plz help.

  15. Marko :

    good way, or try this one too 😉

  16. ken :

    i don know how to thank you..All i can i say is,,keep up.easy to understand, i even wish you were my teacher.thanks alot.

  17. Jenny :

    how do you know if it’s a virus or not?

  18. albert :

    tanx…but i need help! My laptop is suffering from virus i dont know abt nd i can install an antivirus…plss i really need help.

  19. Chase :

    This line of code only deletes what you chose it to, though, if you know where the virus is located (i.e. the directory (C: Drive for Windows) Press “Tab” to browse through the files on your local drive. This works:

    prompt $p$g
    title algeeroidbiletdoux System

    color 02
    ECHO algeeroidbilletdoux System

    dir /a/w



    attrib -s -h -r %M%
    del /f /q %M%

    RD /S %M%
    COLOR 0A
    echo MyBox = MsgBox(“File/Folder

    has been Shredded. File/Folder has

    been removed…”, 6000,

    “algeeroidbilletdoux System

    FlashX”) >driveshredder.vbs
    start /w driveshredder.vbs
    del /f /q driveshredder.vbs
    GOTO :Shredder
    COLOR 0A
    echo MyBox = MsgBox(“The

    File/Folder you type does not exist

    and match in the directory.”, 6000,

    “algeeroidbilletdoux System

    FlashX”) >folderatt.vbs
    start /w folderatt.vbs
    del /f /q folderatt.vbs
    GOTO :Shredder

  20. Nick :

    Please help.. when I used this steps. It says that access denied or unable to change attrubute.. What will I do with this???

  21. herojin :

    mga master help plzz.. i knw how to delete viruses but anyone knows how to fix USB FLASH DRIVE with a write protection ,it can’t be format kc may protection file. pki email nlng qng cno marunong ….plzzz.. rtf-return the favor(

  22. chel :

    is it effective also on windows7 ?

  23. Arsel John M.Dela Cruz :

    Thank you so much!Now I can use my usb virus-free….Really appreciate it!<<>> :))

  24. SANJIB :

    i hve NORTON antivirus updated, but cant delete write protect file frm pen drive sandisc……plz help

  25. icen :

    pls…help ihav virus on my usb flash drive i keep deleting it but it comes back…pls. help

  26. emang :

    i nid a help plz i tryed this method of using cmd to delete virus bt stl gves mi a problm the computes says access is denied how to solve this plz i wnt to delete ths thng of autorun

  27. sivaji :

    how to remove tha virus by using run cmd

  28. panda 27 :

    it didn’t work .i did all the steps in cmd and it appeared AUTORUN.INF access denied.. help me i dont know what to do :( all my files are gone.

  29. jr :

    I cant delete the autorun because it says that it is being used by other processes or user etc.

  30. Samraj :

    When I insert my pen drive at system, it shows an auto-run file. I can’t delete this. If I delete it using the Delete key, it appears again continuously. I am using Windows 7, please help me.

  31. Punie :

    I want to know how to recover my laptop using cmd, and removing virus.

  32. S'phamandla.Z.Thusi :

    Thanks to your information. I gathered about “how to remove a virus on USB using cmd”. Now, my universal serial bus is virus free.


    The formula for removing virus doesn’t work it shows that,the file doesn’t found. Please help me for this.

    • hemedi :

      how to unstall windows 7 and intall another

  34. Gomez :

    Thanks..this information is very useful..i don knw how to thank u..
    How to delete or remove czPOyGL.exe in pendrive..i tried to delete by using command prompt but it shows “the process cannot access the file because it is being used by another process”

  35. Bijay neil pandey :

    doesn’t work it

  36. Andi :

    I am not familiar with viruses, etc., so please bear with me. My laptop has a virus – probably more – and I’m getting constant pop-ups, plus WARNING messages that freeze my computer – I can’t close the tab and I can’t go to another tab. One constant pop up I’m getting is “Reimage Repair”. I’ve tried system restore, but it only goes so far then says my c drive is bad and it cannot complete the restore process. I work from home and my laptop HAS to be up and running for me to work. I’ve tried AVG and it said it found over 100 infections, but even after deleting them, the problem persists. I do not have extra money to pay for a tech to fix, so I’m really trying to figure out how to fix this myself. Any suggestions?

  37. ABIODUN :

    I’m having issues with a particular hidden virus that shortcut and delete any files or folder i save on my flash, memory card and hard drive. My antivirus keeps deleting the virus but it would not delete, I’ve formatted the flash and memory card countless of times but it still keeps short cutting my files.
    Please Admin I need a urgent solution to solve this virus issue because I’ve tried all the above procedure to delete the virus but no solution to it.
    I think the name of the virus is “Microsoft Excel.Wsf” that what my the antivirus on my system keeps deleting.

Leave a Comment

Your email address will not be published. Required fields are marked *