Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for winver.vbs

(view source code of winver.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. On Error Resume Next
  21. ' Query and display running processes
  22. Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
  23. ' Display error number and description if applicable
  24. If Err.Number Then
  25. 	strMsg = vbCrLf & strComputer & vbCrLf & _
  26. 	         "Error # " & Err.Number & vbCrLf & _
  27. 	         Err.Description & vbCrLf & vbCrLf
  28. 	Syntax
  29. End If
  30.  
  31. ' Collect information on OS
  32. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  33. Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
  34. For Each objItem in colItems
  35.     strMsg = "Computer Name   : " & objItem.CSName & vbCrLf & _
  36.              "Windows Version : " & objItem.Caption & vbCrLf & _
  37.              "ServicePack     : " & objItem.CSDVersion & vbCrLf & _
  38.              "Build Number    : " & objItem.BuildNumber & vbCrLf & _
  39.              "Serial Number   : " & objItem.SerialNumber & vbCrLf
  40. Next
  41.  
  42. ' Display the results
  43. Wscript.Echo strMsg
  44.  
  45. ' Done
  46. WScript.Quit(0)
  47.  
  48.  
  49. Sub Syntax
  50. strMsg = strMsg & vbCrLf & vbCrLf & "WinVer.vbs,  Version 1.11" & vbCrLf _
  51.        & "Display Windows version for any WMI enabled computer on the network." _
  52.        & vbCrLf & vbCrLf _
  53.        & "Usage:  CSCRIPT  WINVER.VBS  [ computer_name ]" _
  54.        & vbCrLf & vbCrLf _
  55.        & "Where:  " & Chr(34) & "computer_name" & Chr(34) _
  56.        & " is the name of the computer to whose Windows version" & vbCrLf _
  57.        & "        is to be displayed (without leading backslashes)." _
  58.        & vbCrLf & vbCrLf _
  59.        & "        Default is " & Chr(34) & "." & Chr(34) _
  60.        & " (the local computer)." _
  61.        & vbCrLf & vbCrLf _
  62.        & "Written by Rob van der Woude" & vbCrLf _
  63.        & "http://www.robvanderwoude.com" _
  64.        & vbCrLf & vbCrLf _
  65.        & "Created using Microsoft's Scriptomatic tool" & vbCrLf _
  66.        & "http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/WMImatic.asp"
  67. Wscript.Echo(strMsg)
  68. Wscript.Quit(1)
  69. End Sub
  70.  

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