Link to home
Start Free TrialLog in
Avatar of cgruber
cgruber

asked on

Automatically run a batch or VB script stored on a USB stick, when plugged in !?!?

Suppose I have a blank USB flash drive and a PC running Windows 7 Pro.

Is there a method which I can use to automatically run a batch file or script, stored on that USB flash drive, when the drive is plugged in to the PC?

The script is intended to copy some files from the USB flash drive to the PC. If the file already exists at that location on the PC, then to silently override it.

The user should not have to do anything to run this, except plug the USB flash drive in the PC.
Avatar of Steven Carnahan
Steven Carnahan
Flag of United States of America image

Microsoft has disabled the autorun.inf feature to protect against virus/malware.  There are good and bad points behind this.

There are workarounds available however we don't allow USB drives at all for security reasons..

Having said that you can start here:  http://www.sevenforums.com/general-discussion/21585-usb-autorun-w7.html
it would be much easier with powersehll than vbs or batch.
first u need to find out the drive letter of the usb card, plug it in and check with is the drive letter.
then use this:
$dest = "c:\script.vbs"
$path = "y:\script.vbs"

Copy-Item $path  -Destination $dest -verbose
cmd /C cscript $dest

Open in new window


in case of .bat file:
$dest = "c:\script.bat"
$path = "y:\script.bat"

Copy-Item $path  -Destination $dest -verbose
cmd /C $dest

Open in new window

Avatar of cgruber
cgruber

ASKER

Can I make it drive letter independent (for the USB drive that is)?
What di u mean independent?
ASKER CERTIFIED SOLUTION
Avatar of Giovanni
Giovanni
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial