Batch Script That Will Kill All CMD Processes Except Itself

I need to create a batch script that will look up all running processes of "cmd" and close/kill them. It should not kill itself though because I want to start another batch process after the kill.

I have Unix windows based tools such as ps, kill and cut. Maybe that can help.

Any assistance would be appreciated.
deharvyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TG TranIT guyCommented:
You may want to try pskill from Sysinternal
http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx

I think you need 2 batch files - first batch file kills all cmd, and the second start another process.  Otherwise, you would need to use PSID because if you use cmd.exe, all cmd will be terminated.
0
matrixnzCommented:
You could also call another program to close and then reopen cmd.exe for e.g. vbscript or autoit script, here's a simple one for AutoIT.

Download and Install AutoIT www.autoitscript.com

Copy and Paste attached code into notepad
Save as CMDKill.au3

Right Click and Select Compile to create an exe (held within the same folder as your .au3 file)
Just call it from batch or run it directly.

Change notepad.exe to your next batch file etc..

Hope that helps.

Cheers
#NoTrayIcon
 
While 1
$CMD = ProcessExists('cmd.exe')
If $CMD Then
	ProcessClose($CMD)
Else
	ExitLoop
EndIf
WEnd
 
Run('notepad.exe', '')

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.