Remove virus from USB Flash Drive using Command Prompt or Batch File
Malware is usually spread across multiple computers using USB Flash drives, external media, connected networks, and the internet – infected USB drive will get activated when you connect and open the USB drive on your computer. In this post, we will show you how to remove viruses from USB Flash Drive using attrib in Windows 10.
Remove virus from USB Flash Drive using Command Prompt
To remove virus from USB flash drive using Command Prompt in Windows 10, do the following:
- Power-on your computer.
- Plug in the USB flash drive.
- Press Windows key + R to invoke the Run dialog.
- In the Run dialog box, type cmd and then press CTRL + SHIFT + ENTER to open Command Prompt in elevated mode.
- In the command prompt window, type the command below and hit Enter.
- Replace the <DriveLetter> placeholder with the flash drive letter that is infected with a virus.
<DriveLetter>:
- Now, type or copy and paste the command below and hit Enter to change the attributes of all the files on the flash drive:
attrib -r -a -s -h *.*
The parameters are described as follows:
- Attrib: stands for the attribute, a command to change system attributes of a file or folder.
- -s: command to remove attributes of the file system.
- -h: command to remove hidden attributes in a file.
- -r: command to remove the read-only attribute in a file.
- / s: command to apply all the attributes that have been set on each folder, file, and subfolder in it.
- / d: command to apply attributes to each folder on the disk
*. * is a wildcard character that functions to execute commands on all files with any name and any extension.
del autorun.inf
In case you are infected with any other virus, then replace autorun.inf with the extension of the virus your system is infected with such as .exe or .lnk.
Read: Free USB security software & antivirus for PC.
Remove virus from USB Flash Drive using Batch (.bat) File
To remove virus from USB flash drive using .bat file in Windows 10, do the following:
- Power-on your computer.
- Connect your USB, pen drive or SD card to your PC.
- Press Windows key + R to invoke the Run dialog.
- In the Run dialog box, type notepad and hit Enter to open Notepad.
- Copy and paste the syntax below into the text editor.
- Replace the <DriveLetter> placeholder with the flash drive letter that is infected with a virus.
@echo off attrib -h -s -r -a /s /d <DriveLetter>:*.* attrib -h -s -r -a /s /d <DriveLetter>:*.* attrib -h -s -r -a /s /d <DriveLetter>:*.* @echo complete
- Save the file with a name and append the .bat file extension – eg; Remove_Virus.bat.
- On the Save as type box select All Files.
- Run the batch file with admin privilege (right-click the saved file and select Run as Administrator from the context menu) to clear and remove the existing shortcut virus.
That’s it on how to remove virus from USB Flash Drive using Command Prompt or Batch File in Windows 10!
Related post: Check and manually remove malware & virus from Registry.