Hey guys; havin' a problem with this code here; can't seem to work out whats goin' wrong with it. All other variables seem to print fine in the HTML ouput; but I get an error that relates to the cputype variable. I get the following error
C:\Users\Methical\Desktop\sysinfo.vbs(235,1) Microsoft VBScript runtime error: Invalid procedure call or argument
I think it has somethin' to do with this line here
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>CPU</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & cputype & "</i></td></tr>"
If i delete this line; the script compiles and outputs with no errors.
Here is the full code below
Dim strComputer, objWMIService, propValue, objItem
Dim strUserName, strPassword, colItems, SWBemlocator
' This section querries for the workstation to be scanned.
UserName = ""
Password = ""
strComputer = "127.1.1.1"
ImgDir = "C:\Scripts\images\"
'Sets up the connections and opjects to be used throughout the script.
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(,"root\CIMV2",strUserName,strPassword)
'This determines the current date and time of the PC being scanned.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LocalTime", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
If objItem.Minute < 10 Then
theMinutes = "0" & objItem.Minute
Else
theMinutes = objItem.Minute
End If
If objItem.Second < 10 Then
theSeconds = "0" & objItem.Second
Else
theSeconds = objItem.Second
End If
DateTime = objItem.Month & "/" & objItem.Day & "/" & objItem.Year & " - " & objItem.Hour & ":" & theMinutes & ":" & theSeconds
Next
'Gets some ingomation about the Operating System including Service Pack level.
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
WKID = objItem.CSName
WKOS = objItem.Caption
CSD = objItem.CSDVersion
Architecture = objItem.OSArchitecture
SysDir = objItem.SystemDirectory
SysDrive = objItem.SystemDrive
WinDir = objItem.WindowsDirectory
ServicePack = objItem.ServicePackMajorVersion & "." & objItem.ServicePackMinorVersion
Next
'This section returns the Time Zone
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objItem in colItems
Zone = objItem.Description
Next
'This section displays the Shadow Storage information
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowStorage")
For Each objItem in colItems
Allocated = int((objItem.AllocatedSpace/1024)/1024+1)
UsedSpace = int((objItem.UsedSpace/1024)/1024+1)
MaxSpace = int((objItem.MaxSpace/1024)/1024+1)
Next
'This section returns the InstallDate of the OS
Set objSWbemDateTime = _
CreateObject("WbemScripting.SWbemDateTime")
Set colOperatingSystems = _
objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem _
in colOperatingSystems
objSWbemDateTime.Value = _
objOperatingSystem.InstallDate
InstallDate = _
objSWbemDateTime.GetVarDate(False)
Next
'This section returns the Video card and current resolution.
Set colItems = objWMIService.ExecQuery("Select * from Win32_DisplayConfiguration",,48)
For Each objItem in colItems
VideoCard = objItem.DeviceName
Resolution = objItem.PelsWidth & " x " & objItem.PelsHeight & " x " & objItem.BitsPerPel & " bits"
Next
'This section returns the Video card memory.
Set objWMIService = GetObject("winmgmts:root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_VideoController")
For Each objItem in colItems
VideoMemory = objItem.AdapterRAM/1024/1024
Next
'This returns various system information including current logged on user, domain, memory, manufacture and model.
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
UserName = objItem.UserName
Domain = objItem.Domain
TotalMemory = int((objItem.TotalPhysicalMemory/1024)/1024+1)
Manufacturer = objItem.Manufacturer
Model = objItem.Model
SysType = objItem.SystemType
Next
'This determines the total hard drive space and free hard drive space.
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where Name='C:'",,48)
For Each objItem in colItems
FreeHDSpace = Fix(((objItem.FreeSpace/1024)/1024)/1024)
TotalHDSpace = Fix(((objItem.Size/1024)/1024)/1024)
Next
'This section returns the default printer and printer port.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer where Default=True", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
Printer = objItem.Name
PortName = objItem.PortName
Next
'This returns the CPU information.
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
CPUDesc = LTrim(objItem.Name)
Next
'// CPU Info
For each objCPU in GetObject("winmgmts:{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2").InstancesOf("Win32_Processor")
Select Case objCPU.Family
Case 2
cputype = "Unknown"
Case 11
cputype = "Pentium brand"
Case 12
cputype = "Pentium Pro"
Case 13
cputype = "Pentium II"
Case 14
cputype = "Pentium processor with MMX technology"
Case 15
cputype = "Celeron "
Case 16
cputype = "Pentium II Xeon"
Case 17
cputype = "Pentium III"
Case 28
cputype = "AMD Athlon Processor Family"
Case 29
cputype = "AMD Duron Processor"
Case 30
cputype = "AMD2900 Family"
Case 31
cputype = "K6-2+"
Case 130
cputype = "Itanium Processor"
Case 176
cputype = "Pentium III Xeon"
Case 177
cputype = "Pentium III Processor with Intel SpeedStep Technology"
Case 178
cputype = "Pentium 4"
Case 179
cputype = "Intel Xeon"
Case 181
cputype = "Intel Xeon processor MP"
Case 182
cputype = "AMD AthlonXP Family"
Case 183
cputype = "AMD AthlonMP Family"
Case 184
cputype = "Intel Itanium 2"
Case 185
cputype = "AMD Opteron Family"
End Select
Next
'This returns the current uptime (time since last reboot) of the system.
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
Uptime = dtmSystemUptime
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) & " " & Mid (dtmBootup, 9, 2) & ":" & Mid(dtmBootup, 11,
2) & ":" & Mid(dtmBootup,13, 2))
End Function
dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
' -- The heart of the create file script -----------------------
' -- Creates the file using the value of strFile on Line 11
' --------------------------------------------------------------
Set fileOutput = objFSO.CreateTextFile( "x.html", true )
'Set fileOutput = objExplorer.Document
'This is the code for the web page to be displayed.
fileOutput.WriteLine "<html>"
fileOutput.WriteLine " <head>"
fileOutput.WriteLine " <title>System Information for '" & WKID & "' </title>"
fileOutput.WriteLine " </head>"
fileOutput.WriteLine " <body bgcolor='#FFFFFF' text='#000000' link='#0000FF' vlink='000099' alink='#00FF00'>"
fileOutput.WriteLine " <center>"
fileOutput.WriteLine " <h1>System Information for " & WKID & "</h1>"
fileOutput.WriteLine " <table border='0' cellspacing='1' cellpadding='1' width='95%'>"
fileOutput.WriteLine " <tr><td background='" & ImgDir & "blue_spacer.gif'>"
fileOutput.WriteLine " <table border='0' cellspacing='0' cellpadding='0' width='100%'>"
fileOutput.WriteLine " <tr><td>"
fileOutput.WriteLine " <table border='0' cellspacing='0' cellpadding='0' width='100%'>"
fileOutput.WriteLine " <tr>"
fileOutput.WriteLine " <td width='5%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'><img src='" & ImgDir &
"write.gif'></td>"
fileOutput.WriteLine " <td width='95%' align='left' valign='middle' background='" & ImgDir & "blue_spacer.gif'> <font
color='#FFFFFF' size='5'>WKInfo - </font><font color='#FFFFFF' size='3'>General information on the Workstation.</font></td>"
fileOutput.WriteLine " </tr>"
fileOutput.WriteLine " <tr><td colspan='2' bgcolor='#FFFFFF'>"
fileOutput.WriteLine " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0'
bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Date and Time</h3></b></TD></TR>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Date/Time</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & DateTime & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Uptime</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & Uptime & " hours</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Time Zone</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & Zone & " </i></td></tr>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Computer
Information</h3></b></TD></TR>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Manufacturer</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & Manufacturer & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Model</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & Model & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Based</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & SysType & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & WKOS & " " & CSD & " " & Architecture & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Operating System Install Date</TD><td width='70%'
bgcolor=#f0f0f0 align=left><i>" & InstallDate & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>UserName</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & UserName & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Workstation Name</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & WKID & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Domain</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & Domain & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Drive</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & SysDrive & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>System Directory</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & SysDir & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Windows Directory</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & WinDir & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Allocated Space</TD><td width='70%'
bgcolor=#f0f0f0 align=left><i>" & Allocated & " MB</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Used Space</TD><td width='70%'
bgcolor=#f0f0f0 align=left><i>" & UsedSpace & " MB</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>ShadowStorage Max Space</TD><td width='70%'
bgcolor=#f0f0f0 align=left><i>" & MaxSpace & " MB</i></td></tr>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Hardware
Information</h3></b></TD></TR>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>CPU</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & cputype & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & TotalMemory & " MB</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Total HDD Space</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & TotalHDSpace & " GB</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Free HDD Space</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & FreeHDSpace & " GB</i></td></tr>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>General Video Card
Information</h3></b></TD></TR>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Video Card</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & VideoCard & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Resolution</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & Resolution & "</i></td></tr>"
fileOutput.WriteLine " <TR><TD width='30%' align='left' bgcolor='#e0e0e0'>Memory</TD><td width='70%' bgcolor=#f0f0f0
align=left><i>" & VideoMemory & " MB</i></td></tr>"
'This section lists all the current services and their status.
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Service
Information</h3></b></TD></TR>"
fileOutput.WriteLine " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLine " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0'
bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLine " <TR><TD width='70%' align='center' bgcolor='#e0e0e0'><b>Service Name</b></td><TD width='30%'
align='center' bgcolor='#e0e0e0'><b>Service State</b></td><tr>"
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objService in colRunningServices
fileOutput.WriteLine " <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0
align=center><i>" & objService.State & "</i></td></tr>"
wscript.echo " <TR><TD align='left' bgcolor='#f0f0f0'>" & objService.DisplayName & "</TD><td bgcolor=#f0f0f0
align=center><i>" & objService.State & "</i></td></tr>"
Next
fileOutput.WriteLine " </table>"
fileOutput.WriteLine " </td></tr>"
'This section lists all the current running processes and some information.
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><h3>Current Process
Information</h3></b></TD></TR>"
fileOutput.WriteLine " <tr><td colspan='2' bgcolor='#f0f0f0'>"
fileOutput.WriteLine " <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0'
bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLine " <TR><TD width='10%' align='center' bgcolor='#e0e0e0'><b>PID</b></td><TD width='35%'
align='center' bgcolor='#e0e0e0'><b>Process Name</b></td><TD width='40%' align='center' bgcolor='#e0e0e0'><b>Owner</b></td><TD width='15%' align='center'
bgcolor='#e0e0e0'><b>Memory</b></td></tr>"
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#f0f0f0'>" & objProcess.Handle & "</td><TD align='center'
bgcolor='#f0f0f0'>" & objProcess.Name & "</td><TD align='center' bgcolor='#f0f0f0'>" & strUserDomain & "\" & strNameOfUser & "</td><TD align='center'
bgcolor='#f0f0f0'>" & objProcess.WorkingSetSize/1024 & " kb</td><tr>"
Next
fileOutput.WriteLine " </table>"
fileOutput.WriteLine " </td></tr>"
'This section lists all the currently installed software on the machine.
fileOutput.WriteLine " <TR><TD align='center' bgcolor='#d0d0d0' colspan='2'><b><i>Installed Software</i></b></TD></TR>"
fileOutput.WriteLine " <tr><td colspan='2' bgcolor='#f0f0f0'>"
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product")
For Each objSoftware in colSoftware
fileOutput.WriteLine" <TABLE width='100%' cellspacing='0' cellpadding='2' border='1' bordercolor='#c0c0c0'
bordercolordark='#ffffff' bordercolorlight='#c0c0c0'>"
fileOutput.WriteLine" <tr><td width=30% align=center bgcolor='#e0e0e0'><b>Name</b></td><td width=30% align=center
bgcolor='#e0e0e0'><b>Vendor</b></td><td width=30% align=center bgcolor='#e0e0e0'><b>Version</b></td></tr>"
fileOutput.WriteLine" <tr><td align=center bgcolor=#f0f0f0>" & objSoftware.Name & "</td><td align=center
bgcolor=#f0f0f0>" & objSoftware.Vendor & "</td><td align=center bgcolor=#f0f0f0>" & objSoftware.Version & "</td></tr>"
fileOutput.WriteLine" <tr height=2><td height=10 align=center bgcolor=midnightblue colspan=3></td></tr>"
fileOutput.WriteLine" </table>"
Next
fileOutput.WriteLine " </td></tr>"
fileOutput.WriteLine " </table>"
fileOutput.WriteLine " </td></tr>"
fileOutput.WriteLine " </table>"
fileOutput.WriteLine " </td></tr>"
fileOutput.WriteLine " </table>"
fileOutput.WriteLine " </td></tr>"
fileOutput.WriteLine " </table>"
fileOutput.WriteLine " <p><small></small></p>"
fileOutput.WriteLine " </center>"
fileOutput.WriteLine " </body>"
fileOutput.WriteLine "<html>"
fileOutput.close
WScript.Quit