celtician
asked on
Kill system process in windows 2000
My next script is working fine detecting all the dllhost process that exceed certain amount of memory, however we can't make it kill dllhost as i guess it is a system process and objProcess.Terminate() won't kill it.
How can we make it kill such type of process??
How can we make it kill such type of process??
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 "El pid es..." & ObjProcess.ProcessId
processMem = objProcess.WorkingSetSize/1024
msgbox "El size es " & processMem
If processMem >= memLimit Then
MsgBox "pasa de " & memLimit & " Kb"
mustKill = 1
Else
MsgBox "es menor " & memLimit & " Kb"
End If
if mustKill = 1 then
msgbox "Im killing it"
objProcess.Terminate()
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 & " El proceso se ha matado con " & processMem & " Kb" & vbnewline & vbNewLine)
end if
objTextFile.Close
WScript.Quit
ASKER
Andy, we actually do this manually, its only for a few months, i know its not an elegant solution but thats what we need.
Is there any way of killing it??
Is there any way of killing it??
>>Is there any way of killing it??
The following may be of help.
Terminating a process (To terminate a process that you do not own, enable the SeDebugPrivilege privilege. In VBScript, you can enable this privilege with the following lines of code:):
https://msdn.microsoft.com/en-us/library/aa393907%28v=vs.85%29.aspx
setting privileges:
https://msdn.microsoft.com/en-us/library/aa446619%28v=vs.85%29.aspx
The following may be of help.
Terminating a process (To terminate a process that you do not own, enable the SeDebugPrivilege privilege. In VBScript, you can enable this privilege with the following lines of code:):
https://msdn.microsoft.com/en-us/library/aa393907%28v=vs.85%29.aspx
setting privileges:
https://msdn.microsoft.com/en-us/library/aa446619%28v=vs.85%29.aspx
ASKER
So should it wokr by just adding:
???
Set objLoc = createobject("wbemscripting.swbemlocator")
objLoc.Security_.privileges.addasstring "sedebugprivilege", true
???
ASKER
It keeps not killing the dllhost process:
Option Explicit
Dim objWMIService, objProcess, objFSO, objTextFile
dim colProcess,colServices, colItems
dim objItem, objService, objLoc
Dim strComputer, strProcessKill, strProcessMem
Dim memLimit, processMem
Dim mustKill
strComputer = "."
strProcessKill = "'DLLHOST.EXE'"
strProcessMem = "'DLLHOST'"
memLimit = 10000
mustKill = 0
Set objLoc = createobject("wbemscripting.swbemlocator")
objLoc.Security_.privileges.addasstring "sedebugprivilege", true
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 "El pid es..." & ObjProcess.ProcessId
processMem = objProcess.WorkingSetSize/1024
msgbox "El size es " & processMem
If processMem >= memLimit Then
MsgBox "pasa de " & memLimit & " Kb"
mustKill = 1
Else
MsgBox "es menor " & memLimit & " Kb"
End If
if mustKill = 1 then
msgbox "voy a matarlo"
objProcess.Terminate()
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 & " El proceso se ha matado con " & processMem & " Kb" & vbnewline & vbNewLine)
end if
objTextFile.Close
WScript.Quit
ASKER
Can anyone help?
ASKER
????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'll be using PSKILL
I'd suggest you do not kill instances of it - it might even cause your own app to die.