top of page

How to remove virus from USB Flash Drive using Command Prompt or Batch File in Windows 10

Updated: Mar 22, 2023

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 drives using the attrib in Windows 10.


Remove virus from USB Flash Drive using Command Prompt


To remove a virus from a USB flash drive using Command Prompt in Windows 10, do the following:


STEP 1: Insert the infected USB flash drive into your computer's USB port.


STEP 2: Press the Windows key + R to open the Run dialogue box.


STEP 3: Type "cmd" and press Enter to open the Command Prompt window.


STEP 4: Type "attrib -h -r -s /s /d g:*.*" (without quotes) and press Enter. Replace "g" with the drive letter of your infected USB flash drive.


STEP 5: This will remove the hidden, read-only, and system attributes of all the files and folders on the USB flash drive.


STEP 6: Now, type "del /f /q /s g:*.lnk" (without quotes) and press Enter. This will delete all the infected shortcuts on the USB flash drive.


STEP 7: Finally, type "del /f /q /s g:*.inf" (without quotes) and press Enter. This will delete all the infected autorun files on the USB flash drive.


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

Remove virus from USB Flash Drive using Batch (.bat) File

To remove a virus from a USB flash drive using a .bat file in Windows 10, do the following:


STEP 1: Open Notepad and type the following commands:

@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

STEP 2: Replace "g" with the drive letter of your infected USB flash drive.


STEP 3: Save the file with the ".bat" extension, such as "virusremoval.bat".


STEP 4: Close Notepad and double-click the batch file to run it.


STEP 5: This will remove the hidden, read-only, and system attributes of all the files and folders on the USB flash drive, delete all the infected shortcuts, and delete all the infected autorun files.


That’s it on how to remove viruses from USB Flash Drive using Command Prompt or Batch File in Windows 10!


Using Command Prompt or Batch File is an effective way to remove viruses from a USB flash drive, as it allows you to quickly and easily remove the infected files and folders without using any third-party antivirus software. However, it's important to note that this method may not be effective against all types of viruses, and it's always recommended to use antivirus software to scan and remove viruses from your computer and USB flash drives.

0 comments

Recent Posts

See All

Comments


bottom of page