So... I've been using this thread ( )for a while now and it has been invaluable however I'm not much of a programmer, more of a sys admin but pieced parts of the code together and this is what I have done.
The problem is when I run this on a Windows 2003 server I get the following error message "Call function required". The scripts still runs but fails if a remote machine is listed. Can anyone see whats going on and where it's failing?
On Error Resume Next
'========================================================================================
' TITLE: Script Template
' Description: Used for creating any script that will be ran against multiple machines so
' that a countdown will display the number of machines remaining (can be used
' against single machines, but was mainly created for multiple machines),
' pings the machine to make sure it is online before proceeding, logs the
' machines that are offline.
'
' Requirements: pclist.txt for multiple machines (each machine listed on their own line)
'
'========================================================================================
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("WScript.Shell")
Const strScript = "Script Template" 'Title for the InputBox
Const PCL = "pclist.txt" 'List containing multiple machines to run script against
Const OFF = "offline.csv" 'Let me know if the machines are offline
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Force script to run in "CScript" mode
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
oShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
WScript.Quit
End If
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'-----------------------------------------------------------------------------
' User input to determine if script is ran against single or multiple machines.
'------------------------------------------------------------------------------
strComputer = InputBox("Which machine do you wish to run this script against?" & vbcrlf _
& vbcrlf & "Leave blank to run against " & chr(34) & PCL & chr(34),strScript,"")
If strComputer = "" Then
'--------------------------------------------------------------------------------------
'Check the date that pclist.txt was created to verify if we still want to use it or not.
'Select NO if you want to update the "pclist.txt"
'---------------------------------------------------------------------------------------
If oFS.FileExists(PCL)Then
Set file = oFS.GetFile(PCL)
myDate = file.DateLastModified
myOpt = MsgBox(PCL & " was created on " & myDate & vbcrlf & vbcrlf & "Would you still like to use it?",4,PCL & " check")
If myOpt = 7 Then
MsgBox "Script will now close.",0,"EXIT"
wscript.quit
End If
'-------------------------------------------------------------------------
'Grab the pclist and get a total count we are running the script against.
'This will give us our countdown in the Command Window as the script runs.
'-------------------------------------------------------------------------
Set file = oFS.GetFile(PCL)
Set pc = file.OpenAsTextStream(1,TristateUseDefault)
Do While pc.AtEndOfStream <> True
strComputer = Trim(pc.ReadLine)
strCount = strCount + 1
Loop
Set pc = file.OpenAsTextStream(1,TristateUseDefault)
Do While pc.AtEndOfStream <> True
strComputer = Trim(pc.ReadLine)
strCount = strCount - 1
wscript.echo strCount & " " & strComputer
Call PingMe(strComputer,strCount)
Call info
Loop
Else
'-----------------------------------------------------------
'No pclist.txt found and no machine name entered in InputBox
'-----------------------------------------------------------
wscript.echo "No " & PCL & " found!" & vbcr & "Script will now close."
wscript.quit
End If
Else
strCount = ""
Call PingMe(strComputer,strCount)
End If
wscript.echo "Finished"
'Functions
'------------------------------------------------------------------------------
Function PingMe(strComputer,strCount)
'-----------------------------------------------------------------------
'Verify that the machine is online before running the rest of the script
'-----------------------------------------------------------------------
Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + strComputer + "'")
For Each oPingResult In cPingResults
If oPingResult.StatusCode = 0 Then
wscript.echo "call function required"
Else
call LogEvent(strComputer,"Offline")
End If
Next
End Function
'+++++++++++++++++++++++++++++++++++++++++++++++++
Function LogEvent(pc,msg)
'--------------------------------
'Machine is OFFLINE, create a log
'--------------------------------
Set strLogFile = oFS.OpenTextFile(OFF,8,True)
strLogFile.WriteLine pc & "," & msg
strLogFile.Close
End Function
'+++++++++++++++++++++++++++++++++++++++++++++++++
Function info
On Error Resume Next
Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
strComputer = env.Item("Computername")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")
report = strComputer & " Computer Inventory" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "OS Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objItem in colItems
report = report & "Caption: " & objItem.Caption & vbCrLf
report = report & "Description: " & objItem.Description & vbCrLf
report = report & "EncryptionLevel: " & objItem.EncryptionLevel & vbCrLf
report = report & "InstallDate: " & objItem.InstallDate & vbCrLf
report = report & "Manufacturer: " & objItem.Manufacturer & vbCrLf
report = report & "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses & vbCrLf
report = report & "Name: " & objItem.Name & vbCrLf
report = report & "Organization: " & objItem.Organization & vbCrLf
report = report & "OSProductSuite: " & objItem.OSProductSuite & vbCrLf
report = report & "RegisteredUser: " & objItem.RegisteredUser & vbCrLf
report = report & "SerialNumber: " & objItem.SerialNumber & vbCrLf
report = report & "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion
report = report & "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
report = report & "Version: " & objItem.Version & vbCrLf
report = report & "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf
Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
report = report & "HP Serial: " & objSMBIOS.SerialNumber & vbCrLf
next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
For Each objItem in colItems
report = report & "Mac Address: " & objItem.MACAddress & vbCRLf
next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Memory and Processor Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objComputer in colSettings
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_Processor")
For Each objProcessor in colSettings
report = report & objProcessor.Description & " Processor" & vbCrLf
Next
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Disk Drive Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
report = report & objLogicalDisk.FreeSpace /1024\1024+1 & "MB Free Disk Space" & vbCrLf
report = report & objLogicalDisk.Size /1024\1024+1 & "MB Total Disk Space" & vbCrLf
oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
software = software & vbCrLf & "******************************************" & vbCrLf
software = software & "Installed Software" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each subkey In arrSubKeys
'MsgBox subkey
If Left (subkey, 1) <> "{" Then
software = software & subkey & vbCrLf
End If
Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("D:\temp\" & strComputer & ".txt", ForWriting)
ts.write report
ts.write software
End Function
The problem is when I run this on a Windows 2003 server I get the following error message "Call function required". The scripts still runs but fails if a remote machine is listed. Can anyone see whats going on and where it's failing?
On Error Resume Next
'========================================================================================
' TITLE: Script Template
' Description: Used for creating any script that will be ran against multiple machines so
' that a countdown will display the number of machines remaining (can be used
' against single machines, but was mainly created for multiple machines),
' pings the machine to make sure it is online before proceeding, logs the
' machines that are offline.
'
' Requirements: pclist.txt for multiple machines (each machine listed on their own line)
'
'========================================================================================
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject("WScript.Shell")
Const strScript = "Script Template" 'Title for the InputBox
Const PCL = "pclist.txt" 'List containing multiple machines to run script against
Const OFF = "offline.csv" 'Let me know if the machines are offline
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Force script to run in "CScript" mode
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
If Instr(1, WScript.FullName, "CScript", vbTextCompare) = 0 Then
oShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
WScript.Quit
End If
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'-----------------------------------------------------------------------------
' User input to determine if script is ran against single or multiple machines.
'------------------------------------------------------------------------------
strComputer = InputBox("Which machine do you wish to run this script against?" & vbcrlf _
& vbcrlf & "Leave blank to run against " & chr(34) & PCL & chr(34),strScript,"")
If strComputer = "" Then
'--------------------------------------------------------------------------------------
'Check the date that pclist.txt was created to verify if we still want to use it or not.
'Select NO if you want to update the "pclist.txt"
'---------------------------------------------------------------------------------------
If oFS.FileExists(PCL)Then
Set file = oFS.GetFile(PCL)
myDate = file.DateLastModified
myOpt = MsgBox(PCL & " was created on " & myDate & vbcrlf & vbcrlf & "Would you still like to use it?",4,PCL & " check")
If myOpt = 7 Then
MsgBox "Script will now close.",0,"EXIT"
wscript.quit
End If
'-------------------------------------------------------------------------
'Grab the pclist and get a total count we are running the script against.
'This will give us our countdown in the Command Window as the script runs.
'-------------------------------------------------------------------------
Set file = oFS.GetFile(PCL)
Set pc = file.OpenAsTextStream(1,TristateUseDefault)
Do While pc.AtEndOfStream <> True
strComputer = Trim(pc.ReadLine)
strCount = strCount + 1
Loop
Set pc = file.OpenAsTextStream(1,TristateUseDefault)
Do While pc.AtEndOfStream <> True
strComputer = Trim(pc.ReadLine)
strCount = strCount - 1
wscript.echo strCount & " " & strComputer
Call PingMe(strComputer,strCount)
Call info
Loop
Else
'-----------------------------------------------------------
'No pclist.txt found and no machine name entered in InputBox
'-----------------------------------------------------------
wscript.echo "No " & PCL & " found!" & vbcr & "Script will now close."
wscript.quit
End If
Else
strCount = ""
Call PingMe(strComputer,strCount)
End If
wscript.echo "Finished"
'Functions
'------------------------------------------------------------------------------
Function PingMe(strComputer,strCount)
'-----------------------------------------------------------------------
'Verify that the machine is online before running the rest of the script
'-----------------------------------------------------------------------
Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + strComputer + "'")
For Each oPingResult In cPingResults
If oPingResult.StatusCode = 0 Then
wscript.echo "call function required"
Else
call LogEvent(strComputer,"Offline")
End If
Next
End Function
'+++++++++++++++++++++++++++++++++++++++++++++++++
Function LogEvent(pc,msg)
'--------------------------------
'Machine is OFFLINE, create a log
'--------------------------------
Set strLogFile = oFS.OpenTextFile(OFF,8,True)
strLogFile.WriteLine pc & "," & msg
strLogFile.Close
End Function
'+++++++++++++++++++++++++++++++++++++++++++++++++
Function info
On Error Resume Next
Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
strComputer = env.Item("Computername")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")
report = strComputer & " Computer Inventory" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "OS Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objItem in colItems
report = report & "Caption: " & objItem.Caption & vbCrLf
report = report & "Description: " & objItem.Description & vbCrLf
report = report & "EncryptionLevel: " & objItem.EncryptionLevel & vbCrLf
report = report & "InstallDate: " & objItem.InstallDate & vbCrLf
report = report & "Manufacturer: " & objItem.Manufacturer & vbCrLf
report = report & "MaxNumberOfProcesses: " & objItem.MaxNumberOfProcesses & vbCrLf
report = report & "Name: " & objItem.Name & vbCrLf
report = report & "Organization: " & objItem.Organization & vbCrLf
report = report & "OSProductSuite: " & objItem.OSProductSuite & vbCrLf
report = report & "RegisteredUser: " & objItem.RegisteredUser & vbCrLf
report = report & "SerialNumber: " & objItem.SerialNumber & vbCrLf
report = report & "ServicePackMajorVersion: " & objItem.ServicePackMajorVersion
report = report & "ServicePackMinorVersion: " & objItem.ServicePackMinorVersion & vbCrLf
report = report & "Version: " & objItem.Version & vbCrLf
report = report & "WindowsDirectory: " & objItem.WindowsDirectory & vbCrLf
Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
report = report & "HP Serial: " & objSMBIOS.SerialNumber & vbCrLf
next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
For Each objItem in colItems
report = report & "Mac Address: " & objItem.MACAddress & vbCRLf
next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Memory and Processor Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each objComputer in colSettings
'report = report & objComputer.Name & vbcrlf
report = report & objComputer.TotalPhysicalMemory /1024\1024+1 & "MB Total memory" & vbcrlf
Next
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_Processor")
For Each objProcessor in colSettings
report = report & objProcessor.Description & " Processor" & vbCrLf
Next
report = report & vbCrLf & "******************************************" & vbCrLf
report = report & "Disk Drive Information" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
report = report & objLogicalDisk.FreeSpace /1024\1024+1 & "MB Free Disk Space" & vbCrLf
report = report & objLogicalDisk.Size /1024\1024+1 & "MB Total Disk Space" & vbCrLf
oReg.EnumKey HKEY_LOCAL_MACHINE, UnInstPath, arrSubKeys
software = software & vbCrLf & "******************************************" & vbCrLf
software = software & "Installed Software" & vbCrLf & "******************************************" & vbCrLf & vbCrLf
For Each subkey In arrSubKeys
'MsgBox subkey
If Left (subkey, 1) <> "{" Then
software = software & subkey & vbCrLf
End If
Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("D:\temp\" & strComputer & ".txt", ForWriting)
ts.write report
ts.write software
End Function