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

Stopping a script running on a Windows Server Box

Status
Not open for further replies.

dman7777777

IS-IT--Management
Jan 13, 2007
52
US

Last night at my job I had to restart a couple of programs. They are actually scripts (.bat files) on a Windows 2000 Server Box. The way I was trained is that you stop the current ones running by clicking on the X in the right corner of the Windows cmd.exe window. My manager saw me do this and got extremely angry at me. He said you never stop a script like that, instead you control C out of it. I'm not a Windows expert. My manager said there's a chance it could still be running, but I'm not very convinced on that. Regardless, I was just doing how I was trained(a year ago....I've been doing this a year and no harm ever has come out of it). I'm so mad I want to put in my two weeks. But anyways, is it ok to stop a script hitting the X in cmd.exe or am I supposed to control-C out of it? And does the script continue to run if I hit the X and the cmd.exe closes?
 
It depends on what the batch file is doing. Not all commands will shutdown cleanly when you just click on the X to close a window. The Ctrl-C will actually issue a break in the processing of the batch file which will allow you to exit it or continue processing it.
 
upset him more kill all cmd.exe's

Code:
' Killer.VBS
' This script kills all processes with name cmd.exe

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

Part and Inventory Search

Sponsor

Back
Top