WLANxxx functions

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

User avatar
jNizM
Posts: 2530
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

WLANxxx functions

18 Jul 2019, 09:05

Moin,

hat von euch schon mal jemand mit den WLANxxx functions (wlanapi.h header) gearbeitet?

Speziell das auslesen der Bekannten Netzwerke? (Windows 10 -> Einstellungen -> Netzwerk und Internet -> WLAN -> Bekannte Netzwerke verwalten)

Hauptsächlich geht es dabei, nur zu überprüfen, ob ein bestimmtes WLAN in der "Bekannten-Liste" vorhanden ist, bzw alle Bekannten auszugeben.


grüße
jNizM
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
LuckyJoe
Posts: 211
Joined: 02 Oct 2013, 09:52

Re: WLANxxx functions

19 Jul 2019, 00:56

Hallo jNizM,

... nur als Denkansatz: hilft da nicht ein Script mit WMI, z.B. Win32_NetworkAdapter class?

Viel Erfolg.
HG - Lucky Joe
User avatar
jNizM
Posts: 2530
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: WLANxxx functions

19 Jul 2019, 05:06

Wenn es direkte WinAPI-Funktionen gibt, ist bei mir WMI nur die zweite Wahl.
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you
just me
Posts: 6548
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: WLANxxx functions

19 Jul 2019, 09:16

Moin jNizM,
hat von euch schon mal jemand mit den WLANxxx functions (wlanapi.h header) gearbeitet?
Bis heute noch nicht aber jetzt schon! ;)

Vielleicht bringt Dich das auf den Weg:

Code: Select all

; ================================================================================================================================
; https://docs.microsoft.com/en-us/windows/win32/api/wlanapi/
; ================================================================================================================================
#NoEnv
; WLAN_INTERFACE_STATE
WIS := {0: "wlan_interface_state_not_ready"
      , 1: "wlan_interface_state_connected"
      , 2: "wlan_interface_state_ad_hoc_network_formed"
      , 3: "wlan_interface_state_disconnecting"
      , 4: "wlan_interface_state_disconnected"
      , 5: "wlan_interface_state_associating"
      , 6: "wlan_interface_state_discovering"
      , 7: "wlan_interface_state_authenticating"}
; Size of WLAN_INTERFACE_INFO structure
WII_Size := 16 + 512 + 8
; Size of WLAN_AVAILABLE_NETWORK structure
WAN_Size := 512 + 36 + 20 + 32 + 28
;
HMOD := DllCall("LoadLibrary", "Str", "Wlanapi.dll", "UPtr")

If (RC := DllCall("Wlanapi.dll\WlanOpenHandle", "UInt", 2, "Ptr", 0, "PtrP", 0, "PtrP", WH, "UInt")) { ; Win Vista+
   MsgBox, 16, Error!, WlanOpenHandle() failed with error code %RC%!
   ExitApp
}
If (RC := DllCall("Wlanapi.dll\WlanEnumInterfaces", "Ptr", WH, "Ptr", 0, "PtrP", WIIL, "UInt")) {
   DllCall("Wlanapi.dll\WlanCloseHandle", "Ptr", WH, "Ptr", 0, "UInt")
   MsgBox, 16, Error!, WlanEnumInterfaces() failed with error code %RC%!
   Exitapp
}
WIIL_Items := NumGet(WIIL + 0, "UInt")
WII_Addr := WIIL + 8
Loop, %WIIL_Items% {
   Descr := StrGet(WII_Addr + 16, "UTF-16")
   StateNum := NumGet(WII_Addr + 528, "UInt")
   StateStr := WIS[StateNum]
   MsgBox, 0, Interface %A_Index% of %WIIL_Items%, Description: %Descr%`nState:%StateNum% -> %StateStr%
   RC := DllCall("Wlanapi.dll\WlanGetAvailableNetworkList", "Ptr", WH, "Ptr", WII_Addr, "UInt", 0, "Ptr", 0, "PtrP", WANL, "UInt")
   WANL_Items := NumGet(WANL + 0, "UInt")
   WAN_Addr := WANL + 8
   Loop, %WANL_Items% {
      WAN_SSID := NumGet(WAN_Addr + 512, "UInt") ? StrGet(WAN_Addr + 516, "CP0") : "N/A"
      Connected := NumGet(WAN_Addr + 620, "UInt")
      MsgBox, 0, WAN %A_Index% of %WANL_Items%, SSID:`t%WAN_SSID% (Connected = %Connected%)
      WAN_Addr += WAN_Size
   }
   DllCall("Wlanapi.dll\WlanFreeMemory", "Ptr", WANL)
   WII_Addr += WII_Size
}
DllCall("Wlanapi.dll\WlanFreeMemory", "Ptr", WIIL)
DllCall("Wlanapi.dll\WlanCloseHandle", "Ptr", WH, "Ptr", 0, "UInt")
ExitApp


/*
// maximum length of name, in characters
#define WLAN_MAX_NAME_LENGTH L2_PROFILE_MAX_NAME_LENGTH ; L2cnm.h: #define L2_PROFILE_MAX_NAME_LENGTH     256

typedef struct _WLAN_INTERFACE_INFO_LIST {
    DWORD dwNumberOfItems;
    DWORD dwIndex;

#ifdef __midl
    [unique, size_is(dwNumberOfItems)] WLAN_INTERFACE_INFO InterfaceInfo[*];
#else
    WLAN_INTERFACE_INFO InterfaceInfo[1];
#endif

} WLAN_INTERFACE_INFO_LIST, *PWLAN_INTERFACE_INFO_LIST;

// struct WLAN_INTERFACE_INFO defines the basic information for an interface
typedef struct _WLAN_INTERFACE_INFO {
    GUID InterfaceGuid;
    WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH];
    WLAN_INTERFACE_STATE isState;
} WLAN_INTERFACE_INFO, *PWLAN_INTERFACE_INFO;

// the states of the network (interface)
#ifdef __midl
// use the 4-byte enum
typedef [v1_enum] enum _WLAN_INTERFACE_STATE {
#else
typedef enum _WLAN_INTERFACE_STATE {
#endif
    wlan_interface_state_not_ready,
    wlan_interface_state_connected,
    wlan_interface_state_ad_hoc_network_formed,
    wlan_interface_state_disconnecting,
    wlan_interface_state_disconnected,
    wlan_interface_state_associating,
    wlan_interface_state_discovering,
    wlan_interface_state_authenticating
} WLAN_INTERFACE_STATE, *PWLAN_INTERFACE_STATE;

// available network flags
#define WLAN_AVAILABLE_NETWORK_CONNECTED                    0x00000001  // This network is currently connected
#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE                  0x00000002  // There is a profile for this network
#define WLAN_AVAILABLE_NETWORK_CONSOLE_USER_PROFILE         0x00000004  // The profile is the active console user's per user profile

#define WLAN_MAX_PHY_TYPE_NUMBER    8
//
// struct WLAN_AVAILABLE_NETWORK defines information needed for an available network
typedef struct _WLAN_AVAILABLE_NETWORK {
    WCHAR strProfileName[WLAN_MAX_NAME_LENGTH];
    DOT11_SSID dot11Ssid;
      typedef struct _DOT11_SSID {
        ULONG uSSIDLength;
        UCHAR ucSSID[DOT11_SSID_MAX_LENGTH];
      } DOT11_SSID, *PDOT11_SSID;
    DOT11_BSS_TYPE dot11BssType;
      typedef enum _DOT11_BSS_TYPE {
        dot11_BSS_type_infrastructure  = 1,
        dot11_BSS_type_independent     = 2,
        dot11_BSS_type_any             = 3
      } DOT11_BSS_TYPE, *PDOT11_BSS_TYPE;
    ULONG uNumberOfBssids;
    BOOL bNetworkConnectable;
    WLAN_REASON_CODE wlanNotConnectableReason; UInt
    ULONG uNumberOfPhyTypes;
    DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; 8 * UInt
    // bMorePhyTypes is set to TRUE if the PHY types for the network
    // exceeds WLAN_MAX_PHY_TYPE_NUMBER.
    // In this case, uNumerOfPhyTypes is WLAN_MAX_PHY_TYPE_NUMBER and the
    // first WLAN_MAX_PHY_TYPE_NUMBER PHY types are returned.
    BOOL bMorePhyTypes;
    WLAN_SIGNAL_QUALITY wlanSignalQuality; UInt
    BOOL bSecurityEnabled;
    DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; UInt
    DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; UInt
    DWORD dwFlags;
    DWORD dwReserved;
} WLAN_AVAILABLE_NETWORK, *PWLAN_AVAILABLE_NETWORK;
*/
Viel Spaß und ein schönes Wochenende!
User avatar
jNizM
Posts: 2530
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: WLANxxx functions

22 Jul 2019, 04:16

Wenn ich mir die Strukturen unten anschaue, hätte es bei mir doch ein bisschen länger gedauert :D

Deshalb, wie immer vielen Dank justme ;)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1909) x64 | [GitHub] Profile
Donations are appreciated if I could help you

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 36 guests