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

<< < (2/2)

pilgrim:
x16wda,

I have not had the time to look at things again but I caught your post and decided to quickly reply to it .

My idea is to keep things as simple as possible (for me).

In case you never caught it comment 9 in the second link is for Windows 7, comment 13 is for XP.
My thought is to create one batch file that will trigger the other two on either OS'.
For one thing that will save messing about with the batch files I already have which are working.
As I said, when I tried to combine the ON and OFF files only parts of them worked.

What I have in mind is something along these lines:

IF SBiectrl.exe is running start Internet_OFF.bat
ELSE start Internet_ON.bat

Obviously that is not exactly how it would look but it's where I'm starting from.

If I did not get anywhere with that another idea was to try and create a toggle so that each time I pressed the same hotkey it alternated between the two files, same outcome different perspective.
If that failed as well I was going to look at using AHK although I would prefer not to in this case.

Let me see what I can come up with before you suggest anything definite or do it for me.

When I've had another go I'll post the results either way.

Ath:
Would this SO question help? (Not on a PC atm, so can't mock up smt)

pilgrim:
Ath,

Thanks for that, I've spent a lot of time on that site recently, along with Computer Hope it's where I've found the most information.

x16wda,

I've been over everything and solved all the problems except for one which I'll get to in a minute.
I can toggle between 2 batch files with the following:

if exist prog-running.txt goto running
rem prog is not running
copy NUL>prog-running.txt
start /D "C:\Batch Files\AHKOSK ON-OFF" AHKOSK_ON.bat
goto alldone
:running
rem prog is already running
del prog-running.txt
start /D "C:\Batch Files\AHKOSK ON-OFF" AHKOSK_OFF.bat
:alldone
--- End quote ---

I ran your script from reply 4, on XP it runs as is, on 7 I had to modify it.
Besides the differences in NIC details I cannot get the "" setting to run on 7, I  have to change it to /D, then it runs perfectly.
If I use "" I either get an error message or it opens an Explorer window to the relevant folder.
So the file on 7 reads thus:

rem Check if our flag file exists and act accordingly
if exist internet_is_on.txt goto running

rem Turning Internet items ON
echo hah>internet_is_on.txt

start /D "C:\Program Files (x86)\D4" D4.exe
start /D "C:\Program Files (x86)\Sandboxie" SbieCtrl.exe
start /D "C:\Program Files (x86)\PeerBlock" peerblock.exe

netsh interface set interface "Router Connection" ENABLED

goto alldone

:running
rem Internet is ON, turn it all OFF now
del internet_is_on.txt

taskkill /F /IM peerblock.exe
taskkill /F /IM SbieCtrl.exe
taskkill /F /IM D4.exe

netsh interface set interface "Router Connection" DISABLED

:alldone
--- End quote ---

The problem is that just like my original Internet ON-OFF files it leaves the icons in the system tray after the programs shut down on both OS'.
But, I have two files which toggle a single program:

@echo off

taskkill /f /im ahk_osk.exe || start /D "C:\Program Files\AHKOSK" ahk_osk.exe
--- End quote ---

This leaves the icon in place.

@echo off

tasklist /fi "ImageName eq ahk_osk.exe" | find /i "ahk_osk.exe" && taskkill /fi "ImageName eq ahk_osk.exe" || start /D "C:\Program Files\AHKOSK" ahk_osk.exe
--- End quote ---

This removes the icon.

My question is whether it is possible to incorporate something from this second file, or anything else for that matter, into your script from reply 4 so that it will automatically remove the icons when the programs are closed?

Navigation

[0] Message Index

[*] Previous page

Go to full version