On my setup (Windows desktop, Wi‑Fi connected), this prints the current SSID even when Location services are disabled in Settings, and I do not get any visible location consent prompt when running it as a plain Win32 console app.
The code below queries the current SSID via the native WLAN API (wlanapi.dll) using WlanQueryInterface with wlan_intf_opcode_current_connection, and then reading wlanAssociationAttributes.dot11Ssid. However, Microsoft’s “Wi‑Fi access location changes” documentation does classify WlanQueryInterface with wlan_intf_opcode_current_connection as a location‑sensitive API that can be gated by location consent and may return ERROR_ACCESS_DENIED in more locked‑down or policy‑controlled environments.
If your requirement is “don’t use any API that Microsoft considers part of the location‑sensitive surface at all”, there is no supported way to obtain the current SSID that fully satisfies that constraint.
#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
#include <wtypes.h>
#include <stdio.h>
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")
void print_ssid(const DOT11_SSID* ssid) {
if (ssid->uSSIDLength == 0) {
printf("SSID: (hidden / empty)\n");
return;
}
printf("SSID: ");
for (ULONG i = 0; i < ssid->uSSIDLength; i++) {
unsigned char c = ssid->ucSSID[i];
if (c >= 32 && c < 127) {
putchar(c);
}
else {
printf("\\x%02X", c);
}
}
putchar('\n');
}
int main() {
DWORD negotiatedVersion = 0;
HANDLE clientHandle = NULL;
DWORD result = ERROR_SUCCESS;
// 1. Open handle
result = WlanOpenHandle(2, NULL, &negotiatedVersion, &clientHandle);
if (result != ERROR_SUCCESS) {
printf("WlanOpenHandle failed with error: %u\n", result);
return 1;
}
// 2. Enumerate interfaces
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
result = WlanEnumInterfaces(clientHandle, NULL, &pIfList);
if (result != ERROR_SUCCESS) {
printf("WlanEnumInterfaces failed with error: %u\n", result);
WlanCloseHandle(clientHandle, NULL);
return 1;
}
if (pIfList->dwNumberOfItems == 0) {
printf("No WLAN interfaces found.\n");
WlanFreeMemory(pIfList);
WlanCloseHandle(clientHandle, NULL);
return 0;
}
// 3. Iterate interfaces
for (unsigned int i = 0; i < pIfList->dwNumberOfItems; i++) {
PWLAN_INTERFACE_INFO pIfInfo = &pIfList->InterfaceInfo[i];
wprintf(L"Interface %u: %ls\n", i, pIfInfo->strInterfaceDescription);
printf(" State: %d\n", pIfInfo->isState);
if (pIfInfo->isState != wlan_interface_state_connected) {
printf(" Not connected, skipping.\n");
continue;
}
// 4. Query current connection
DWORD dataSize = 0;
PWLAN_CONNECTION_ATTRIBUTES pConnAttrs = NULL;
WLAN_OPCODE_VALUE_TYPE opType;
result = WlanQueryInterface(
clientHandle,
&pIfInfo->InterfaceGuid,
wlan_intf_opcode_current_connection,
NULL,
&dataSize,
(PVOID*)&pConnAttrs,
&opType
);
if (result != ERROR_SUCCESS) {
printf(" WlanQueryInterface failed with error: %u\n", result);
continue;
}
// 5. Cast and print SSID
if (pConnAttrs->isState == wlan_interface_state_connected) {
DOT11_SSID ssid = pConnAttrs->wlanAssociationAttributes.dot11Ssid;
print_ssid(&ssid);
}
else {
printf(" Interface not in connected state according to connection attrs.\n");
}
// 6. Cleanup per-interface
if (pConnAttrs) {
WlanFreeMemory(pConnAttrs);
}
}
// 7. Global cleanup
if (pIfList) {
WlanFreeMemory(pIfList);
}
if (clientHandle) {
WlanCloseHandle(clientHandle, NULL);
}
printf("Done.\n");
getchar(); // keep console open
return 0;
}