code_junkie

Mount/Unmount USB drives with VBSCript

Nov 12th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. Sub EjectDrive(strDrive)
  2. On Error Resume Next
  3. CONST SSF_DRIVES = 17
  4. Set objShell = CreateObject("Shell.Application")
  5. Set objDrive = objShell.Namespace(SSF_DRIVES).ParseName(strDrive)
  6. objDrive.InvokeVerb "E&ject"
  7. End Sub
  8.  
  9. strComputer = "."
  10. Set objWMIService = GetObject("winmgmts:" _
  11. & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
  12.  
  13. Set colItems = objWMIService.ExecQuery _
  14. ("Select * From Win32_Volume Where Name = 'E:\'")
  15.  
  16. For Each objItem in colItems
  17. objItem.Dismount(True, True)
  18. Next
  19.  
  20. Set WshShell = WScript.CreateObject("WScript.Shell")
  21. intReturn = WshShell.Run("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll", 1, TRUE)
Add Comment
Please, Sign In to add comment