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.

<< < (3/16) > >>

pilgrim:
4wd,

I have tried all 4 batch files in your last post and they all worked except for one thing which I have resolved.
In the NetConnected ON file I had to add 'start' to the beginning of line 11 or the cmd window stayed open.

The good:

Using NetConnected puts an icon in the tray (ON) and removes it (OFF). (Terrible icon. ;D)

The bad:

If I hover the cursor over the NetConnected icon there is a 'Left-click to execute file and exit' option, what actually happens is that the icon disappears but the VPN stays connected.

If the VPN connection drops out the icon stays put, so there is no indication the the connection has dropped.

Batch file X is a toggle, when it is removed I need 2 trigger points (hotkeys, shortcuts) as opposed to 1.
An extra batch file is far less of an issue for me than an extra click.


I've taken the liberty of changing the NetConnected icon to netshell_193.ico to match the one in Network Connection Indicator.
In NCI as well as by default in XP the 4 netshell.dll icons change in relation to the traffic, which in numerical order is, 190 - in & out, 191 - in, 192 - out, 193 - none.
Without getting overly complicated is there a way of incorporating this in NetConnected?

The only other thing that I have noticed is that if I have the icon showing in the system tray and disconnect, when I reconnect the icon reappears far left in the system tray (XP default) rather than where it was before (7 default).
(For some reason this appears to have resolved itself, I think it might have had something to do with which programs were running when I was switching NetConnected on and off.)

All the testing I have done so far has been in Windows 7 but I am confident that once I finalise the details it will work in both.


With what I have now I can put together a working solution to what I was looking for.
All the issues I have mentioned above are relatively trivial and can either be resolved (reinstating the X batch file) or ignored (changing icons).
If you, or anybody else, can suggest ways of tidying things up in any way let me know and I'll give it a try.

4wd:
If the VPN connection drops out the icon stays put, so there is no indication the the connection has dropped.
--- End quote ---

Half a dozen posts later it has all become clear - all you want is a network connection monitor, nothing to do with batch files at all really.  ;D

If I hover the cursor over the NetConnected icon there is a 'Left-click to execute file and exit' option, what actually happens is that the icon disappears but the VPN stays connected.
--- End quote ---

It's not an option, it's a ToolTip - what you're saying is that as soon as you hover over the icon you get the ToolTip and then the program exits without you doing anything further, (something it doesn't do on my machine).

Anyway, now that all that's required is a connection monitor it's back to the drawing board  ;)

Icon changed for NetConnected, download archive again.

pilgrim:
If the VPN connection drops out the icon stays put, so there is no indication the the connection has dropped.
--- End quote ---

Half a dozen posts later it has all become clear - all you want is a network connection monitor, nothing to do with batch files at all really.  ;D

If I hover the cursor over the NetConnected icon there is a 'Left-click to execute file and exit' option, what actually happens when clicked is that the icon disappears but the VPN stays connected.
--- End quote ---

It's not an option, it's a ToolTip - what you're saying is that as soon as you hover over the icon you get the ToolTip and then the program exits without you doing anything further, (something it doesn't do on my machine).

Anyway, now that all that's required is a connection monitor it's back to the drawing board  ;)

Icon changed for NetConnected, download archive again.
-4wd (May 02, 2013, 02:57 AM)
--- End quote ---

Mea culpa, mea culpa, mea maxima culpa. It's what comes of trying to think of too many things at once when you don't understand most of them in the first place.  :-[

When I started this there were three things that I was missing, the first was the cmd line commands to turn a VPN on and off, those I finally found after much searching online. The second was a way to toggle the VPN on and off from a single hotkey/shortcut, the batch files solved that. The third was to have an icon to indicate the VPN state, originally I was thinking only in terms of whether it was on or off, it was only later that I considered the possibility of it indicating traffic.

Last night it suddenly occurred to me that there was an obvious answer right in front of me, running a second instance of Network Activity Indicator, the first to monitor the main connection, the second to monitor a VPN. Unfortunately it is only possible to run a single instance of it and that monitors all connections. I have sent the developer an email to see what he thinks of the idea.

The first part of your reply highlights something I have noticed repeatedly when searching for things, it's not just about what you are looking for but the words you use to describe it.
In the last two months I have amassed a considerable amount of information about things I had never heard of before, devcon, rasdial and numerous others.
Rather than just copy and paste everything into text files I have added explanations that I can understand, which is more than I can say about many of the sites that information came from.

Going back to something I said yesterday, I am still suffering from wandering icons, this happened before when I was playing with batch files.

4wd:
Simple connection monitor: ConnStat.exe

The simple part: an icon = connected; no icon = disconnected


ConnStat - Connection Status

ConnStat.exe <adapter> [delay]

where: <adapter >= NIC adapter name as given under Windows Network Connections, use quotes if necessary
            [delay]    = Optional delay before monitoring starts (in seconds)

eg.  ConnStat.exe "virtualbox host-only network" 30

Tray icon will change colour at the end of the delay period, (if given), to indicate monitoring has begun.

If the NIC given does not exist or it does not have a status of Connected, the program will exit.

NIC status will be checked every 1000 milliseconds.

ConnStat can be terminated by causing the NIC to disconnect, (eg. pull the cable, disable it, nuke the destination, etc), or choosing Exit from the icon context menu.

If the icon is flashing between its normal icon and a red cross it indicates the program is PAUSED - use the context menu to unpause.



--- Code: AutoIt ---#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Icon=netshell_193.ico#AutoIt3Wrapper_UseUpx=n#AutoIt3Wrapper_Res_Icon_Add=netshell_190.ico#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #comments-start ConnStat - Connection Status ConnStat.exe <adapter> [delay] where: <adapter >= NIC adapter name as given under Windows Network Connections, use quotes if necessary, it's case-insensitive            [delay]    = Optional delay before monitoring starts, (in seconds). eg.  ConnStat.exe "virtualbox host-only network" 30 Tray icon will change colour at the end of the delay period, (if given), to indicate monitoring has begun. If the NIC given does not exist or it does not have a status of Connected, the program will exit. NIC status will be checked every 1000 milliseconds. ConnStat can be terminated by causing the NIC to disconnect, (eg. pull the cable), or choosing Exit from the icon context menu. If the icon is flashing between its normal icon and a red cross it indicates the program is PAUSED - use the context menu to unpause.#comments-end #Include <Array.au3> ; No command line args = message and exitIf $CmdLine[0] = 0 Then        MsgBox(48, "ConnStat", "Command format:" & @CRLF & "ConnStat.exe <network connection> [delay]" & @CRLF & @CRLF & 'eg. ConnStat.exe "Local Area Connection 2" 30')        _Exit()EndIf TraySetState()                                                                   ; Show tray icon$checkConn = $CmdLine[1]                                            ; arg 1 = NICIf $CmdLine[0] > 1 Then        If Int($CmdLine[2]) > 0 Then Sleep(Int($CmdLine[2]) * 1000)    ; arg2 = optional delayEndIfTraySetState(2)                                                                 ; Hides tray icon appears after delay, ie. monitoring startsTraySetIcon(@ScriptName, -5)                                         ; Change iconTraySetState(1)                                                                 ; Show tray icon While 1        $connNICs = _AdaptersConnected()                            ; get NICs with state "connected"        $i = _ArraySearch($connNICs, $checkConn, 1)            ; search NIC list for our adapter        If @error Then _Exit()                                                   ; exit if not found        Sleep(1000)WEnd  Func _Exit()        ExitEndFunc ; Function by guiness @ http://www.autoitscript.com/forum/topic/134245-get-netconnection-status/#entry936095Func _AdaptersConnected($sComputer = @ComputerName)    Local $aReturn[1] = [0], $iDimension = 0, $oColItems, $oWMIService, $sDelimeter = Chr(01), $sReturn = ""     $oWMIService = ObjGet("winmgmts:\\" & $sComputer & "\")    $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionStatus='2'", "WQL", 0x30)     If IsObj($oColItems) Then        For $oObjItem In $oColItems            If $oObjItem.AdapterType = "" Or $oObjItem.NetConnectionID = "" Then ; Ensures that the connections are physical adapters.                ContinueLoop            EndIf            If StringInStr($sDelimeter & $sReturn, $sDelimeter & $oObjItem.Description & $sDelimeter, 1) Then ; Ensures there are no duplicates.                ContinueLoop            EndIf            $sReturn &= $oObjItem.Description & $sDelimeter             If ($aReturn[0] + 1) >= $iDimension Then ; http://www.autoitscript.com/forum/topic/...en-you-have-to-resize-an-exist                $iDimension = ($aReturn[0] + 1) * 2                ReDim $aReturn[$iDimension]            EndIf             $aReturn[0] += 1            $aReturn[$aReturn[0]] = $oObjItem.NetConnectionID        Next    EndIf     ReDim $aReturn[$aReturn[0] + 1]    Return $aReturnEndFunc   ;==>_AdaptersConnected

You can run multiple copies and you can rename the executable to anything you like.

EDIT: For some wierd reason I can't get the ToolTip to change to something other than the executable name, (I was going to make it the passed NIC name), more reading to be done.

NOTE: Currently only works for physical adapters.

pilgrim:
Hmmm?

The icon appears (193) after delay it changes (190) and immediately disappears.
Tried it on several connections with the same result each time.

EDIT: Just tried it on OpenVPN Adapter and it works perfectly, had to add 'start' to get rid of cmd window.
         It works perfectly on the Router Connection as well, went back to PPTP, same as before.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version