Home > Enterprise >  Can Win32 applications open the system's settings from code?
Can Win32 applications open the system's settings from code?

Time:03-09

Is it possible to open Windows' settings dialogs using Win32 API calls from C? Such as the monitor settings (the one that allows you to set the monitor's resolution), and the network settings (the one that allows you to set the Wifi settings).

If it is possible, how to do that?

Or, is this not possible at all, and the user has to manually open them?

CodePudding user response:

Launch the Windows Settings app explains how to pull up the Windows Settings app using the ms-settings: URI scheme. It also lists the supported URIs, including the ones this question is asking for (ms-settings:network-wifi and ms-settings:display).

While the documentation proposes using the Windows Runtime API Launcher.LaunchUriAsync this is a fair bit complex with C (as opposed to C ). Since the URIs can be invoked from the command prompt using the start command (e.g. start ms-settings:display), it's reasonable to assume that ShellExecuteExW can handle the ms-settings: URI scheme as well.

And indeed, this does appear to work:

#include <Windows.h>

#include <stdio.h>

int main() {
    SHELLEXECUTEINFOW sei = {
        .cbSize = sizeof(sei),
        .hwnd = NULL,
        .lpVerb = L"open",
        .lpFile = L"ms-settings:display",
        //.lpFile = L"ms-settings:network-wifi",
        .nShow = SW_SHOWNORMAL,
    };
    if (!ShellExecuteExW(&sei))
    {
        printf("Failed with error code %d", GetLastError());
    }
}

I wasn't able to find any documentation that specifies this behavior, so this may well be an unsupported implementation detail. I will also mention that while SHELLEXECUTEINFOW has an lpClass field that can be used to specify a URI protocol scheme, none of my iterations to use it worked for the ms-settings: URI scheme.

  • Related