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??

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

Open in new window

LVL 1
celticianAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Dllhost (as far as I understand it) is a part of the operating system which is used to perform some essential tasks - to allow other apps to run correctly.
I'd suggest you do not kill instances of it - it might even cause your own app to die.
0
celticianAuthor Commented:
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??
0
AndyAinscowFreelance programmer / ConsultantCommented:
>>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
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

celticianAuthor Commented:
So should it wokr by just adding:

Set objLoc = createobject("wbemscripting.swbemlocator")
objLoc.Security_.privileges.addasstring "sedebugprivilege", true

Open in new window


???
0
celticianAuthor Commented:
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

Open in new window

0
celticianAuthor Commented:
Can anyone help?
0
celticianAuthor Commented:
????
0
AmitIT ArchitectCommented:
Use PSKill too from PSTools.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Spike99On-Site IT TechnicianCommented:
In later OSs, you could use "taskkill" to do that, but that wasn't available for 2000.  You could use the "PSkill" command at a DOS prompt.  But, looking at the info about that tool, I don't think you can forcefully shut down a process with that.

SysInternals has the download for PStools here:
https://technet.microsoft.com/en-us/sysinternals/bb896683.aspx

Or, you could install the Windows 2000 support tools from the installation CD to enable use of the "kill" command. This page has more details about that.  The "-F" switch will force the process to stop:
http://www.techrepublic.com/article/quick-tip-kill-frozen-windows-2000-applications-with-tlist-and-kill/
0
celticianAuthor Commented:
I'll be using PSKILL
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.