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 - How to terminate a Win32 process without using "winmgmts:"

Reply
 
Old 10-10-2008   #1 (permalink)
Smoreno


 
 

How to terminate a Win32 process without using "winmgmts:"

Hello,

I use the following script to terminate the process listed in it. As the
server gets loaded killing the process (terminate()) takes longer as the load
increases. The WMI service takes longer find and kill the process.

Other than calling WMI, is there another way to kill the process via script
that doesn't take a long time?

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'pcsws.exe'")
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strNameOfUser)
If strusername = strnameofuser Then
objProcess.Terminate()
Else
End If
Next
--
Smoreno - ADOT

My System SpecsSystem Spec
Old 10-10-2008   #2 (permalink)
James Whitlow


 
 

Re: How to terminate a Win32 process without using "winmgmts:"

"Smoreno" <Smoreno@xxxxxx> wrote in message
news:BC3F0888-3984-455B-8752-69DEEF321B11@xxxxxx
Quote:

> Hello,
>
> I use the following script to terminate the process listed in it. As the
> server gets loaded killing the process (terminate()) takes longer as the
> load
> increases. The WMI service takes longer find and kill the process.
>
> Other than calling WMI, is there another way to kill the process via
> script
> that doesn't take a long time?
You might consider shelling out to Taskkill:

http://technet.microsoft.com/en-us/l.../bb491009.aspx

I don't know if it is going to be faster or not, but it does allow you
to filter by username.


My System SpecsSystem Spec
Old 10-10-2008   #3 (permalink)
Smoreno


 
 

Re: How to terminate a Win32 process without using "winmgmts:"

Hello,

how do you determine the process id for the app to kill? This is a Citrix
environment so I need to make sure that the only the process ID for a
specific user is killed.
Don't we have to use WMI to determine the process ID for that?

--
Smoreno - ADOT


"James Whitlow" wrote:
Quote:

> "Smoreno" <Smoreno@xxxxxx> wrote in message
> news:BC3F0888-3984-455B-8752-69DEEF321B11@xxxxxx
Quote:

> > Hello,
> >
> > I use the following script to terminate the process listed in it. As the
> > server gets loaded killing the process (terminate()) takes longer as the
> > load
> > increases. The WMI service takes longer find and kill the process.
> >
> > Other than calling WMI, is there another way to kill the process via
> > script
> > that doesn't take a long time?
>
> You might consider shelling out to Taskkill:
>
> http://technet.microsoft.com/en-us/l.../bb491009.aspx
>
> I don't know if it is going to be faster or not, but it does allow you
> to filter by username.
>
>
>
My System SpecsSystem Spec
Old 10-10-2008   #4 (permalink)
James Whitlow


 
 

Re: How to terminate a Win32 process without using "winmgmts:"

>> "Smoreno" <Smoreno@xxxxxx> wrote in message
Quote:
Quote:

>> news:BC3F0888-3984-455B-8752-69DEEF321B11@xxxxxx
Quote:

>> > Hello,
>> >
>> > I use the following script to terminate the process listed in it. As
>> > the
>> > server gets loaded killing the process (terminate()) takes longer as
>> > the
>> > load
>> > increases. The WMI service takes longer find and kill the process.
>> >
>> > Other than calling WMI, is there another way to kill the process via
>> > script
>> > that doesn't take a long time?
>>
>> You might consider shelling out to Taskkill:
>>
>> http://technet.microsoft.com/en-us/l.../bb491009.aspx
>>
>> I don't know if it is going to be faster or not, but it does allow
>> you
>> to filter by username.
> Hello,
>
> how do you determine the process id for the app to kill? This is a Citrix
> environment so I need to make sure that the only the process ID for a
> specific user is killed.
> Don't we have to use WMI to determine the process ID for that?
You can use 'tasklist.exe' to list tasks with associated PID. However,
'taskkill.exe' allows you to specify a username, so you should be able to
isolate it's task killing to a specific user. I have not used 'taskkill.exe'
before, I was just offering it up as an alternative to WMI.

Can you offer the group additional details on what you are trying to
accomplish? We might be able to offer you other options if we better
understand what you are trying to accomplish.


My System SpecsSystem Spec
Old 10-11-2008   #5 (permalink)
mr_unreliable


 
 

Re: How to terminate a Win32 process without using "winmgmts:"

Smoreno wrote:
Quote:

> Other than calling WMI, is there another way to kill the process via script
> that doesn't take a long time?
>
hi Smoreno,

In addition to wmi and the previously mentioned TaskKill,
I suggest taking a look at sysInternals "Process Explorer":

http://technet.microsoft.com/en-us/s.../bb896653.aspx

The sysInternals group was previously run by Mark Russinovich,
but has since been taken over by microsoft (as you can see by
the url). The Process Explorer utility will tell you everything
you ever wanted to know about your running processes, and more
to the point will allow you to kill a process (either from the
main menu, or a context menu). However, I can't say whether
it will be any faster than wmi, except that M.R. is one clever
guy and if there is a faster way -- he knows it.

The Process Explorer utility is not scriptable, other than via
appactivate and sendkeys. However I would strongly advise against
sending keys (ever!), and just using the gui provided.

If you happen to be courageous enough, or foolhardy enough to
call api's from script, then that is probably the "fastest way"
to kill a process. There are plenty of code samples available
to show how to do it. In short, you "walk-the-process-list"
(there are different ways to do this, depending on the system
you are using). You walk-the-process-list to get the process ID
of the process you are looking to terminate. Then to terminate
the process you use OpenProcess to open the process for termination,
then you use TerminateProcess api. WMI is nothing more than a
scriptable interface to this sort of code. Any delays you are
seeing may be due to the fact that it is not so simple to terminate
a process. There is a lot of "checking" to do (looking for child
threads, child processes, de-allocating system resources, freeing
dll's, etc). There is a "laundry list" to things that must be done
to properly terminate a process, and that may be taking time.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
"This application has requested the Runtime to terminate it in an unusual way." Vista performance & maintenance
"X is not a valid Win32 application" Error on EVERY executable Vista account administration
How to terminate a "For Each" statement VB Script
"this application has requested the runtime to terminate in an unusual way" Software
"*.pps is not a valid Win32 application" error message in Windows Vista installation & setup


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