VBScript - Disconnect USB Drive

I have a tiring project. I need to insert a USB drive into a computer, then copy three files to this drive, and then unmount it and repeat 3,000 times (literally). I was hoping to come up with VBScript that can reduce my actions to everything

  • insert a USB flash drive,
  • double-click the .vbs file,
  • remove the USB drive.

I find it not too difficult to come up with a copy and paste part of the code if I insert USB into the same port every time. Is this assumption correct? However, the real problem is unmounting / removing the USB drive. Is there any simple VB Script code that can do this?

+4
source share
4 answers

This was the first Google result for vbscript unmount: Disconnecting USB drives


This worked on Windows 7 if the script is run with elevated privileges (as an administrator):

Set shell = WScript.CreateObject("WScript.Shell") shell.Run "mountvol <drive>: /d" 

mountvol included in Windows.


Perhaps you can even reduce the input needed to poll the drive letter to which your USB drives are attached, and if there is a drive, copy the files and then disconnect them.

+1
source

Since you are doing this with 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

0
source

My answer is not very strongly connected, but if you want to use Linux, I will have a complete software package for this. What he does is connect to the Linux udev system and automatically format the USB drives that connect to specific USB ports and then copy the files to the disk, unmount the disk and inform the user.

We used this to copy data to 500 USB storage devices.

0
source

The best option I can find is:

1) open a shell and run mountvol and find the GUID

 \\?\Volume{1be3da43-6602-11e0-b9e6-f11e1c50f5b5}\ F:\ 

2) run the mountvol / p [GUID] command in the 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 administrator access is required to delete the drive letter. If it is called by the user, it will disconnect the drive, in which case it will leave F: phantom. It is safe to remove the USB drive, or you can remove the phantom to remove it.

0
source

Source: https://habr.com/ru/post/1382203/


All Articles