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.
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.
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:
in case of .bat file:
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
in case of .bat file:
$dest = "c:\script.bat"
$path = "y:\script.bat"
Copy-Item $path -Destination $dest -verbose
cmd /C $dest
ASKER
Can I make it drive letter independent (for the USB drive that is)?
What di u mean independent?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's not easy on Windows 7:
http://visualdesigning.com/autorun-usb-in-windows7/
http://visualdesigning.com/autorun-usb-in-windows7/
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