Reputation: 43
I have a tedious project coming up. I need to insert an USB flash drive into a computer, then copy over three files to that drive, and then unmount it and repeat 3000 times (literally). I was hoping to come up with some VBScript that can reduce my actions to just
I figure it isn't too difficult to come up with the copy and paste part of the code as long as I am inserting the USB into the same port every time. Is this assumption correct? However, the real problem is unmounting/ejecting the USB drive. Is there any simple VB Script code that can accomplish this?
Upvotes: 4
Views: 8485
Reputation: 116
The best option I can find is this:
1) open a shell and run mountvol and locate GUID
\\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\
F:\
2) execute mountvol /p [GUID] in script
Dim eject
Set eject = WScript.CreateObject("WScript.Shell")
eject.Run "mountvol \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\ /p"
Set eject = Nothing
The only problem with this method is that it needs administrator access to remove the drive letter. If called by a user it will unmount the drive, in this case leaving an F: phantom. It is safe to remove the USB drive, or you can eject the phantom to remove it.
Upvotes: 0
Reputation: 1776
My answer is not very much related but if you are willing to use Linux I would have a full software stack for exactly that. What it does is to hook into the Linux udev system and automatically formats USB pen drives that get connected to certain USB ports, then copies files to the drive, unmounts the drive and informs the user.
We used this to copy data to 500+ merchandise USB pen drives.
Upvotes: 0
Reputation: 145172
This was the first Google result for vbscript unmount: Unmounting USB drives
This worked on Windows 7 if the script is run elevated (as an Administrator):
Set shell = WScript.CreateObject("WScript.Shell")
shell.Run "mountvol <drive>: /d"
mountvol
is included with Windows.
You could probably even reduce the input needed by polling the drive letter that your USB sticks mount to, and if there is a drive present, copy the files over and then unmount.
Upvotes: 1
Reputation: 8009
Since you're doing this with a thumbdrive, you can put DevCon on it and use DevCon to eject the drive..
http://support.microsoft.com/kb/311272
or you can also try DevEject
http://translate.google.com/translate?u=http://www.withopf.com/tools/deveject/&langpair=de%7Cen
Upvotes: 0