celtician
asked on
Problems executing VBS script in Windows 2000
The next script that must kill dllhost when it consumes over 80% of CPU keeps returning the same error:
Script:
Error:
C:\>cscript.exe /nologo "C:\myscript.vbs"
C:\myscript.vbs(10, 2) SWbemObjectSet: Non Specified Error
Script:
strProcess = "dllhost"
intLimit = 80
strLogFile = "C:\Temp\dllhost.log"
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
While True
Set colPerf = objWMI.ExecQuery("Select * From Win32_PerfFormattedData_PerfProc_Process Where Name='" & strProcess & "' Or Name like '" & strProcess & "#%'")
If colPerf.Count = 0 Then
Wscript.StdErr.WriteLine "No Instance(s) Available."
Else
For Each objPerf in colPerf
intPercentProcessorTime = CInt(objPerf.PercentProcessorTime)
If intPercentProcessorTime > intLimit Then
Set objLog = objFSO.OpenTextFile(strLogFile, ForAppending, True)
objLog.WriteLine "[" & Date & "][" & Time & "] Killed " & strProcess & " with PID " & objPerf.IDProcess & "."
objLog.Close
Set colProcess = objWMI.ExecQuery("Select * From Win32_Process Where ProcessId='" & objPerf.IDProcess & "'")
For Each objProcess in colProcess
objProcess.Terminate
Next
Else
Wscript.StdOut.WriteLine "Usage for PID " & objPerf.IDProcess & " at " & objPerf.PercentProcessorTime & " at " & Time
End If
Next
End If
Wscript.Sleep 60 * 1000
Wend
Error:
C:\>cscript.exe /nologo "C:\myscript.vbs"
C:\myscript.vbs(10, 2) SWbemObjectSet: Non Specified Error
ASKER
Ok, im trying today as soon as i get to work? have you tried it yet??
ASKER
Thanks for the answer, after making the suggested changes and executing the script i get now the next error:
C:\>cscript.exe /nologo "C:\myscript.vbs"
C:\myscript.vbs(11, 13) 0x80041017
With that hex value at the end... i have checked over google and seems to be something related to WMI, but i really don't know how to handle this... :S
C:\>cscript.exe /nologo "C:\myscript.vbs"
C:\myscript.vbs(11, 13) 0x80041017
With that hex value at the end... i have checked over google and seems to be something related to WMI, but i really don't know how to handle this... :S
ASKER
Can any one shed some light please?
The error is the result of the query returning a null result. Maybe you're specifying something that is not supported in the Win32_PerfFormattedData_Pe rfProc_Pro cess under Window 2000.
ASKER
It simply has to kill dllhost when it exceeds 80% of CPU, doesn't require any program or specifical config, should be able to be executed on any win2000 server...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In this case i get the next error:
myscript.vbs(2, 1) SWbemServices: Non Valid Class
:(
myscript.vbs(2, 1) SWbemServices: Non Valid Class
:(
Did you use the script I give? or is there something else in it except my code? Because I test it and it is working fine on my machine.
ASKER
Yes i used it exactly as it its, is there any special instruction on compilation?
maybe should i change any settings in the server config??
maybe should i change any settings in the server config??
It seems your machine don't have certain WMI files. Have a look at the following link:
http://networkadminkb.com/KB/a73/wmi-invalid-class-error-caused-by-missing-files.aspx
Or you can try this script on any other machine.
http://networkadminkb.com/KB/a73/wmi-invalid-class-error-caused-by-missing-files.aspx
Or you can try this script on any other machine.
ASKER
I have taken a look at that link however i really don't want to change any configuration as i don't have the knowledge to fix any damage or i dont know what can happen... there is an important application running on that server used by hundreds of people everyday...
This is the version of the Win 2000 we have installed:
This is the version of the Win 2000 we have installed:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes you can replace Win32_PerfFormattedData_Pe rfProc_Pro cess with Win32_PerfRawData_PerfProc _Process.
http://computer-programming-forum.com/59-vbscript/789e84bf5a91ddfb.htm
http://computer-programming-forum.com/59-vbscript/789e84bf5a91ddfb.htm
ASKER
Now it detect it, thank you!
https://technet.microsoft.com/en-us/library/ee198934.aspx
You can't use the
colPerf.Count
After
Set colPerf = objWMI.ExecQuery(
Because it is forward only return type. Count will took the result of query to the end.
So the modified script would be:
strProcess = "dllhost"
intLimit = 80
strLogFile = "C:\Temp\dllhost.log"
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.Fi
Set objWMI = GetObject("winmgmts:{imper
While True
Set colPerf = objWMI.ExecQuery("Select * From Win32_PerfFormattedData_Pe
For Each objPerf in colPerf
intPercentProcessorTime = CInt(objPerf.PercentProces
If intPercentProcessorTime > intLimit Then
Set objLog = objFSO.OpenTextFile(strLog
objLog.WriteLine "[" & Date & "][" & Time & "] Killed " & strProcess & " with PID " & objPerf.IDProcess & "."
objLog.Close
Set colProcess = objWMI.ExecQuery("Select * From Win32_Process Where ProcessId='" & objPerf.IDProcess & "'")
For Each objProcess in colProcess
objProcess.Terminate
Next
Else
Wscript.StdOut.WriteLine "Usage for PID " & objPerf.IDProcess & " at " & objPerf.PercentProcessorTi
End If
Next
Wscript.Sleep 60 * 1000
Wend