/build/static/layout/Breadcrumb_cap_w.png

OSD Scripting: How to kill a process using VB Script

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

Answers (5)

Posted by: lurulu 15 years ago
Yellow Belt
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
Posted by: TheGuru 14 years ago
Senior Yellow Belt
0
Simple dos command - Taskkill /blah blah
http://www.computerhope.com/taskkill.htm

WShell.Run "Taskkill /blah blah" in your VBscript and done
Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
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!
Posted by: anonymous_9363 14 years ago
Red Belt
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...
Posted by: TheGuru 14 years ago
Senior Yellow Belt
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ