4

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

  1. insert the USB flash drive,
  2. double click on the .vbs file,
  3. remove the USB flash drive.

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?

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
user736887
  • 43
  • 1
  • 5

4 Answers4

1

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.

Community
  • 1
  • 1
josh3736
  • 139,160
  • 33
  • 216
  • 263
  • I have looked at that thread before posting this. The problem with that is it is an .exe file rather than a vbscript, I was hoping to have all of this code run from just one .vbs file – user736887 Nov 21 '11 at 03:26
  • 1
    This causes the drive to be completely disassociated from the drive letter, so even if you unplug and plug back, the drive is no longer mounted. – jviotti Nov 23 '15 at 16:20
0

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.

Matthias Steinbauer
  • 1,786
  • 11
  • 24
0

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.

Pedro
  • 96
  • 5
0

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

Drew Chapin
  • 7,779
  • 5
  • 58
  • 84
  • You should make your script to eject copy itself to the PC first before executing, otherwise it might not eject safely or at all since it's on the thumb drive you're ejecting. – Drew Chapin Nov 21 '11 at 02:00
  • The usb drives will be empty and I will need to copy over files from the hard drive to the flash drive. I dont think I would be allowed to copy over the code file to the flash drive anyway since my work only wants three specific files – user736887 Nov 21 '11 at 03:25
  • Are these computers networked? There has to be a better way than sneaker netting these files. – Drew Chapin Nov 21 '11 at 03:50
  • the goal of this project is to put three certain files on each of 3000 usb drives. I am just looking for a scripting solution to make that repetitive task easier. – user736887 Nov 21 '11 at 03:53
  • If the computers are networked, I could help you make it so all you have to do is plug all of the drives in, go to one computer, execute a single script, and then unplug the drives. – Drew Chapin Nov 21 '11 at 04:17
  • @druciferre: I think you're misunderstanding what the OP is trying to accomplish. Think burning files to CDs for distribution -- except flash drives instead of CDs. – josh3736 Nov 21 '11 at 05:21
  • I have **not** misunderstand. I fully understand what he needs to do. I'm trying to tell you and the OP if the computers are networked, and he has an administrative account on all of them, I can make it so his process is go to each individual PC, plug in a thumb drive. Go to one specific PC, click on a script, and then go unplug the drives when the script finishes. I could do the same thing if he wanted the PC's to burn a CD. – Drew Chapin Nov 21 '11 at 18:27