Autostart programs when a usb drive is connected

Martin Brinkmann
Jan 22, 2007
Updated • May 27, 2013
Security
|
3

USB Virus Scan is a nice little command line utility that performs predefined operations if an usb drive is connected to your computer.It can distinguish between different drive types so that you can define custom operations for individual drives as well as general commands for all drives or drives that are not recognized by the program. The tool uses the volume serial number of the drives to identify them and perform the selected operations.

Some tasks that come to mind are to start True Crypt automatically when an external encrypted hard drive is connected, or the iTunes software when you connect your iPod, iPhone or iPad to the PC. You can also start a background antivirus scan for all drives that are not recognized by the software.

Note though that the user in front of the PC has full control over the procedure, and that it is possible to abandon or cancel autostart operations. It is therefore not possible to run programs or commands forcefully on the system.

The tool uses the following syntax which you need to add to a .bat file to autostart it with Windows.

USBVirusScan cmd /k %d:

A real example would look like the following. Say you do want to start the file antivirus.exe on drive c:\ whenever a usb device is connected. You create a new bat file which is basically a text file with the .bat extension. Create the file test.bat in the same folder that usb virus scan resides. Add the following line to it.

USBVirusScan "c:\antivirus.exe" %d:

It is possible to add additional parameters. -c hides the command window, -i hides the tray icon, -e disables the exit menu.

I was not able to figure out how to create autostart entries that would use the volume name or volume serial number so I asked Didier the author of the software directly. The following paragraph is his answer to the question, thanks for being so quick to answer it Didier.

On my laptop, I have this entry in the Startup menu: "D:\Program Files\USBVirusScan\USBVirusScan.exe" wscript "D:\Program Files\USBVirusScan\tasks.vbs" %d %s '%v' tasks.vbs will start TrueCrypt when I insert a USB-key with serial number "318606D2" to automatically mount the TrueCrypt volume on the USB-key. If it's my MP3 player that is inserted (volume name PackardBell), 2xEplorer is launched. And in any other case, a virusscan is executed. tasks.vbs:

dim WshShell

Set WshShell = WScript.CreateObject("WScript.Shell")

'wscript.echo Wscript.Arguments.Item(2)

if Wscript.Arguments.Item(1) = "318606D2" then WshShell.run """D:\Program Files\TrueCrypt\TrueCrypt.exe"" /v " & Wscript.Arguments.Item(0) & ":\d1.tc /lz /q", 1, true

elseif Wscript.Arguments.Item(2) = "'PackardBell'" then

WshShell.run """D:\Program Files\2xExplorer\2xExplorer.exe"" D:\MyDirsD\Temp\PodcastQueue " & Wscript.Arguments.Item(0) & ":\", 1,

true

else

WshShell.run """D:\Program Files\Network Associates\VirusScan\csscan.exe"" /target " & Wscript.Arguments.Item(0) & ": /secure /quiet /log ""D:\Program Files\USBVirusScan\log.txt""", 1, true

end if

You would have to edit the path and serial volume number to make the script usable but I think it demonstrates the usage nicely.

Advertisement

Previous Post: «
Next Post: «

Comments

  1. Adam said on October 8, 2008 at 4:36 am
    Reply

    You mentioned that this program listens to windows events. Can you tell me which events in particular? Or direct me to some resource that introduces me to windows events. They look useful, but the names are not exactly friendly to new faces

  2. Javier Marti said on January 23, 2007 at 12:50 am
    Reply

    Man I don’t know who you are, but you are one of my favourtite blogs. i visit you every day. Keep it up!
    thank you

    http://niquel757.blogspot.com

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.