Hi Friends,

I'm a sequencing a application, where-in I need to kill a process just before the shutdown of my shortcut. I know PRE SHUTDOWN is not supported. So i have scripted to kill a process POST LAUNCH i.e.

<DEPENDENCY>
<SCRIPT EVENT="LAUNCH" PROTECT="TRUE" TIMING="POST" WAIT="TRUE">
<SCRIPTBODY>"C:\apps\oracle\client_1020_eng\Kill.vbs"</SCRIPTBODY>
</SCRIPT>
</DEPENDENCY>

And VBS is

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'launch.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
msgbox "Prcoess Killed"

But somehow the process is not killed on launching shortcut.

Please someone guide where I'm doing wrong.
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill1, strProcessKill2
strComputer = "."
strProcessKill1 = "'iexplore.exe'"
strProcessKill2 = "'firefox.exe'"


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

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill1 )
For Each objProcess in colProcess
objProcess.Terminate()
Next
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill2 )
For Each objProcess in colProcess
objProcess.Terminate()
Next


WScript.Quit
Answered 11/27/2009 by: lurulu
Yellow Belt

Please log in to comment
0
Simple dos command - Taskkill /blah blah
http://www.computerhope.com/taskkill.htm

WShell.Run "Taskkill /blah blah" in your VBscript and done
Answered 02/05/2010 by: TheGuru
Senior Yellow Belt

Please log in to comment
0
Some thoughts:

Your script should execute and close "launch.exe" just fine, but have you tried using it outside of the task sequencer to see if it will successfully close the process, just to make sure?
Some programs use more than one executable, are there others that should be closed as well?
You'll want to remove the msgbox command at the end of that script, you shouldn't require any user input from the system account.

Good luck!
Answered 02/05/2010 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
...and, like practically every script I see, there is ZERO error-trapping. After executing the Terminate method, how do you know that the process actually terminated? How do you even know if the WMI object got created? You don't, for either - the script just assumes that everything works. BIG mistake...
Answered 02/05/2010 by: VBScab
Red Belt

Please log in to comment
0
Zero error trapping? Try below. It depends how you code your program.

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("taskkill /f /im taskmgr.exe", 0, TRUE)
msgbox Return

1)Test it with Task Mananger open
2)Test it no Task Manager

See what error code you get
Answered 02/18/2010 by: TheGuru
Senior Yellow Belt

Please log in to comment
Answer this question or Comment on this question for clarity