Toggle a set of programs on and off

September 17, 2010 at 10:31:53
Specs: Windows 7
I have a number of programs that I want to be able to Run together. I also want them to exit together. I know how to run several programs and close several programs from a batch file, and currently have one file to open my programs and one to close them. I'd like to condense that to one file that can toggle my programs On and Off.

Does anyone have any idea how this could be done?

Thanks so much, I really appreciate it!


See More: Toggle a set of programs on and off

Report •


#1
September 17, 2010 at 22:01:31
Simply copy the second file into the first... stick a pause in there and you're set.

Alternatively post the contents and ill give you hand.

Can I put a question here?


Report •

#2
September 21, 2010 at 23:59:14
start "" "C:\Program Files\C:\Program Files\C:\Program Files\Skype\Phone\Skype.exe"
start "" "C:\Program FilesC:\Program Files\Winamp\winamp.exe"

pause

taskkill /IM Skype.exe
taskkill/IM winamp.exe

Here is the new code. It works as you said it would. But what I'm looking for is a little more specific - I want to run the script once and have it start the programs, then run it again to close them.

Using Pause leaves me with a cmd window open, which is not desirable.

I really appreciate your help, thank you so much!


Report •

#3
September 22, 2010 at 04:37:30
Try this:

@ECHO OFF

FOR /f "tokens=*" %%a IN ('TAKSLIST ^| FINDSTR /i skype.exe') DO (
IF "%ErrorLevel%"=="0" (
	CALL :Kill1
) ELSE (
	START "" "C:\Program Files\Skype\Phone\Skype.exe"
)
)

FOR /f "tokens=*" %%a IN ('TASKLIST ^| FINDSTR /i winamp.exe') DO (
IF "%ErrorLevel%"=="0" (
	CALL :Kill2
) ELSE (
	START "" "C:\Program Files\Winamp\winamp.exe"
)
)

:Kill1

TASKKILL /IM Skype.exe
GOTO :eof

:Kill2

TASKKILL /IM winamp.exe
GOTO :eof

:eof

Can I put a question here?


Report •

Related Solutions

#4
September 22, 2010 at 13:54:37
'TAKSLIST' is not recognized as an internal or external command,
operable program or batch file.

Do I need to download something else for this to work? I'm running win7.


Report •

#5
September 22, 2010 at 15:24:27
Check the spelling in your script - should be TASKLIST and not TAKSLIST. It should be included in Windows 7.

Report •

#6
September 22, 2010 at 15:27:08
Ooh, my bad. Tasklist is a windows 7 command. To my knowledge, it's the only way to do this without third party software.

Can I put a question here?


Report •

#7
September 23, 2010 at 06:24:58
Tasklist was included with WinXP Pro, and I believe all versions of Vista and Win7. Before that, I think it was in one of the Resource Kits.

Before taskkill, there was tskill, which has been included in all versions of WinNT since Win2K, I believe.

As of Win2K, you can use WMI's Win32_Process to list and kill processes.

If you're getting a TASKLIST not found error (and not a "TAKSLIST" not found error, as mentioned previously), check to make sure you have a viable PATH.


Report •

#8
September 23, 2010 at 07:23:10
Well that makes me feel foolish, haha. That's what I get for copying and pasting. Anyway, when I fixed that spelling I got an error saying the process skype was not found, so I added another GOTO, so it wouldn't try closing the program immediately after opening it, and I removed a GOTO after the first kill, so it'd do both of them.

It isn't running either program, however (before or after my changes). It will kill them though, if I start them manually beforehand.

@ECHO OFF

FOR /f "tokens=*" %%a IN ('TASKLIST ^| FINDSTR /i skype.exe') DO (
IF "%ErrorLevel%"=="0" (
CALL :Kill1
) ELSE (
START "" "C:\Program Files\C:\Program Files\C:\Program Files\Skype\Phone\Skype.exe"
)
)

FOR /f "tokens=*" %%a IN ('TASKLIST ^| FINDSTR /i winamp.exe') DO (
IF "%ErrorLevel%"=="0" (
CALL :Kill2
) ELSE (
START "" "C:\Program FilesC:\Program Files\Winamp\winamp.exe"
)
)

GOTO :eof

:Kill1

TASKKILL /IM Skype.exe

:Kill2

TASKKILL /IM winamp.exe
GOTO :eof

:eof


Report •

#9
September 23, 2010 at 14:08:48
This may be a stupid question, but why does the path to the program include C:\program files twice in the Start command? Would that possibly cause the problem or is that used to define the path in which the program is starting?

Report •

#10
September 23, 2010 at 14:23:51
That's a mistake... I just copied his code and mixed it into the new one. Fixed now.

Can I put a question here?


Report •

#11
September 23, 2010 at 14:34:22
For humor, my version:
taskkill /im skype.exe || start "" "C:\Program Files\Skype\Phone\Skype.exe"
taskkill /im winamp.exe || start "" "C:\Program Files\Winamp\winamp.exe"


Report •

#12
September 23, 2010 at 14:57:12
Oh Razor... Always showing me up eh?

=)

Can I put a question here?


Report •

#13
September 23, 2010 at 15:02:25
It's what I do. =P

Report •

#14
September 23, 2010 at 20:30:20
Haha, for humor he says!

Well that worked perfectly. That was a very concise, elegant solution man...impressive! I did not know one could do that.

Thank you all very much for your help!


Report •


Ask Question