ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Combining Batch Files

(1/2) > >>

I have two very simple batch files to start and stop a single program. The first uses the 'start' command, the second the 'taskkill' command.
Is there a way to combine the two to create a toggle?
I have tried numerous options but they all finish up starting the program and then stopping it.

use a flag so the batch knows which routine to run?
use powershell get-process?

I agree with jpfx, a flag file would be the simplest.

--- Code: Text ---if exist prog-running.txt goto runningrem prog is not runningcopy NUL>prog-running.txtstart vncviewer.exegoto alldone:runningrem prog is already runningdel prog-running.txttaskkill /IM vncviewer.exe:alldone

Thank you both for your replies.

I'm afraid that mention of flags means nothing to me unless they are fluttering from flagpoles, I have always been a practical person and any sort of programming language loses me quite early on.
I have bookmarks and text files containing all the information I could need on both batch files and AHK, to do just about anything they are capable of doing, but putting it together is something else.
I keep being reminded of when I started using logic gates in electronics, at least then I could get diagrams of the IC's to see what each pin was for.

With regard to my original post, after many hours of searching online I found THIS (comment 1) which solved the initial problem.

I have now moved on to trying to find ways to combine the 2 batch files in comment 9 of THIS thread, which will also give me the answer to combining the 2 batch files in comment 13 of the same thread.
My efforts so far seem to indicate that I actually need to create a third batch file in each case using IF and ELSE commands to trigger the other 2, when I tried to combine them I found that only 2 of the 3 programs were being triggered and it had no effect at all on the connection.
By the time I had got that far I needed to pack up, I'll start again when I have the time.

Pilgrim, what I posted was basically the same as your comment #1 link.

From looking at the thread in the second link, is your intention that you want one script to do both your Internet_ON and Internet_OFF scripts?  If so we could pull the guts from your two scripts and put them into this framework, or just change this to call your existing batch files.  This would be the first option, with everything in one place:

--- Code: Text ---rem Check if our flag file exists and act accordinglyif exist internet_is_on.txt goto running rem Turning Internet items ONecho hah>internet_is_on.txt start "" "C:\Program Files\D4\D4.exe"sleep 1start "" "C:\Program Files\Sandboxie\SbieCtrl.exe"sleep 1start "" "C:\Program Files\PeerBlock\peerblock.exe"sleep 3 devcon enable *DEV_001C* goto alldone :runningrem Internet is ON, turn it all OFF nowdel internet_is_on.txt taskkill /F /IM peerblock.exetaskkill /F /IM SbieCtrl.exetaskkill /F /IM D4.exe devcon disable *DEV_001C* :alldone
That said, when you reboot your computer the status of the programs and device might be out of sync with the "internet_is_on.txt" flag file.  If that happens you should be able to just run the script an extra time to get everything in sync.


[0] Message Index

[#] Next page

Go to full version