EDN Admin
Well-known member
I cant seem to figure out how to get this code to work correctly.
<br/>
Menu Driven Computer / Network Tests<br/>
This VBScript program is run using the PC_Tests.cmd Batch Script<br/>
Set args = WScript.Arguments<br/>
WScript.Echo vbCrLf
Select Case args.Item(0)<br/>
Case "1"<br/>
Call System_Information<br/>
Case "2"<br/>
Call System_Memory_Size<br/>
Case "3"<br/>
Call OS_Version<br/>
Case "4"<br/>
Call Printers_Status<br/>
case "5"<br/>
Call Logical_HDD_Information<br/>
On Error GoTo ErrorRoutine<br/>
End Case
Sub System_Information<br/>
Set WshShell = WScript.CreateObject("WScript.Shell")<br/>
WScript.Echo "The computer name is ............ " & _<br/>
WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")<br/>
WScript.Echo "The Num of CPUs is .............. " & _<br/>
WshShell.ExpandEnvironmentStrings("%NUMBER_OF_PROCESSORS%")<br/>
WScript.Echo "The Processor Architecture is ... " & _<br/>
WshShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")<br/>
End Sub
Sub System_Memory_Size<br/>
strComputer = "."<br/>
Set objWMIService = GetObject("winmgmts:" _<br/>
& "{impersonationLevel=impersonate}!\" _<br/>
& strComputer & "rootcimv2")<br/>
Set colComputer = objWMIService.ExecQuery _<br/>
("Select * from Win32_ComputerSystem")<br/>
For Each objComputer in colComputer<br/>
intRamMB = int((objComputer.TotalPhysicalMemory) /1048576)+1<br/>
Wscript.Echo "System Name ...... " & objComputer.Name _<br/>
& vbCrLf & "Total RAM ........ " & intRamMB & " MBytes."<br/>
End Sub
Sub OS_Version<br/>
strComputer = "."<br/>
Set objWMIService = GetObject("winmgmts:" _<br/>
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")<br/>
Set colOperatingSystems = objWMIService.ExecQuery _<br/>
("Select * from Win32_OperatingSystem")<br/>
WScript.Echo "The Operating System Detected is Shown Below:" & vbCrLf<br/>
For Each objOperatingSystem in colOperatingSystems<br/>
WScript.Echo objOperatingSystem.Caption & "Version: " & _<br/>
objOperatingSystem.Version<br/>
End Sub<br/>
<br/>
Sub Printers_Status<br/>
strComputer ="."<br/>
intPrinters = 1<br/>
Set objWMIService = GetObject _<br/>
("winmgmts:\" & strComputer & "rootCIMV2")<br/>
Set colItems = objWMIService.ExecQuery _<br/>
("SELECT * FROM Win32_Printer Where PrinterState > 0")<br/>
WScript.Sleep(1000)<br/>
For Each objItem In colItems<br/>
WScript.Echo _<br/>
"Printer: " & objItem.DeviceID & vbCrLf & _<br/>
"===============================================" & vbCrLf & _<br/>
"Driver Name ............. " & objItem.DriverName & vbCrLf & _<br/>
"Port Name ............... " & objItem.PortName & vbCrLf & _<br/>
"Printer State ........... " & objItem.PrinterState & vbCrLf & _<br/>
"Printer Status .......... " & objItem.PrinterStatus & vbCrLf & _<br/>
"Print Processor ......... " & objItem.PrintProcessor & vbCrLf & _<br/>
"Spool Enabled ........... " & objItem.SpoolEnabled & vbCrLf & _<br/>
"Shared .................. " & objItem.Shared & vbCrLf & _<br/>
"ShareName ............... " & objItem.ShareName & vbCrLf & _<br/>
"Horizontal Res .......... " & objItem.HorizontalResolution & vbCrLf & _<br/>
"Vertical Res ............ " & objItem.VerticalResolution & vbCrLf<br/>
intPrinters = intPrinters + 1<br/>
End Sub
Sub Logical_HDD_Information<br/>
strComputer = "."<br/>
Set objWMIService = GetObject _<br/>
("winmgmts:\" & strComputer & "rootcimv2")<br/>
Set colItems = objWMIService.ExecQuery _<br/>
("Select * from Win32_LogicalDisk Where FreeSpace > 0")<br/>
For Each objItem in colItems<br/>
WScript.Echo vbCrLf & _<br/>
"========================================" & vbCrLf & _<br/>
"Drive Letter ......... " & objItem.Name & vbCrLf & _<br/>
"Description .......... " & objItem.Description & vbCrLf & _<br/>
"Volume Name .......... " & objItem.VolumeName & vbCrLf & _<br/>
"Drive Type ........... " & objItem.DriveType & vbCrLf & _<br/>
"Media Type ........... " & objItem.MediaType & vbCrLf & _<br/>
"VolumeSerialNumber ... " & objItem.VolumeSerialNumber & vbCrLf & _<br/>
"Size ................. " & Int(objItem.Size /1073741824) & " GB" & vbCrLf & _<br/>
"Free Space ........... " & Int(objItem.FreeSpace /1073741824) & " GB"<br/>
End Sub
Sub ErrorRoutine(Case"1",Case"2",Case"3",Case"4",case"5")<br/>
MsgBox"(chr(7) & chr(7)" & Error, Correct Values are 1..5 or X!!<br/>
End Sub
View the full article
<br/>
Menu Driven Computer / Network Tests<br/>
This VBScript program is run using the PC_Tests.cmd Batch Script<br/>
Set args = WScript.Arguments<br/>
WScript.Echo vbCrLf
Select Case args.Item(0)<br/>
Case "1"<br/>
Call System_Information<br/>
Case "2"<br/>
Call System_Memory_Size<br/>
Case "3"<br/>
Call OS_Version<br/>
Case "4"<br/>
Call Printers_Status<br/>
case "5"<br/>
Call Logical_HDD_Information<br/>
On Error GoTo ErrorRoutine<br/>
End Case
Sub System_Information<br/>
Set WshShell = WScript.CreateObject("WScript.Shell")<br/>
WScript.Echo "The computer name is ............ " & _<br/>
WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")<br/>
WScript.Echo "The Num of CPUs is .............. " & _<br/>
WshShell.ExpandEnvironmentStrings("%NUMBER_OF_PROCESSORS%")<br/>
WScript.Echo "The Processor Architecture is ... " & _<br/>
WshShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")<br/>
End Sub
Sub System_Memory_Size<br/>
strComputer = "."<br/>
Set objWMIService = GetObject("winmgmts:" _<br/>
& "{impersonationLevel=impersonate}!\" _<br/>
& strComputer & "rootcimv2")<br/>
Set colComputer = objWMIService.ExecQuery _<br/>
("Select * from Win32_ComputerSystem")<br/>
For Each objComputer in colComputer<br/>
intRamMB = int((objComputer.TotalPhysicalMemory) /1048576)+1<br/>
Wscript.Echo "System Name ...... " & objComputer.Name _<br/>
& vbCrLf & "Total RAM ........ " & intRamMB & " MBytes."<br/>
End Sub
Sub OS_Version<br/>
strComputer = "."<br/>
Set objWMIService = GetObject("winmgmts:" _<br/>
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")<br/>
Set colOperatingSystems = objWMIService.ExecQuery _<br/>
("Select * from Win32_OperatingSystem")<br/>
WScript.Echo "The Operating System Detected is Shown Below:" & vbCrLf<br/>
For Each objOperatingSystem in colOperatingSystems<br/>
WScript.Echo objOperatingSystem.Caption & "Version: " & _<br/>
objOperatingSystem.Version<br/>
End Sub<br/>
<br/>
Sub Printers_Status<br/>
strComputer ="."<br/>
intPrinters = 1<br/>
Set objWMIService = GetObject _<br/>
("winmgmts:\" & strComputer & "rootCIMV2")<br/>
Set colItems = objWMIService.ExecQuery _<br/>
("SELECT * FROM Win32_Printer Where PrinterState > 0")<br/>
WScript.Sleep(1000)<br/>
For Each objItem In colItems<br/>
WScript.Echo _<br/>
"Printer: " & objItem.DeviceID & vbCrLf & _<br/>
"===============================================" & vbCrLf & _<br/>
"Driver Name ............. " & objItem.DriverName & vbCrLf & _<br/>
"Port Name ............... " & objItem.PortName & vbCrLf & _<br/>
"Printer State ........... " & objItem.PrinterState & vbCrLf & _<br/>
"Printer Status .......... " & objItem.PrinterStatus & vbCrLf & _<br/>
"Print Processor ......... " & objItem.PrintProcessor & vbCrLf & _<br/>
"Spool Enabled ........... " & objItem.SpoolEnabled & vbCrLf & _<br/>
"Shared .................. " & objItem.Shared & vbCrLf & _<br/>
"ShareName ............... " & objItem.ShareName & vbCrLf & _<br/>
"Horizontal Res .......... " & objItem.HorizontalResolution & vbCrLf & _<br/>
"Vertical Res ............ " & objItem.VerticalResolution & vbCrLf<br/>
intPrinters = intPrinters + 1<br/>
End Sub
Sub Logical_HDD_Information<br/>
strComputer = "."<br/>
Set objWMIService = GetObject _<br/>
("winmgmts:\" & strComputer & "rootcimv2")<br/>
Set colItems = objWMIService.ExecQuery _<br/>
("Select * from Win32_LogicalDisk Where FreeSpace > 0")<br/>
For Each objItem in colItems<br/>
WScript.Echo vbCrLf & _<br/>
"========================================" & vbCrLf & _<br/>
"Drive Letter ......... " & objItem.Name & vbCrLf & _<br/>
"Description .......... " & objItem.Description & vbCrLf & _<br/>
"Volume Name .......... " & objItem.VolumeName & vbCrLf & _<br/>
"Drive Type ........... " & objItem.DriveType & vbCrLf & _<br/>
"Media Type ........... " & objItem.MediaType & vbCrLf & _<br/>
"VolumeSerialNumber ... " & objItem.VolumeSerialNumber & vbCrLf & _<br/>
"Size ................. " & Int(objItem.Size /1073741824) & " GB" & vbCrLf & _<br/>
"Free Space ........... " & Int(objItem.FreeSpace /1073741824) & " GB"<br/>
End Sub
Sub ErrorRoutine(Case"1",Case"2",Case"3",Case"4",case"5")<br/>
MsgBox"(chr(7) & chr(7)" & Error, Correct Values are 1..5 or X!!<br/>
End Sub
View the full article