celtician
asked on
Pskill not working on VBS script
On the next VBS script, pskill seems not to be working, see the error returned attached, and this is the code. i think it has to do with the declaration of wshShell?? But im not sure.
Option Explicit
Dim objWMIService, objProcess, objFSO, objTextFile
dim colProcess,colServices, colItems
dim objItem, objService
Dim strComputer, strProcessKill, strProcessMem
Dim memLimit, processMem
Dim mustKill
strComputer = "."
strProcessKill = "'DLLHOST.EXE'"
strProcessMem = "'DLLHOST'"
memLimit = 10000
mustKill = 0
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
dim intRC
For Each objProcess in colProcess
msgbox "Pid is..." & ObjProcess.ProcessId
processMem = objProcess.WorkingSetSize/1024
msgbox "Size is " & processMem
If processMem >= memLimit Then
MsgBox "is more than" & memLimit & " Kb"
mustKill = 1
Else
MsgBox "is less than " & memLimit & " Kb"
End If
if mustKill = 1 then
msgbox "im gonna kill it"
wshShell.Run "cmd /k C:\pskill.exe -accepteula ObjProcess", 1, True
if intRC = 0 Then
msgbox "Successfully killed process."
else
msgbox "Could not kill process. Error code: " & intRC
end if
end if
Next
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\informe_dllhost.txt", ForAppending, True)
if mustKill = 1 then
objTextFile.WriteLine(now & vbnewline & " Process has been killed with " & processMem & " Kb" & vbnewline & vbNewLine)
end if
objTextFile.Close
WScript.Quit
ASKER
ASKER
I ugess the error must be in line 33, i dont know what parameter send to the cmd that will evoke the pskill:
wshShell.Run "cmd /k C:\pskill.exe -accepteula ObjProcess", 1, True
wshShell.Run "cmd /k C:\pskill.exe -accepteula ObjProcess", 1, True
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window