Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumberating and Ending running tasks

Status
Not open for further replies.

cmwoodman

IS-IT--Management
Sep 20, 2000
32
US
I have not been able to find an example of seeing what was running and being able to end the running tasks on a remote system. does anyone have any ideas?

Thanks
 
You want to look up WMI win32_Process. That is what I use. The following code with get the running procs, but not kill them. I have not worked on that part yet. But this is a start:

strComputer = 10.10.10.10
Set oWmi = GetObject("winmgmts:{impersonationlevel=impersonate}!\\"&strComputer&"\root\cimv2")
query = "Select * from Win32_Process"
Set wql = oWmi.execQuery(query)
For Each item In wql
WScript.Echo(item.name)
next
Set wql = Nothing
Set owmi = Nothing
 
This is what i needed, I already have the kill part.

Thanks.
 
in your example it would be item.terminate()

But i would not do a test run with the script as written since it will kill EVERY task running. I was looking for Multiple instances of a paticular task and when i saw your example i remembered the stock examples of how to find a specific running task. then i just added the .terminate() at the end of my named object, and it works.

thanks

Using your example, here is the finished code below:

strComputer = 10.10.10.10
Set oWmi = GetObject("winmgmts:{impersonationlevel=impersonate}!\\"&strComputer&"\root\cimv2")
query = "Select * from Win32_Process Where name = 'notepad.exe'"
Set wql = oWmi.execQuery(query)
For Each item In wql
'WScript.Echo(item.name)
item.terminate()
next
Set wql = Nothing
Set owmi = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top