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

kill process? 4

Status
Not open for further replies.

Smithsco

Technical User
Mar 30, 2003
89
AU
Does anyone know how to kill a process in VBS?
I just want to stop one process from running.
 
what type of process? you can due a number of things. redirect, exit sub, end if etc.......

a bit more detailed explanation may help out

_________________________________________________________
$str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;

onpnt2.gif
[/sub]
 
redirect, exit sub, end if etc.......??? OK I mean a process listed in task manager such as smlogsrv.exe or iexplorer.exe

My research tends to point me to WMI

Extrat from msdn:

Scripting the Operating System
You've started to use the new services available in Windows 2000 and your Web site is about to go live on your Web server farm. Great—but how are you going to administer the site? Previously, this hasn't been the easiest thing to accomplish with the Windows NT® operating system, but manageability was a major focus for Windows 2000. I've written in the past about the wonders of the ADSI-WMI combination, but I've given only examples of how to use theose technologies. For this article, I thought I'd try and provide a more in depth sample that you could actually use.

One of the nightmare scenarios for all administrators is when a server stops responding—and no matter how many times you press the stop button in the management console, the errant process refuses to shut down. Those of you familiar with Unix are probably thinking, "I'd just run PS, get the process ID, and then kill it." Unfortunately, Windows 2000 doesn't come with those utilities built in. It does provide all the right components to achieve the same result—and with a little script, we can recreate these features.

Writing PS in script is reasonably simple with Windows Management Instrumentation (WMI). You just have to query the Win32_process service. This returns a collection of all the processes that are running on the machine. The script to return the process name and ID looks like this:

VBScript

set objService = getobject("winmgmts:")

for each Process in objService.InstancesOf("Win32_process")
WScript.echo Process.Name & vbTab & Process.processid
Next


Once we get the process ID, we need to be able to kill the process. Writing kill in script is a little more complex than returning the processes—but only slightly, as it still uses the Win32_process object. I've attached a full blown kill.vbs and ps.vbs that you can use for more details.

However the kill.vbs and ps.vbs are not attached to the article (not that I can see anyway).
 
thats the way id would do it.
there is a kill.exe available which comes with the nt resource kit.
this kill.exe doesnt work in wxp though, there is another exe available but i cant remember the name

what exe are you trying to kill??
ive had a big set to with people here about use of the kill.exe as they were closing outlook and excel and word with it!! in cases where you have good doucmentation on the object model you are better off closing/killin the app via the object model. objWinword.Quit or something like that, and closing and saving all open documents before you do that.

but back to killing an exe i would go with the WMI

regards von moyla
 
Thanks Mr Movie I eventually found the kill.exe and used that for the 2k box.

Thanks Jonscott8 that is what I was after :)
 
And of course on a related level Response.End would stop the code on the current page from being acted upon.

Best regards,
J. Paul Schmidt - Freelance ASP Web Developer
- Creating "dynamic" Web pages that read and write from databases...
 
This one kills the explorer.exe process:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'explorer.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next


//Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top