Link to home
Start Free TrialLog in
Avatar of celtician
celticianFlag for American Samoa

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.

User generated image
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

Open in new window

Avatar of NVIT
NVIT
Flag of United States of America image

Add this above line 9:
Set WshShell = WScript.CreateObject("WScript.Shell")

Open in new window

Avatar of celtician

ASKER

It doesn't find the process, i guess the command line is not getting right the process id. It opens up a cmd window (right) however it gets instead the error in the next capture:User generated image
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
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial