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.

(1/16) > >>

pilgrim:
Ever since I started using Windows 7 one of my dislikes was that there was no way to show an icon in the system tray to tell if a PPTP/L2TP VPN was connected, unlike in XP.
Having sorted out most of the other things I wanted to change I have come back to the issue and think that I have found a solution but I need some help to finalise it.

I have written a batch file that enables me to toggle individual PPTP VPN's on and off but that still leaves me without an icon.
My idea is to create an AHK script to do the same job, as far as I can see it is not possible to change the icon on an AHK script which leads me to the possibility of converting it to an EXE.

The batch file:

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

Can this be converted to an AHK script and if compiled will it still toggle on alternate triggers?
If not can anybody suggest an alternative?

c.gingerich:
So do you want an app that does the same as above but you have access to it from the system tray?

pilgrim:
The idea is to trigger something with a hotkey that will enable the VPN and put an icon in the system tray.
Trigger it a second time from the same hotkey and it will disable the VPN and remove the icon.

It would be useful if the icon only appeared once the connection is established but that is not essential as all my connections are set to reconnect if they drop out anyway.

The reason I was looking at an executable was to give me a choice of icons but I would need the script for it as I use numerous VPN's and they all require their own batch files so the script would be different for each one.

4wd:
A simple AutoIt script, seems to work here, you may need to change the batch file folder and/or names if I got it wrong.

I'm sure you could think of something better to call it:


--- Code: AutoIt ---; ToggleIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Icon=OnOff.ico#AutoIt3Wrapper_UseUpx=n#AutoIt3Wrapper_Res_Icon_Add=On.ico#AutoIt3Wrapper_Res_Icon_Add=Off.ico#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Constants.au3>#include <GUIConstantsEx.au3>#include <WindowsConstants.au3>#include <StaticConstants.au3> $flag = "C:\pptp-running.txt"TraySetClick(16) If Not FileExists($flag) Then        TraySetIcon(@ScriptName, -6)Else        TraySetIcon(@ScriptName, -5)EndIf While 1        $msg = TrayGetMsg()        Switch $msg                Case $TRAY_EVENT_PRIMARYUP                        _Toggle()                Case Else                        ContinueLoop        EndSwitch        Sleep(500)WEnd Func _Toggle()        If Not FileExists($flag) Then                $file = FileOpen($flag, 2)                FileClose($file)                Run(@ComSpec & " /c " & '"C:\Batch Files\PPTP-US-ON.bat"', "C:\Batch Files", @SW_HIDE)                TraySetIcon(@ScriptName, -5)        Else                FileDelete($flag)                Run(@ComSpec & " /c " & '"C:\Batch Files\PPTP-US-OFF.bat"', "C:\Batch Files", @SW_HIDE)                TraySetIcon(@ScriptName, -6)        EndIfEndFunc
Left-click the icon to toggle the connection, right-click to exit it via menu.

NOTE: This was knocked up before you mentioned hotkeys and different icons but it wouldn't be hard to change.

Changing icons is just a matter of changing the icon files and recompiling or you could probably go nuts and use a config file that specifies what images to use.

pilgrim:
4wd,

Thanks for that.

I just tried the EXE but apart from an icon appearing nothing happened, I don't have AutoIt installed to modify the script.
Given my lack of programming understanding ('programmatically challenged is a good expression') I am trying to keep to AHK and batch files, they give me enough headaches. :(

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.
I could also vary it, perhaps by colour, depending on which VPN I was using.
In fact it just occurred to me that I could use the relevant country flag for each VPN's icon.

Navigation

[0] Message Index

[#] Next page

Go to full version