Repository: microsoft/PowerToys
File: installer/PowerToysSetupCustomActions/CustomAction.cpp (C++)

Code before:
    
        HANDLE hUserToken = NULL;
        DWORD dwSessionId;
        ProcessIdToSessionId(GetCurrentProcessId(), &dwSessionId);
        auto rv = WTSQueryUserToken(dwSessionId, &hUserToken);

        if (rv == 0)
        {
            ExitOnFailure(hr, "Failed to query user token");
        }

        HANDLE hUserTokenDup;
        if (DuplicateTokenEx(hUserToken, TOKEN_ALL_ACCESS, NULL, SECURITY_IMPERSONATION_LEVEL::SecurityImpersonation, TOKEN_TYPE::TokenPrimary, &hUserTokenDup) == 0)
            // if (DuplicateToken(hUserToken, SECURITY_IMPERSONATION_LEVEL::SecurityImpersonation, &hUserTokenDup) == 0)
        {
            CloseHandle(hUserToken);
            CloseHandle(hUserTokenDup);
            ExitOnFailure(hr, "Failed to duplicate user token");
        }

        if (ImpersonateLoggedOnUser(hUserTokenDup))
        {
            STARTUPINFO startupInfo;
            ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
            startupInfo.cb = sizeof(STARTUPINFO);
            startupInfo.wShowWindow = SW_SHOWNORMAL;

            PROCESS_INFORMATION processInformation;

            PVOID lpEnvironment = NULL;
            CreateEnvironmentBlock(&lpEnvironment, hUserTokenDup, FALSE);

            CreateProcessAsUser(
                hUserTokenDup,
                NULL,
                commandLine.data(),
                NULL,
                NULL,
                FALSE,
                CREATE_DEFAULT_ERROR_MODE | CREATE_UNICODE_ENVIRONMENT,
                lpEnvironment,
                NULL,
                &startupInfo,
                &processInformation);

            if (!CloseHandle(processInformation.hProcess))
            {
                er = ERROR_INSTALL_FAILURE;
            }
            if (!CloseHandle(processInformation.hThread))
            {

Review comment (suggestion):
```suggestion
            STARTUPINFO startupInfo {.cb = = sizeof(STARTUPINFO),  .wShowWindow = SW_SHOWNORMAL};
```

Code after:
    if (isSystemUser) {
    
        HANDLE hUserToken = NULL;
        DWORD dwSessionId;
        ProcessIdToSessionId(GetCurrentProcessId(), &dwSessionId);
        auto rv = WTSQueryUserToken(dwSessionId, &hUserToken);

        if (rv == 0)
        {
            ExitOnFailure(hr, "Failed to query user token");
        }

        HANDLE hUserTokenDup;
        if (DuplicateTokenEx(hUserToken, TOKEN_ALL_ACCESS, NULL, SECURITY_IMPERSONATION_LEVEL::SecurityImpersonation, TOKEN_TYPE::TokenPrimary, &hUserTokenDup) == 0)
        {
            CloseHandle(hUserToken);
            CloseHandle(hUserTokenDup);
            ExitOnFailure(hr, "Failed to duplicate user token");
        }

        if (ImpersonateLoggedOnUser(hUserTokenDup))
        {
            STARTUPINFO startupInfo{ .cb = sizeof(STARTUPINFO),  .wShowWindow = SW_SHOWNORMAL };
            PROCESS_INFORMATION processInformation;

            PVOID lpEnvironment = NULL;
            CreateEnvironmentBlock(&lpEnvironment, hUserTokenDup, FALSE);

            CreateProcessAsUser(
                hUserTokenDup,
                NULL,
                commandLine.data(),
                NULL,
                NULL,
                FALSE,
                CREATE_DEFAULT_ERROR_MODE | CREATE_UNICODE_ENVIRONMENT,
                lpEnvironment,
                NULL,
                &startupInfo,
                &processInformation);

            if (!CloseHandle(processInformation.hProcess))
            {
                er = ERROR_INSTALL_FAILURE;
            }
            if (!CloseHandle(processInformation.hThread))
            {
                er = ERROR_INSTALL_FAILURE;
            }

            RevertToSelf();