-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGetNetworkConnectivityHint.ahk
48 lines (40 loc) · 2.23 KB
/
GetNetworkConnectivityHint.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
; =============================================================================================================================================================
; Author ........: jNizM
; Released ......: 2022-10-14
; Modified ......: 2023-01-12
; Tested with....: AutoHotkey v2.0.2 (x64)
; Tested on .....: Windows 11 - 22H2 (x64)
; Function ......: GetNetworkConnectivityHint()
;
; Parameter(s)...: No parameters used
;
; Return ........: Retrieves the aggregate level and cost of network connectivity that an application or service is likely to experience.
; =============================================================================================================================================================
#Requires AutoHotkey v2.0
GetNetworkConnectivityHint()
{
static NO_ERROR := 0 ; User-Mode: NO_ERROR on success, error code on failure.
static LEVEL_HINT := Map(0, "Unknown", 1, "None", 2, "LocalAccess", 3, "InternetAccess", 4, "ConstrainedInternetAccess", 5, "Hidden")
static COST_HINT := Map(0, "Unknown", 1, "Unrestricted", 2, "Fixed", 3, "Variable")
if (VerCompare(A_OSVersion, "10.0.19041") < 0)
throw Error("Minimum supported client: Windows 10, version 2004 (Build 19041)", -1)
Buf := Buffer(20)
NETIOAPI_SUCCESS := DllCall("iphlpapi\GetNetworkConnectivityHint", "Ptr", Buf, "UInt")
if (NETIOAPI_SUCCESS = NO_ERROR)
{
NETWORK_CONNECTIVITY_HINT := Map()
NETWORK_CONNECTIVITY_HINT["ConnectivityLevel"] := LEVEL_HINT[NumGet(Buf, 0, "Int")]
NETWORK_CONNECTIVITY_HINT["ConnectivityCost"] := COST_HINT[NumGet(Buf, 4, "Int")]
NETWORK_CONNECTIVITY_HINT["ApproachingDataLimit"] := NumGet(Buf, 8, "Int")
NETWORK_CONNECTIVITY_HINT["OverDataLimit"] := NumGet(Buf, 12, "Int")
NETWORK_CONNECTIVITY_HINT["Roaming"] := NumGet(Buf, 16, "Int")
return NETWORK_CONNECTIVITY_HINT
}
throw OSError()
}
; =============================================================================================================================================================
; Example
; =============================================================================================================================================================
for k, v in GetNetworkConnectivityHint()
output .= k ": " v "`n"
MsgBox output