src/runner/settings_window.cpp
// Try to run the Settings process with non-elevated privileges.
Try to run the Settings process with non-elevated privileges.
Try to run the Settings process with non - elevated privileges .
BOOL run_settings_non_elevated(LPCWSTR executable_path, LPWSTR executable_args, PROCESS_INFORMATION* process_info)
{
    HWND hwnd = GetShellWindow();
    if (!hwnd)
    {
        return false;
    }
    DWORD pid;
    GetWindowThreadProcessId(hwnd, &pid);
    winrt::handle process{ OpenProcess(PROCESS_CREATE_PROCESS, FALSE, pid) };
    if (!process)
    {
        return false;
    }
    SIZE_T size = 0;
    InitializeProcThreadAttributeList(nullptr, 1, 0, &size);
    auto pproc_buffer = std::unique_ptr<char[]>{ new (std::nothrow) char[size] };
    auto pptal = reinterpret_cast<PPROC_THREAD_ATTRIBUTE_LIST>(pproc_buffer.get());
    if (!pptal)
    {
        return false;
    }
    if (!InitializeProcThreadAttributeList(pptal, 1, 0, &size))
    {
        return false;
    }
    if (!UpdateProcThreadAttribute(pptal,
                                   0,
                                   PROC_THREAD_ATTRIBUTE_PARENT_PROCESS,
                                   &process,
                                   sizeof(process),
                                   nullptr,
                                   nullptr))
    {
        return false;
    }
    STARTUPINFOEX siex = { 0 };
    siex.lpAttributeList = pptal;
    siex.StartupInfo.cb = sizeof(siex);
    BOOL process_created = CreateProcessW(executable_path,
                                          executable_args,
                                          nullptr,
                                          nullptr,
                                          FALSE,
                                          EXTENDED_STARTUPINFO_PRESENT,
                                          nullptr,
                                          nullptr,
                                          &siex.StartupInfo,
                                          process_info);
    return process_created;
}
BOOL run_settings_non_elevated ( LPCWSTR executable_path , LPWSTR executable_args , PROCESS_INFORMATION * process_info ) { HWND hwnd = GetShellWindow ( ) ; if ( ! hwnd ) { return false ; } DWORD pid ; GetWindowThreadProcessId ( hwnd , & pid ) ; winrt :: handle process { OpenProcess ( PROCESS_CREATE_PROCESS , FALSE , pid ) } ; if ( ! process ) { return false ; } SIZE_T size = 0 ; InitializeProcThreadAttributeList ( nullptr , 1 , 0 , & size ) ; auto pproc_buffer = std :: unique_ptr < char [ ] > { new ( std :: nothrow ) char [ size ] } ; auto pptal = reinterpret_cast < PPROC_THREAD_ATTRIBUTE_LIST > ( pproc_buffer . get ( ) ) ; if ( ! pptal ) { return false ; } if ( ! InitializeProcThreadAttributeList ( pptal , 1 , 0 , & size ) ) { return false ; } if ( ! UpdateProcThreadAttribute ( pptal , 0 , PROC_THREAD_ATTRIBUTE_PARENT_PROCESS , & process , sizeof ( process ) , nullptr , nullptr ) ) { return false ; } STARTUPINFOEX siex = { 0 } ; siex . lpAttributeList = pptal ; siex . StartupInfo . cb = sizeof ( siex ) ; BOOL process_created = CreateProcessW ( executable_path , executable_args , nullptr , nullptr , FALSE , EXTENDED_STARTUPINFO_PRESENT , nullptr , nullptr , & siex . StartupInfo , process_info ) ; return process_created ; }
Try to run the Settings process with non-elevated privileges.
Try to run the Settings process with non - elevated privileges .