Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for cdrom.vbs

(view source code of cdrom.vbs as plain text)

  1. ' Check command line parameters
  2. Select Case WScript.Arguments.Count
  3. 	Case 0
  4. 		' Default if none specified is local computer (".")
  5. 		Set objWMIService = GetObject( "winmgmts://./root/cimv2" )
  6. 		Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
  7. 		For Each objItem in colItems
  8. 			strComputer = objItem.Name
  9. 		Next
  10. 	Case 1
  11. 		' Command line parameter can either be a computer name
  12. 		' or "/?" to request online help
  13. 		strComputer = Wscript.Arguments(0)
  14. 		if InStr( strComputer, "?" ) > 0 Then Syntax
  15. 	Case Else
  16. 		' Maximum is 1 command line parameter
  17. 		Syntax
  18. End Select
  19.  
  20. ' Set initial values of variables used
  21. strMsg = " found on \\" & strComputer & ":"
  22. intCount = 0
  23.  
  24. ' Enable error handling
  25. On Error Resume Next
  26. ' Connect to the computer
  27. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  28. If Err Then DispErr
  29.  
  30. ' Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where MediaType=11",,48)
  31. Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where DriveType=5",,48)
  32. If Err Then DispErr
  33. For Each objItem in colItems
  34. 	intCount = intCount + 1
  35. 	strMsg = strMsg &  " " & objItem.Name
  36. Next
  37.  
  38. ' Format the screen output
  39. If intCount = 1 Then
  40. 	strDrive = "drive"
  41. Else
  42. 	strDrive = "drives"
  43. End If
  44. strMsg = vbCrLf & intCount & " CD-ROM " & strDrive & strMsg
  45.  
  46. ' Display the result
  47. WScript.Echo strMsg
  48.  
  49. ' Done
  50. WScript.Quit(0)
  51.  
  52.  
  53. Sub DispErr
  54. 	If Err.Number Then
  55. 		WScript.Echo vbCrLf & "Error # " & CStr( Err.Number ) & _
  56. 		             " " & Err.Description
  57. 		Err.Clear
  58. 		Syntax
  59. 	End If
  60. End Sub
  61.  
  62.  
  63. Sub Syntax
  64. 	strMsg = vbCrLf & "CDROM.vbs,  Version 1.10" & vbCrLf _
  65. 	       & "Display CD-ROM drive letters for any WMI enabled " _
  66. 	       & "computer on the network." & vbCrLf & vbCrLf _
  67. 	       & "Usage:  CSCRIPT  CDROM.VBS  [ computer_name ]" _
  68. 	       & vbCrLf & vbCrLf _
  69. 	       & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  70. 	       & " is the name of a WMI enabled computer on the network" _
  71. 	       & vbCrLf & vbCrLf _
  72. 	       & "Written by Rob van der Woude" & vbCrLf _
  73. 	       & "http://www.robvanderwoude.com" & vbCrLf
  74. 	WScript.Echo strMsg
  75. 	WScript.Quit(1)
  76. End Sub
  77.  

page last modified: 2024-04-16; loaded in 0.0054 seconds