[FUNCTION] Net_GetNetworkProfilesInfo

Post your working scripts, libraries and tools.
User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

[FUNCTION] Net_GetNetworkProfilesInfo

Post by cyruz » 14 Dec 2022, 10:16

Hello guys,

next network function here. This one retrieves several info about network profiles. Tested on Windows 10.

Code: Select all

; ----------------------------------------------------------------------------------------------------------------------
; Function .....: Net_GetNetworkProfilesInfo
; Description ..: Get saved network profiles informations.
; Parameters ...: nFlag = 1 "Connected networks" | 2 "Disconnected networks" | 3 "All networks"
; Return .......: Array of objects with profile information:
; ..............: { name:          "xxx" 
; ..............: , description:   "xxx"
; ..............: , isconnected:   0|1
; ..............: , hasinternet:   0|1
; ..............: , connectivity:  0|1|2|16|32|64|256|512|1024
; ..............: , category:      0|1|2
; ..............: , domaintype:    0|1|2
; ..............: , guid:          "xxx"
; ..............: , timecreated:   { year: x, month: x, dayofweek: x, day: x
; ..............:                  , hour: x, minute: x, second: x, millisecond: x }
; ..............: , timeconnected: { year: x, month: x, dayofweek: x, day: x
; ..............:                  , hour: x, minute: x, second: x, millisecond: x } }
; AHK Version ..: AHK v2
; Author .......: Cyruz  (http://ciroprincipe.info)
; License ......: WTFPL - http://www.wtfpl.net/txt/copying/
; Changelog ....: Dec. 14, 2022 - v0.1 - First version.
; Remarks ......: The INetwork interface has also the method "GetNetworkConnections" that has not been implemented.
; Info .........: https://learn.microsoft.com/en-us/windows/win32/api/netlistmgr/nn-netlistmgr-inetworklistmanager
; ..............: https://learn.microsoft.com/en-us/windows/win32/api/netlistmgr/nn-netlistmgr-inetwork
; ----------------------------------------------------------------------------------------------------------------------
Net_GetNetworkProfilesInfo(nFlag)
{
    If !IsInteger(nFlag) || nFlag < 1 || nFlag > 3
        Throw ValueError("Incorrect flag value")
        
    oNetMan := ComObject("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}") ; CLSID INetworkListManager
    
    aNetworks := []
    cGuid := Buffer(16), sGuid := "", VarSetStrCapacity(&sGuid, 128)
    For oNet in oNetMan.GetNetworks(nFlag)
    {
        oTmp := { name:         oNet.GetName() 
                , description:  oNet.GetDescription()
                , isconnected:  oNet.IsConnected()
                , hasinternet:  oNet.IsConnectedToInternet()
                , connectivity: oNet.GetConnectivity()
                , category:     oNet.GetCategory()
                , domaintype:   oNet.GetDomainType()}
        
        oQ := ComObjQuery(oNet, "{dcb00002-570f-4a9b-8d69-199fdba5723b}") ; IID INetwork
        
        ComCall(11, oQ, "Ptr",cGuid)
        oTmp.guid := DllCall("Ole32.dll\StringFromGUID2", "Ptr",cGuid, "Str",sGuid, "Int",64)
        
        cFTCreated := Buffer(8), cFTConnected := Buffer(8), cSTCreated := Buffer(16), cSTConnected := Buffer(16)
        ComCall(14, oQ, "UInt*",cFTCreated.Ptr, "UInt*",cFTCreated.Ptr+4, "UInt*",cFTConnected.Ptr, "UInt*",cFTConnected.Ptr+4)
        DllCall("FileTimeToSystemTime", "Ptr",cFTCreated, "Ptr",cSTCreated)
        DllCall("FileTimeToSystemTime", "Ptr",cFTConnected, "Ptr",cSTConnected)
        oTmp.timecreated   := { year:        NumGet(cSTCreated,   0,  "Short")
                              , month:       NumGet(cSTCreated,   2,  "Short")
                              , dayofweek:   NumGet(cSTCreated,   4,  "Short")
                              , day:         NumGet(cSTCreated,   6,  "Short")
                              , hour:        NumGet(cSTCreated,   8,  "Short")
                              , minute:      NumGet(cSTCreated,   10, "Short")
                              , second:      NumGet(cSTCreated,   12, "Short")
                              , millisecond: NumGet(cSTConnected, 14, "Short") }
        oTmp.timeconnected := { year:        NumGet(cSTConnected, 0,  "Short")
                              , month:       NumGet(cSTConnected, 2,  "Short")
                              , dayofweek:   NumGet(cSTConnected, 4,  "Short")
                              , day:         NumGet(cSTConnected, 6,  "Short")
                              , hour:        NumGet(cSTConnected, 8,  "Short")
                              , minute:      NumGet(cSTConnected, 10, "Short")
                              , second:      NumGet(cSTConnected, 12, "Short")
                              , millisecond: NumGet(cSTConnected, 14, "Short") }
        
        
        aNetworks.Push(oTmp)
    }
    cGuid := "", VarSetStrCapacity(&sGuid, 0)
    cFTCreated := cFTConnected := cSTCreated := cSTConnected := ""
    Return aNetworks
}
Cheers :beer:
ABCza on the old forum.
My GitHub.

User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: [FUNCTION] Net_GetNetworkProfilesInfo

Post by DataLife » 31 Jan 2023, 14:10

@cyruz
Would you be able/willing to create another Net_GetNetworkProfilesInfo function to work with AHK V1?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] Net_GetNetworkProfilesInfo

Post by cyruz » 31 Jan 2023, 17:33

DataLife wrote:
31 Jan 2023, 14:10
@cyruz
Would you be able/willing to create another Net_GetNetworkProfilesInfo function to work with AHK V1?
Hi DataLife, I'm not using V1 anymore, but I'll have a look into it, not soon!
ABCza on the old forum.
My GitHub.

User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: [FUNCTION] Net_GetNetworkProfilesInfo

Post by DataLife » 01 Feb 2023, 15:40

cyruz wrote:
31 Jan 2023, 17:33
DataLife wrote:
31 Jan 2023, 14:10
@cyruz
Would you be able/willing to create another Net_GetNetworkProfilesInfo function to work with AHK V1?
Hi DataLife, I'm not using V1 anymore, but I'll have a look into it, not soon!
I found another solution, so you don't need to do it for me. thanks

I have a V1 script that the method I was using to retrieve the network connections was broken with a windows update. It is over 6000 lines long and I am not going to convert to V2. I am just going to maintain it as V1.

thanks
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

User avatar
cyruz
Posts: 346
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] Net_GetNetworkProfilesInfo

Post by cyruz » 01 Feb 2023, 17:00

DataLife wrote:
01 Feb 2023, 15:40
cyruz wrote:
31 Jan 2023, 17:33
DataLife wrote:
31 Jan 2023, 14:10
@cyruz
Would you be able/willing to create another Net_GetNetworkProfilesInfo function to work with AHK V1?
Hi DataLife, I'm not using V1 anymore, but I'll have a look into it, not soon!
I found another solution, so you don't need to do it for me. thanks

I have a V1 script that the method I was using to retrieve the network connections was broken with a windows update. It is over 6000 lines long and I am not going to convert to V2. I am just going to maintain it as V1.

thanks
Got it. Yeah for such long scripts it doesn't make sense to convert...
ABCza on the old forum.
My GitHub.

Post Reply

Return to “Scripts and Functions (v2)”