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
}