1.

Solve : Creating .bat file to open program and close multiple processes?

Answer»

I would like to make a batch file that would start one program and would also close several running PROCESSES of my choosing. I'm running Windows XP Home and am having CPU spikes that slow down the program I want in the batch file.

I don't know what some of the processes that are running are that I'd like to close, but the ones I usually notice the most in Task Manager/Processes are System, Winssnotify, iexplore, winss, MsMpEng, svchost, and crss. I'm also running Windows Live OneCare (which has no way of exiting! - help would also be appreciated if there's a way to close this app at will).

I know the basic commands to create a .bat file to open multiple programs at once:

@echo off
start "program1 title" "program1 target path"
start "program2 title" "program2 target path"

save as "all files" not text file and as a .bat

But HOW do you create a batch that closes several programs/processes while opening a program? Thanks.You can pass the programs to kill on the command line:

Code: [Select]@echo off
start "program1 title" "program1 target path"
start "program2 title" "program2 target path"

:loop
for /f "tokens=1-2" %%f in ('tasklist') do (
if /i %%f equ %1.exe taskkill /F /IM %%f 2>nul
)
if .%2==. goto :eof
shift
goto loop

You can run from the command line as: batchname System Winssnotify iexplore winss MsMpEng svchost crss

If the spikes are causing you to terminate important Windows programs, you may have other system problems. Suggest posting on the Computer viruses and SPYWARE board.Wow, that's awesome, thank you! Could you explain everything you said? Especially what each command means that you entered in. I'd really like to understand what that means.

As for my comp, I have no viruses or spyware that I'm aware of. It's a relatively NEW OS install (GOING on 3 weeks with XP after a decade of using 98) and Windows Live OneCare is installed and always running. It's identified and quarantined several viruses I've accidentally downloaded from freeware sites and the firewall is very effective.

Basically, the program I'm wanting to open in conjuction with closing several processes is Civilization 4. It eats a ton of CPU when it runs. ALTHOUGH I've heard it's pretty typical to keep getting CPU spikes on XP. It's only noticable when I run that game though, so I was thinking a killer .bat could solve that problem.

You know what else I was thinking... making another .bat that could reopen all the processes the other .bat killed - like a toggle switch. I think this could be very useful once all running processes are identified. I'm also looking at some freeware taskmon programs that will hopefully give more detailed explanations of what each process is for, where the .exe is located, what it's doing, and any conflicts. This would be very helpful in determining which processes to toggle on and off with a couple of .bat files.Quote

Wow, that's awesome

Not really. I use the same code to kill off program remnants when testing my homegrown applications. It's handy to have a closet full of snippets.

By using the shift command, the batch code sequentially moves each program name on the command line into the %1 position. Once there, it's like shooting fish in a barrel.

You can find a good free task manager here

Good luck.The coding you replied with is far too advanced for me at this time, but I'd like to learn how each snippet works. If you want, you could go over each thing in your code or tell me where I can find a detailed list of all .bat codes, strings, and puncuations and how to apply them? I've searched the net for the past couple days and have only found simple commands - like for opening multiple files at once. Thank you very much for helping me with this.Not knowing your skill level, I generally send posters to this site for learning batch code.

Considering there are only 13 or so batch instructions, batch code can be powerful stuff. My only gripe is readability and a notation straight from the cave drawings.

Good luck.
OK. I'll check out that link and see if I can create a resource toggle.bat eventually.

Also, that task manager you showed me is PERFECT! Now I know what each process is for and the path to the .exe files. I also replaced the standard taskmon with it.

Keep up the good work! Your help is very much appreciated.


Discussion

No Comment Found