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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't terminate two processes using HTA

Status
Not open for further replies.

nkntb

Technical User
Jun 3, 2005
8
US
Hello,

I use this vbscript to kill two processes calc.exe and freecell.exe and it works fine.
But if I convert it into an HTA, it only kills one process.
Does anyone know why?
Thanks,

Here is the script.

‘’’’beginning of the script’’’’

On Error Resume Next
strComputer = "."
arrTargetProcs = Array("calc.exe","freecell.exe")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each strTargetProc In arrTargetProcs
Set colProcesses = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name='" & strTargetProc & "'")
For Each objProcess in colProcesses
objProcess.Terminate
Next
Next

’’end of script’’’’
 
If you remove the "On Error Resume Next" do you get an error?

Also, you know you can include more than one process in the query right? Name = 'calc.exe' or Name = 'freecel.exe'

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Hello Dm4ever,

Thank you for your responds.

I copied the code from my post back to my HTA and it works.
Not sure what happen here.

Just out of curiosity. Can you Shed some light on how to include more than one process in the query?

Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top