#include <windows.h> #include <stdio.h> #include <Netlistmgr.h> void main() { HRESULT hr = 0; VARIANT_BOOL vb = 0; INetworkListManager* pNlm = NULL; hr = CoInitialize( NULL ); if( Failed(hr) ) { printf( "CoInitialize Failed./n" ); return; } hr = CoCreateInstance( CLSID_NetworkListManager,NULL,CLSCTX_ALL,IID_INetworkListManager,(void**) &pNlm ); if( Failed(hr) ) { printf( "CoCreateInstance Failed./n" ); CoUninitialize(); return; } hr = pNlm->get_IsConnected ( &vb ); if( SUCCEEDED(hr) ) { if( vb ) { printf("Network Connected!/n" ); } else { printf("Network Not Connected./n" ); } } else { printf( "get_IsConnected Failed./n" ); } pNlm->Release(); CoUninitialize(); return; }
原文链接:https://www.f2er.com/vb/261281.html