How to retrieve all RAS connections using api?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

How to retrieve all RAS connections using api?

23 Oct 2013, 06:33

I want to know a specific RAS connection (vpn) is connected or not.

The command line tools rasdial.exe and ipconfig.exe can list all RAS connections, but I intended to retrieve the vpn status frequently (maybe per 5 seconds), so I think it is best to use Dllcall.
(Another way is to query the IP address on a website, but this might take some time.)

The RasEnumConnections function seems can do this job, anyone can post an example? Thanks a lot!
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: How to retrieve all RAS connections using api?

23 Oct 2013, 22:14

You are a pioneer, maybe show what you started with your pathfinder jobs.
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: How to retrieve all RAS connections using api?

24 Oct 2013, 00:19

I found the WMI Win32_PerfFormattedData_RemoteAccess_RASTotal class, with a count total property qualifier.
It may do what you want and seems fast enough.

Please test this out and let me know if it counts the RAS connections.

Code: Select all

CoordMode, Tooltip, Screen

Loop
{
    For Item in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_PerfRawData_RemoteAccess_RASTotal")
        ToolTip % (tc:=Item.TotalConnections) " RAS Connections Detected.`n"
            . (!tc?"Waiting "(StrLen(s.=">")<10?s:(s:="")):"Connected."), 10, 10
}

ESC::ExitApp	;  << press escape to exit.
Untested
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: How to retrieve all RAS connections using api?

24 Oct 2013, 01:06

Thanks for the replies. I've tested the WMI code, no results here.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton, mikeyww, peter_ahk and 130 guests