Home All Groups Group Topic Archive Search About

Stopping Processes - Permission Errors



Author
8 Aug 2005 3:48 PM
Martypi
I need to stop a set of processes periodically.  The snippet of code that I'm
using to try and kill the processes is:

    Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & cComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process
Where Name = '" & strProcessName & "'")
    For Each objProcess in colProcessList
        RetVal = objProcess.Terminate()

I am an administrator on the server.  When I try to run the script, it will
kill some of the desired processes, but others I get permission denied.  I
can go into Task Manager and kill the processes with no problem. 

Any ideas on what I'm doing wrong?
Thanks,
Marty

Author
8 Aug 2005 4:11 PM
Torgeir Bakken (MVP)
Martypi wrote:

Show quote
> I need to stop a set of processes periodically.  The snippet of code that I'm
> using to try and kill the processes is:
>
>     Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & cComputer & "\root\cimv2")
>     Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process
> Where Name = '" & strProcessName & "'")
>     For Each objProcess in colProcessList
>         RetVal = objProcess.Terminate()
>
> I am an administrator on the server.  When I try to run the script, it will
> kill some of the desired processes, but others I get permission denied.  I
> can go into Task Manager and kill the processes with no problem. 
>
> Any ideas on what I'm doing wrong?
Hi,

See if taking the debug priviledge helps.

Change
  "{impersonationLevel=impersonate}!\\"

to
  "{impersonationLevel=impersonate,(Debug)}!\\"



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

AddThis Social Bookmark Button