Advertisement
jcunews

DevEject.vbs

Nov 19th, 2019 (edited)
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub help
  2.   wscript.echo "Usage:" & vbcrlf _
  3.     & vbcrlf & "  DevEject /list" _
  4.     & vbcrlf & "    List ejectable devices." & vbcrlf _
  5.     & vbcrlf & "  DevEject /eject {device name}" _
  6.     & vbcrlf & "    Eject specified device."
  7.   wscript.quit 1
  8. end sub
  9.  
  10. if wscript.arguments.count = 0 then help
  11. cmd = -1
  12. s = ucase(wscript.arguments(0))
  13. if s = "/EJECT" then
  14.   cmd = 1
  15.   if wscript.arguments.count = 1 then help
  16.   name = ucase(wscript.arguments(1))
  17. elseif s = "/LIST" then
  18.   cmd = 0
  19. else
  20.   help
  21. end if
  22.  
  23. set sa = createobject("shell.application")
  24. set fd = sa.namespace("::{26EE0668-A00A-44D7-9371-BEB064C98683}\0\::{A8A91A66-3A7D-4424-8D24-04E180695C7A}")
  25. if fd is nothing then
  26.   wscript.echo "This script requires administrator rights."
  27.   wscript.quit 2
  28. end if
  29.  
  30. cnt = 0
  31. if cmd = 0 then 'list
  32.  for each fi in fd.items
  33.     for each vi in fi.verbs
  34.       if vi.name = "&Eject" then
  35.         cnt = cnt + 1
  36.         wscript.echo fi.name
  37.         exit for
  38.       end if
  39.     next
  40.   next
  41.   if cnt = 0 then wscript.echo "No ejectable device found."
  42. else 'eject
  43.  for each fi in fd.items
  44.     if ucase(fi.name) = name then
  45.       cnt = 1
  46.       for each vi in fi.verbs
  47.         if vi.name = "&Eject" then
  48.           vi.doit
  49.           wscript.echo "Ejected " & fi.name & "."
  50.           wscript.quit
  51.         end if
  52.       next
  53.     end if
  54.   next
  55.   if cnt > 0 then
  56.     wscript.echo "Specified device is not ejectable."
  57.   else
  58.     wscript.echo "Specified device is not found."
  59.   end if
  60. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement