Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eject USB flash drive 4

Status
Not open for further replies.

Nu2Java

Technical User
Jun 5, 2012
166
US
Hi... does anyone know of a way in vbscript to eject/stop a USB flash drive? My search has been rather unsuccessful. Any help is greatly appreciated.
 
Hi !

Code:
Set Ws = CreateObject("Wscript.Shell")
Cmd = "RUNDLL32.EXE shell32.dll,Control_RunDLL hotplug.dll"
Eject = Ws.Run(Cmd,1,False)
 
Thanks, Crackoo ... This seems to open up the remove hardware window for you to make a selection. Is there a way to identify only the USB flash drive and eject it?

Thanks
 
I'm like you, looking for something as you said above but until now i don't find any code to eject it directly !
 
Do you know the drive letter of the flash drive ?
If this is the case then you may try to use the FolderItem.InvokeVerb method of the Shell.Application object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Crackoo, thanks for the reply.

PHV ... Yes, I do know the drive letter. I have not used that method before. Do you have any examples by chance?
 
I found this code to dismount the USB drive... my problem is, how do you remount it? The system sees it in disk management, but it acts dismounted. Any ideas? Thanks


Code:
Set shell = WScript.CreateObject("WScript.Shell")
shell.Run "mountvol E: /d"
 
Geates ... thanks for the reply. I am a little ignorant to this as I have not used it before. Could you give an example of that method? I'm not sure about the path and volume name.

thanks
 
I'm in the same boat. Microsoft defines the VolumeName argument as "Specifies the volume name that is the target of the mount point. The volume name is of the form \\?\Volume{GUID}\, where {GUID} is a globally unique identifier (GUID) (for example, \\?\Volume\{2eca078d-5cbc-43d3-aff8-7e8511f60d0e}\)."

In order to mount a path to a volume, you need to know the GUID of the volumn you want to mount to. To get the GUID for the c: drive, issue a [tt]"mountvol c: /l"[/tt]. For me, the result is \\?\Volume{821c2cc7-42f9-11e1-ba53-806e6f6e6963}\. So if I want to mount the EXISTING path "f:\disk" to the c: drive, I would issue [tt]"mountvol f:\disk \\?\Volume{821c2cc7-42f9-11e1-ba53-806e6f6e6963}\".

Unfortunately, I cannot get this thing to work from the command line (I'm using Win7x64 - admin privledges). It's not much more additional info but may provide an "ah-ha!"

-Geates

 
Geates, thanks a lot for your help and time with this. I did find a little more about the volume name, and the link you sent is interesting, so I will have to play around a little bit. Seems so odd there doesn't appear to be a simple way to eject a USB flash drive. I like the small piece of code above from crackoo, but it only opens the stop window for selecting a device.
 
a simple way to eject a USB flash drive
CreateObject("Shell.Application").NameSpace("E:").Self.InvokeVerb "E&ject"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV ... that IS a simple way and I will make good use of that line of code. I couldn't find anything like it with all of my searching. But the good thing is, I learned plenty of new things along the way. Many thanks to ALL!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top