Plug / unplug USB drives with VBSCript

I am looking for a way to install / unmount a USB drive using VBScript. This is the closest I could get.

Sub EjectDrive(strDrive) On Error Resume Next CONST SSF_DRIVES = 17 Set objShell = CreateObject("Shell.Application") Set objDrive = objShell.Namespace(SSF_DRIVES).ParseName(strDrive) objDrive.InvokeVerb "E&ject" End Sub 
+8
source share
3 answers

This will work on Windows Server 2003, but not NT / 2000 / XP / Vista, unfortunately.

 strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_Volume Where Name = 'E:\\'") For Each objItem in colItems objItem.Dismount(True, True) Next 

From Turn off the volume .

+2
source

Take a look at this thread about how to use the mountvol.exe command-line tool to mount / unmount the drive, and this should work on USB flash drives, or there is a program called deveject. Se this thread for more information: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/d2e5d16e-e7c9-48ef-88b8-3abf6e638384

+1
source

You can open the extraction dialog using something like this. I'm not sure if it is possible to unmount a particular device.

 Set WshShell = WScript.CreateObject("WScript.Shell") intReturn = WshShell.Run("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll", 1, TRUE) 
0
source

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


All Articles