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

DonationCoder.com Software > Post New Requests Here

Turn a batch file into an AHK script.

<< < (2/16) > >>

4wd:
I just tried the EXE but apart from an icon appearing nothing happened, ......-pilgrim (April 29, 2013, 09:12 AM)
--- End quote ---

That's exactly what should happen when you run it.......then it just sits there until you click the LMB on it at which point it goes and runs your batch file and the icon changes colour.

Simples  :)

I am trying to keep to AHK and batch files, they give me enough headaches. :(
--- End quote ---

Fair enough, I find the syntax used in AHK is too strange to get to grips with :)

My intention was to use a one of the Windows network icons and only have it show when the VPN is connected, the way it is on XP.
--- End quote ---

So what you want is something along the lines of the OpenVPN GUI which provides an indication in the SysTray and allows you to easily switch between VPNs?

pilgrim:
Apologies for not working it out.

I just tried it again and the icon is flashing between different colours and a cross, I opened Network Connections and the VPN that this is set up for shows no indication of trying to connect.

I'll try and explain more clearly what I want to do, at the moment I have a batch file X that alternately triggers two other batch files ON and OFF.
The OFF file does not contain specific details so it will disconnect ANY PPTP/L2TP VPN that is connected when it is triggered.
The ON files contain the name of the VPN as well as username and password so each one is specific to a single VPN server, therefore I am going to need a different ON file for each VPN server, although I have no intention of creating files for all of them at the last count there were 40+.
This also means that I will need a separate X batch file for each one and that in turn means that I need separate scripts or apps to trigger the various X batch files as the path will be different for each one.

Moving on to icons, on XP both PPTP/L2TP VPN's use the same icon(s) as the main connection:

System32/netshell.dll

netshell_190.ico
netshell_191.ico
netshell_192.ico
netshell_193.ico

These icons are also in Windows 7 and they are the same ones as Network Activity Indicator uses, which I run in Windows 7 for the main connection.
The VPN icons need to be automatically removed from the system tray when not in use just as they are in XP.

At the moment I have shortcuts to the PPTP/L2TP VPN's that I most frequently use which make the connection but give no visible indication i.e. an icon.
Instead of pointing those shortcuts directly at the connections I want to be able to point them at individual apps that will trigger a specific VPN and put an icon in the system tray at the same time.
When I trigger them a second time I want the VPN to disconnect and the apps icon to disappear.
I do not want or need a GUI and the only option it would be useful to have in the icon would be to disconnect the VPN and exit the app at the same time without going back to the shortcut, which is not really necessary.
Except on very rare occasions whatever VPN I connect to when I start for the day I stay on so being able to switch between them is not a consideration while connecting/disconnecting them is.

If I can get a working AHK script that I can edit and compile I can change all the variables to suit the different VPN's myself.

Just to finish on your last point, all my OpenVPN VPN's come with their own software and none of them use the OpenVPN GUI, when I am not using any of them I disable the TAP-Win32 adaptor and there is nothing showing in the system tray.

The main issue for me from the beginning is that by default in Windows 7 there is no visible indication when a PPTP/L2TP VPN is connected, to have an icon in the system tray that is synchronised with the VPN: connected - icon visible, disconnected - icon not visible, is all I am really interested in and the only way that I can see to do that is with an app because the connections themselves have no icons.

4wd:
I just tried it again and the icon is flashing between different colours and a cross, I opened Network Connections and the VPN that this is set up for shows no indication of trying to connect.-pilgrim (April 30, 2013, 11:48 AM)
--- End quote ---

If it's flashing between an icon and a red cross that means the script is paused, ie. you clicked the RMB on it and the default AutoIt action is to bring up the Script Paused/Exit menu - just right-click it again and choose Script Paused to unpause.

The ON files contain the name of the VPN as well as username and password so each one is specific to a single VPN server, therefore I am going to need a different ON file for each VPN server, although I have no intention of creating files for all of them at the last count there were 40+.
This also means that I will need a separate X batch file for each one and that in turn means that I need separate scripts or apps to trigger the various X batch files as the path will be different for each one.
--- End quote ---

It sounds more like you need a decent Network Connection Manager but let's see if I can reduce the number of batch files required without doing much of anything :)

The way you've described it you need one "X" batch file for every ON batch file, is this correct?

The "X" batch file is there for the sole purpose of setting/deleting a flag file and choosing which of the following two, (ON or OFF), batch files to run based on the (non)existence of the flag file.

However, if you move the conditional test to the ON and OFF batch files there's no need for the "X" batch files at all.

Now you only need one ON batch file for each connection and the OFF batch file.

eg. The first few lines of each ON batch file would be:


--- Code: Text ---if not exist pptp-running.txt goto startvpnREM prog is already runningstart /D "C:\Batch Files\PPTP ON-OFF" PPTP-OFF.batgoto alldone:startvpnREM prog is not runningcopy NUL>pptp-running.txt VPN connection commands :alldone
For the OFF batch file, (PPTP-OFF.bat), the first few lines would be:

--- Code: Text ---if not exist pptp-running.txt goto alldonedel pptp-running.txt VPN disconnection commands :alldone
Running any ON batch file with an already established connection would cause disconnection, so in effect every ON file becomes an OFF file if there is a connection.

If we add in a little program, (see below), that throws an icon into the SysTray when run and optionally runs the OFF batch file when clicked then all you require would be a program launcher, (Launchy, FARR, etc), to choose which ON batch file you want to run.

Would not this be easier?

NetConnected is a small program that will put an icon into your SysTray and then just sit there.  It takes one optional argument, a file to run when you click on it with the LMB or choose Exit from its menu - the file will then execute and NetConnected will exit.

eg. NetConnected.exe "C:\Batch Files\PPTP-OFF.bat"

If you run NetConnected without arguments then it will terminate any previous running instance then exit.  You can also rename the executable to anything you like, it will still work.  (I chose a generic network icon for it but if you want something else let me know - I might see if I can get it to change according to a supplied country code or icon.)

So your ON files would become:

--- Code: Text ---if not exist pptp-running.txt goto startvpnREM prog is already runningstart /D "C:\Batch Files\PPTP ON-OFF" PPTP-OFF.batgoto alldone:startvpnREM prog is not runningcopy NUL>pptp-running.txt VPN connection commands NetConnected.exe "C:\Batch Files\PPTP-OFF.bat":alldone
And you could add it to the OFF file:

--- Code: Text ---if not exist pptp-running.txt goto alldonedel pptp-running.txt VPN disconnection commands :alldoneNetConnected.exe
Is that any better?

Target:
can we see the content of one of the 'on' batch files?

seems like it would be more logical to start from scratch instead of building a tool to control a tool to control a tool to control a tool...

pilgrim:
4wd,

I'll try the app and the batch file later but to pick up on some of your comments:

I unpaused the previous app but the VPN still showed no sign of connecting.

All my connections show up in the Network Connections window so I can connect/disconnect them from there and I can open that by right clicking on the icon for Network Activity Indicator which stays in the tray all the time, but I do not want to keep opening a window every time which is why I do not want an app with a GUI, nor does it provide an icon to show the VPN is connected.

Your idea about cutting out the X batch files makes sense to me and as I said I will try it later, remember that my understanding of these things is somewhat limited and I have been basically putting together various scripts that I have found online so it is almost certain that there is a more efficient way to do what I am trying to do.
It's like the question I asked at the end of Reply 7 in THIS thread, my only way of answering it will be by trial and error, at the moment each new type of batch file is taking me an average of 10 hours to sort out.

I have never tried to run a batch file with an already established connection but if I was trying to change connections in that way I would simply have to click it twice, the first time to disconnect the old connection (thats why I made the OFF file non-specific), the second time to connect the new one.

I already have a number of launchers for various things and I do not want to install another, the sole purpose of any additional program is to put an icon in the system tray to indicate the connection is active and then remove the icon when it is not.

I will try NetConnected as I said but if that leaves an icon in the tray when there is no VPN connected it is not what I want.
When there is no VPN running there should be nothing else associated with them running (i.e. an app) and nothing visible (i.e. an icon).


Target,

The ON files read as follows:

rasdial "VPN Name" "Username" "Password"


The image below shows the left hand end of my taskbar, the first 3 icons are in Quick Launch, the next 3 in an additional toolbar:



From left to right the shortcuts are as follows:

Quick Launch: Router Connection, TAP-Win32 adaptor, LAN.

Second Toolbar: EU VPN, UK VPN, US VPN. (All PPTP)

All I want to do is continue using the same PPTP shortcuts but with (A) the ability to toggle the connections, which I can now do with the batch files, and (B) put an icon in the system tray, (only) when a connection is 'on'.

I'll be back when I have tried out the latest suggestions.

Many thanks for the help by the way.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version