Untitled
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
#include <Windows.h> #include <iostream> #include <netlistmgr.h> int main() { HRESULT hr = CoInitialize(NULL); if (SUCCEEDED(hr)) { INetworkListManager* pNetworkListManager = NULL; hr = CoCreateInstance(CLSID_NetworkListManager, NULL, CLSCTX_ALL, IID_INetworkListManager, (LPVOID*)&pNetworkListManager); if (SUCCEEDED(hr)) { IEnumNetworks* pEnumNetworks = NULL; hr = pNetworkListManager->GetNetworks(NLM_ENUM_NETWORK_CONNECTED, &pEnumNetworks); if (SUCCEEDED(hr) && pEnumNetworks != NULL) { INetwork* pNetwork = NULL; while (pEnumNetworks->Next(1, &pNetwork, NULL) == S_OK) { BSTR networkName; if (SUCCEEDED(pNetwork->GetName(&networkName))) { std::wcout << L"Connected Network Name: " << networkName << std::endl; SysFreeString(networkName); } pNetwork->Release(); } pEnumNetworks->Release(); } pNetworkListManager->Release(); } CoUninitialize(); } return 0; }