Malicious programs are often spread via USB drives and other external media. Viruses from an infected flash drive or removable hard drive are activated as soon as the device is connected to the computer. Since Windows 10 usually opens the root path of the USB drive in File Explorer, this leaves the system open to infection.
To avoid this type of threat, it is recommended to regularly scan external media for malware using specialized programs or the built-in Windows Defender. Also, before transferring any files from one PC to another using a flash drive, you need to scan it with an antivirus on the initial computer.
If you do not have antivirus installed, or you doubt the scan results, below are two ways to remove suspicious files from removable media. It is worth noting that these methods are also effective on older versions of Windows 7, 8, and 8.1.
Method 1. Removing viruses from a USB drive or hard drive
Instructions:
- Connect your USB drive to your computer.
- Right-click the Windows icon and select Command Prompt (Admin).
- In the system window, enter the command: “E:” (without quotes), where the letter “E” must be replaced with the one that marks the flash drive in the explorer. It must be written in English.
- Then press Enter, which will open the removable storage directory.
- Next, enter the following command: E: attrib -r -a -s -h *. *
- After pressing the Enter key, a command will be executed to make changes to the files of the flash drive. The letter “E” at the beginning must also be replaced with the appropriate drive.
- Next, enter the command: DIR
- After pressing the Enter key, all files infected with a virus in the flash memory or on the hard disk will be displayed.
- In addition, all files will be displayed, including those that were initially hidden, among them one or more files with the .inf or .lnk extension will be searched for.
- Also, viruses often infect the autorun.inf file.
- To remove it, type the following command and press Enter: del autorun.inf
If there are other files with the specified extensions, repeat the execution of the previous command, replacing the autorun.inf name with the name of the infected files.
Method 2: Remove malware from USB drive using batch file (.bat)
To remove a virus from a USB flash drive using a batch file with .bat resolution, you must do the following:
- Connect a USB drive or external hard drive to your computer.
- Open Notepad.
- In the opened document, copy and paste the following
- @echo off
attrib -h -s -r -a / s / e: *. *
attrib -h -s -r -a / s / e: *. *
attrib -h -s -r -a / s / e: *. *
@echo complete - As in the previous version, you must replace the letter “e” with the one assigned to the USB drive.
- Save the file with any name and add the .bat extension at the end so that the entry looks like this: Remove_Virus.bat
- Also, before saving the file, you must set the File type field to: All files.
- Then close notepad and right-click on the created file.
- Select Run as administrator.
- After that, the process will start to remove all suspicious files from the flash drive, including those with the .inf and .lnk extensions from the first method.