Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Cancel Process that is a System Task

Reply
 
Old 11-24-2008   #1 (permalink)
Installer


 
 

Cancel Process that is a System Task

I'm using VBS trying to cancel a process who's user is SYSTEM. The code
below work just fine for any process that I've started, but if I try one that
has a user of SYSTEM it doesn't work.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = ""MqrServerMon.exe""")

For Each objProcess in colProcessList
objProcess.Terminate()
Next
WSCript.Echo "Just killed process " _
& " on " & strComputer

This is pretty standard code to do this, but it just does not seem to be
working for the system users.

Thanks for any suggestions.
Rodney

My System SpecsSystem Spec
Old 11-24-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Cancel Process that is a System Task


"Installer" <Installer@xxxxxx> wrote in message
news:29729467-CD51-4EA5-AD1C-8D7B892CE174@xxxxxx
Quote:

> I'm using VBS trying to cancel a process who's user is SYSTEM. The code
> below work just fine for any process that I've started, but if I try one
> that
> has a user of SYSTEM it doesn't work.
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colProcessList = objWMIService.ExecQuery _
> ("Select * from Win32_Process Where Name = ""MqrServerMon.exe""")
>
> For Each objProcess in colProcessList
> objProcess.Terminate()
> Next
> WSCript.Echo "Just killed process " _
> & " on " & strComputer
>
> This is pretty standard code to do this, but it just does not seem to be
> working for the system users.
>
> Thanks for any suggestions.
> Rodney
Can you kill the task with taskkill.exe? If you can't the you'll probably
see a screen message that tells you the reason.


My System SpecsSystem Spec
Old 11-24-2008   #3 (permalink)
Installer


 
 

Re: Cancel Process that is a System Task

Yes, I have no problem with taskkill. My problem with using taskkill from
the shell command is that it ignores my vbHide parameter and I get the pop-up
cmd prompt. This looks really awful during an install so I was trying to get
everything into vbscript.

Thanks for the idea.

"Pegasus (MVP)" wrote:
Quote:

>
> "Installer" <Installer@xxxxxx> wrote in message
> news:29729467-CD51-4EA5-AD1C-8D7B892CE174@xxxxxx
Quote:

> > I'm using VBS trying to cancel a process who's user is SYSTEM. The code
> > below work just fine for any process that I've started, but if I try one
> > that
> > has a user of SYSTEM it doesn't work.
> >
> > strComputer = "."
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> >
> > Set colProcessList = objWMIService.ExecQuery _
> > ("Select * from Win32_Process Where Name = ""MqrServerMon.exe""")
> >
> > For Each objProcess in colProcessList
> > objProcess.Terminate()
> > Next
> > WSCript.Echo "Just killed process " _
> > & " on " & strComputer
> >
> > This is pretty standard code to do this, but it just does not seem to be
> > working for the system users.
> >
> > Thanks for any suggestions.
> > Rodney
>
> Can you kill the task with taskkill.exe? If you can't the you'll probably
> see a screen message that tells you the reason.
>
>
>
My System SpecsSystem Spec
Old 11-24-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

Re: Cancel Process that is a System Task


"Installer" <Installer@xxxxxx> wrote in message
news:1D0FF693-FDCD-431B-9428-981DE417C8B0@xxxxxx
Quote:

> Yes, I have no problem with taskkill. My problem with using taskkill from
> the shell command is that it ignores my vbHide parameter and I get the
> pop-up
> cmd prompt. This looks really awful during an install so I was trying to
> get
> everything into vbscript.
>
> Thanks for the idea.
With "taskkill" I intended to give some pointers only. However, I
subsequently found that I could not terminate System tasks either when using
your code. On the other hand I could use the "taskkill" work-around without
getting a pop-up Command Prompt by running this code:

Set ObjWshShell = WScript.CreateObject("WScript.Shell")
ObjWshShell.Run "taskkill.exe /f /im MqrServerMon.exe", 0, False


My System SpecsSystem Spec
Old 11-24-2008   #5 (permalink)
urkec


 
 

Re: Cancel Process that is a System Task

"Installer" wrote:
Quote:

> Yes, I have no problem with taskkill. My problem with using taskkill from
> the shell command is that it ignores my vbHide parameter and I get the pop-up
> cmd prompt. This looks really awful during an install so I was trying to get
> everything into vbscript.
>
> Thanks for the idea.
>
> "Pegasus (MVP)" wrote:
>
Quote:

> >
> > "Installer" <Installer@xxxxxx> wrote in message
> > news:29729467-CD51-4EA5-AD1C-8D7B892CE174@xxxxxx
Quote:

> > > I'm using VBS trying to cancel a process who's user is SYSTEM. The code
> > > below work just fine for any process that I've started, but if I try one
> > > that
> > > has a user of SYSTEM it doesn't work.
> > >
> > > strComputer = "."
> > > Set objWMIService = GetObject("winmgmts:" _
> > > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> > >
> > > Set colProcessList = objWMIService.ExecQuery _
> > > ("Select * from Win32_Process Where Name = ""MqrServerMon.exe""")
> > >
> > > For Each objProcess in colProcessList
> > > objProcess.Terminate()
> > > Next
> > > WSCript.Echo "Just killed process " _
> > > & " on " & strComputer
> > >
> > > This is pretty standard code to do this, but it just does not seem to be
> > > working for the system users.
> > >
> > > Thanks for any suggestions.
> > > Rodney
> >
> > Can you kill the task with taskkill.exe? If you can't the you'll probably
> > see a screen message that tells you the reason.
> >
> >
> >

Your WMI code should work providing that you use the right privileges:


strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, " _
& "(Debug)}!\\" _
& strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process " _
& "Where Name = 'someprocess.exe'")

For Each objProcess in colProcessList
intRetVal = objProcess.Terminate()
Next
WSCript.Echo "Just killed process " _
& " on " & strComputer


--
urkec
My System SpecsSystem Spec
Old 11-25-2008   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: Cancel Process that is a System Task


"urkec" <urkec@xxxxxx> wrote in message
news:6FC247B8-94DB-4E9B-A746-0DDF9031E5F6@xxxxxx
Quote:

> "Installer" wrote:
>
Quote:

>> Yes, I have no problem with taskkill. My problem with using taskkill
>> from
>> the shell command is that it ignores my vbHide parameter and I get the
>> pop-up
>> cmd prompt. This looks really awful during an install so I was trying to
>> get
>> everything into vbscript.
>>
>> Thanks for the idea.
>>
>> "Pegasus (MVP)" wrote:
>>
Quote:

>> >
>> > "Installer" <Installer@xxxxxx> wrote in message
>> > news:29729467-CD51-4EA5-AD1C-8D7B892CE174@xxxxxx
>> > > I'm using VBS trying to cancel a process who's user is SYSTEM. The
>> > > code
>> > > below work just fine for any process that I've started, but if I try
>> > > one
>> > > that
>> > > has a user of SYSTEM it doesn't work.
>> > >
>> > > strComputer = "."
>> > > Set objWMIService = GetObject("winmgmts:" _
>> > > & "{impersonationLevel=impersonate}!\\" & strComputer &
>> > > "\root\cimv2")
>> > >
>> > > Set colProcessList = objWMIService.ExecQuery _
>> > > ("Select * from Win32_Process Where Name = ""MqrServerMon.exe""")
>> > >
>> > > For Each objProcess in colProcessList
>> > > objProcess.Terminate()
>> > > Next
>> > > WSCript.Echo "Just killed process " _
>> > > & " on " & strComputer
>> > >
>> > > This is pretty standard code to do this, but it just does not seem to
>> > > be
>> > > working for the system users.
>> > >
>> > > Thanks for any suggestions.
>> > > Rodney
>> >
>> > Can you kill the task with taskkill.exe? If you can't the you'll
>> > probably
>> > see a screen message that tells you the reason.
>> >
>> >
>> >
>
>
> Your WMI code should work providing that you use the right privileges:
>
>
> strComputer = "."
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate, " _
> & "(Debug)}!\\" _
> & strComputer & "\root\cimv2")
>
> Set colProcessList = objWMIService.ExecQuery _
> ("Select * from Win32_Process " _
> & "Where Name = 'someprocess.exe'")
>
> For Each objProcess in colProcessList
> intRetVal = objProcess.Terminate()
> Next
> WSCript.Echo "Just killed process " _
> & " on " & strComputer
>
>
> --
> urkec
AFAICS, the only difference between the OP's code and yours is the (Debug)
qualifier, yet your version works. What exactly does (Debug) do?


My System SpecsSystem Spec
Old 11-25-2008   #7 (permalink)
Gilles LAURENT [MVP]


 
 

Re: Cancel Process that is a System Task

"Pegasus (MVP)" wrote:
Quote:

> AFAICS, the only difference between the OP's code and yours is the (Debug)
> qualifier, yet your version works. What exactly does (Debug) do?
Hello,

This privilege (SE_DEBUG_PRIVILEGE) is required to kill other users's
processes. You need to be an admin to be able to activate this privilege or
this one have to be manually granted to a user with the security policy
editor. The link below is very interesting (Specifically Table 6.8 :
Privileges and descriptions).

Hope this helps.

--
Gilles LAURENT
MVP Windows Server - Admin Frameworks
http://glsft.free.fr

My System SpecsSystem Spec
Old 11-25-2008   #8 (permalink)
urkec


 
 

Re: Cancel Process that is a System Task

"Pegasus (MVP)" wrote:
Quote:

>
> "urkec" <urkec@xxxxxx> wrote in message
> news:6FC247B8-94DB-4E9B-A746-0DDF9031E5F6@xxxxxx
Quote:

> > "Installer" wrote:
> >
Quote:

> >> Yes, I have no problem with taskkill. My problem with using taskkill
> >> from
> >> the shell command is that it ignores my vbHide parameter and I get the
> >> pop-up
> >> cmd prompt. This looks really awful during an install so I was trying to
> >> get
> >> everything into vbscript.
> >>
> >> Thanks for the idea.
> >>
> >> "Pegasus (MVP)" wrote:
> >>
> >> >
> >> > "Installer" <Installer@xxxxxx> wrote in message
> >> > news:29729467-CD51-4EA5-AD1C-8D7B892CE174@xxxxxx
> >> > > I'm using VBS trying to cancel a process who's user is SYSTEM. The
> >> > > code
> >> > > below work just fine for any process that I've started, but if I try
> >> > > one
> >> > > that
> >> > > has a user of SYSTEM it doesn't work.
> >> > >
> >> > > strComputer = "."
> >> > > Set objWMIService = GetObject("winmgmts:" _
> >> > > & "{impersonationLevel=impersonate}!\\" & strComputer &
> >> > > "\root\cimv2")
> >> > >
> >> > > Set colProcessList = objWMIService.ExecQuery _
> >> > > ("Select * from Win32_Process Where Name = ""MqrServerMon.exe""")
> >> > >
> >> > > For Each objProcess in colProcessList
> >> > > objProcess.Terminate()
> >> > > Next
> >> > > WSCript.Echo "Just killed process " _
> >> > > & " on " & strComputer
> >> > >
> >> > > This is pretty standard code to do this, but it just does not seem to
> >> > > be
> >> > > working for the system users.
> >> > >
> >> > > Thanks for any suggestions.
> >> > > Rodney
> >> >
> >> > Can you kill the task with taskkill.exe? If you can't the you'll
> >> > probably
> >> > see a screen message that tells you the reason.
> >> >
> >> >
> >> >
> >
> >
> > Your WMI code should work providing that you use the right privileges:
> >
> >
> > strComputer = "."
> >
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate, " _
> > & "(Debug)}!\\" _
> > & strComputer & "\root\cimv2")
> >
> > Set colProcessList = objWMIService.ExecQuery _
> > ("Select * from Win32_Process " _
> > & "Where Name = 'someprocess.exe'")
> >
> > For Each objProcess in colProcessList
> > intRetVal = objProcess.Terminate()
> > Next
> > WSCript.Echo "Just killed process " _
> > & " on " & strComputer
> >
> >
> > --
> > urkec
>
> AFAICS, the only difference between the OP's code and yours is the (Debug)
> qualifier, yet your version works. What exactly does (Debug) do?
>
>
>

It is the short form (that you can use in the winmgmts: moniker) of
SeDebugPrivilege. You can also enable it with

objWMIService.Security_.Privileges.AddAsString("SeDebugPrivilege")

or

Const wbemPrivilegeDebug = 19
objWMIService.Security_.Privileges.Add(wbemPrivilegeDebug)

See here for the complete list of privileges:

http://msdn.microsoft.com/en-us/libr...58(VS.85).aspx
--
urkec
My System SpecsSystem Spec
Old 11-25-2008   #9 (permalink)
Pegasus \(MVP\)


 
 

Re: Cancel Process that is a System Task


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:%23Iq4oitTJHA.5860@xxxxxx
Quote:

>
> "urkec" <urkec@xxxxxx> wrote in message
> news:6FC247B8-94DB-4E9B-A746-0DDF9031E5F6@xxxxxx
Quote:

>> "Installer" wrote:
>>
Quote:

>>> Yes, I have no problem with taskkill. My problem with using taskkill
>>> from
>>> the shell command is that it ignores my vbHide parameter and I get the
>>> pop-up
>>> cmd prompt. This looks really awful during an install so I was trying
>>> to get
>>> everything into vbscript.
>>>
>>> Thanks for the idea.
>>>
>>> "Pegasus (MVP)" wrote:
>>>
>>> >
>>> > "Installer" <Installer@xxxxxx> wrote in message
>>> > news:29729467-CD51-4EA5-AD1C-8D7B892CE174@xxxxxx
>>> > > I'm using VBS trying to cancel a process who's user is SYSTEM. The
>>> > > code
>>> > > below work just fine for any process that I've started, but if I try
>>> > > one
>>> > > that
>>> > > has a user of SYSTEM it doesn't work.
>>> > >
>>> > > strComputer = "."
>>> > > Set objWMIService = GetObject("winmgmts:" _
>>> > > & "{impersonationLevel=impersonate}!\\" & strComputer &
>>> > > "\root\cimv2")
>>> > >
>>> > > Set colProcessList = objWMIService.ExecQuery _
>>> > > ("Select * from Win32_Process Where Name = ""MqrServerMon.exe""")
>>> > >
>>> > > For Each objProcess in colProcessList
>>> > > objProcess.Terminate()
>>> > > Next
>>> > > WSCript.Echo "Just killed process " _
>>> > > & " on " & strComputer
>>> > >
>>> > > This is pretty standard code to do this, but it just does not seem
>>> > > to be
>>> > > working for the system users.
>>> > >
>>> > > Thanks for any suggestions.
>>> > > Rodney
>>> >
>>> > Can you kill the task with taskkill.exe? If you can't the you'll
>>> > probably
>>> > see a screen message that tells you the reason.
>>> >
>>> >
>>> >
>>
>>
>> Your WMI code should work providing that you use the right privileges:
>>
>>
>> strComputer = "."
>>
>> Set objWMIService = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate, " _
>> & "(Debug)}!\\" _
>> & strComputer & "\root\cimv2")
>>
>> Set colProcessList = objWMIService.ExecQuery _
>> ("Select * from Win32_Process " _
>> & "Where Name = 'someprocess.exe'")
>>
>> For Each objProcess in colProcessList
>> intRetVal = objProcess.Terminate()
>> Next
>> WSCript.Echo "Just killed process " _
>> & " on " & strComputer
>>
>>
>> --
>> urkec
>
> AFAICS, the only difference between the OP's code and yours is the (Debug)
> qualifier, yet your version works. What exactly does (Debug) do?
Thanks to both Gilles and urkec for the clarification. Fascinating stuff!


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to write a script to process it as a task? PowerShell
Cancel export certificate process in Windows Vista with IE 7 Vista security
Windows Task Manager or Process Explorer? General Discussion
Ending process in Task Manager doesn't end it Vista performance & maintenance
System Idle Process Vista performance & maintenance


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46