Link to home
Start Free TrialLog in
Avatar of robkarlen
robkarlenFlag for United States of America

asked on

How do I terminate a process based on application name instead of process name in vbs?

I'm looking for the correct syntax in vbs to kill a process based on it's application name in task manager.  My current code kills the process based on it's process name, but the problem now is that it kills all running iexplore processes whereas they require it to just kill one specific instance.
KillApps = "iexplore.exe, Please Wait.exe"
For Each app In Split(KillApps, ", ")
    Set objProcs=GetObject("winmgmts:\\.\root\cimv2").ExecQuery("select * from Win32_Process where Name='" & app & "'")
    For Each process In objProcs
        process.Terminate
    Next
Next
 
WScript.Quit

Open in new window

Avatar of robkarlen
robkarlen
Flag of United States of America image

ASKER

Would creating a small executable in AutoIT be my best solution?  I don't think it's possible to terminate on anything aside from process or PID.
Avatar of RobSampson
It is possible, but it requires that Microsoft Word is installed:

How Can I Close a Command Window with a Specific Title?
http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov05/hey1130.mspx

Regards,

Rob.
That's so very close to what I need but unfortunately not all of our machines have Word.  Can you create an object of word viewer and accomplish this by any chance? - it doesn't appear to be a builtin server class  Licensing restrictions do not allow us to have Word on every machine.

Thanks for the help so far, you've got me pointed in a good direction.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a bunch.  A little tweaking got me exactly what I needed.  I would have never ever thought of this approach so thank you so very much.
Thanks for the grade.

Was the tweaking anything major?  This appeared to work for me OK....

Regards,

Rob.