c++windowswinapicomreverse-engineering

How to open network adapter properties via Windows API?


I'm creating a custom WLAN connection wizard, taking inspriation from Windows XP/Server 2003. On its sidebar, there is an option to 'Change advanced settings' (the screenshot is from a system WLAN wizard, not mine), which opens adapter properties. Same thing does ncpa.cpl on Windows Vista and newer when 'Properties' are clicked in the menu appearing on clicking RMB on the network adapter. This is target behavior.

I have tried digging through docs on Microsoft Learn related to Network Configuration Interfaces COM interfaces and the closest match was INetCfgComponent::RaisePropertyUi but it opens specific network component settings, which is a miss—it is one level deeper than required. This is what exactly code from unanwsered question 15901907 does.

Then I chose to search for undocumented Windows interfaces and stumbled upon GUID {C08956A4-1CD3-11D1-B1C5-00805FC1270E} known as INetConnectionPropertyUi which is missing from registry at HKCR hive but accessible via CoCreateInstance. I thought this will be a success with the following code (full file can be seen here):

hr = pNetCCPui->AddPages(NULL, PropSheetExCallback, reinterpret_cast<LPARAM>(&pinfo));
if (SUCCEEDED(hr))
{
    if (PropertySheetW(&pinfo) < 0)
        hr = E_FAIL;
}

But I crash with 0xC0000005 (access violation) at PropertySheetW call immediately. The desired property sheet appears during the crash, but completely blank.

Today I got an idea of getting the desired window via ShellExecute thinking it's accessible via specific CLSID. I wasn't far away from target behavior—I got at least to adapter status window, but again, a miss—this time one level shallow than required:

shell:::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\{network adapter GUID}

I found this approach via unanswered (?) question 78393276 and freshly moved question 1840801 on Superuser.


I look for ways to open adapter properies dialog that are not:

What kind of solution would work:


Solution

  • It seems that I will answer my question for another time. It's possible to get there ShellExecuteW way:

    {
      ATL::CStringW cswNetworkAdapterPath = L"";
      LPOLESTR lpwszNetConCLSID;
    
      StringFromIID(CLSID_NetworkConnections, &lpwszNetConCLSID);
      cswNetworkAdapterPath.Format(L"::%s\\::%s", lpwszNetConCLSID, lpwszAdapterGUID);
    
      ShellExecuteW(NULL, L"properties", cswNetworkAdapterPath, NULL, NULL, SW_SHOWNORMAL);
    }
    

    That's the quick and dirty approach but it works (the less dirty will be CSIDL_CONNECTIONS way). You may also need to grab a thread to let the property sheet open.