Пример #1
0
HRESULT PipeLaunchParentProcess(
    __in_z LPCWSTR wzCommandLine,
    __in int nCmdShow,
    __in_z LPWSTR sczConnectionName,
    __in_z LPWSTR sczSecret,
    __in BOOL /*fDisableUnelevate*/
    )
{
    HRESULT hr = S_OK;
    DWORD dwProcessId = 0;
    LPWSTR sczBurnPath = NULL;
    LPWSTR sczParameters = NULL;
    HANDLE hProcess = NULL;

    dwProcessId = ::GetCurrentProcessId();

    hr = PathForCurrentProcess(&sczBurnPath, NULL);
    ExitOnFailure(hr, "Failed to get current process path.");

    hr = StrAllocFormatted(&sczParameters, L"-%ls %ls %ls %u %ls", BURN_COMMANDLINE_SWITCH_UNELEVATED, sczConnectionName, sczSecret, dwProcessId, wzCommandLine);
    ExitOnFailure(hr, "Failed to allocate parameters for unelevated process.");

#ifdef ENABLE_UNELEVATE
    if (fDisableUnelevate)
    {
        hr = ProcExec(sczBurnPath, sczParameters, nCmdShow, &hProcess);
        ExitOnFailure1(hr, "Failed to launch parent process with unelevate disabled: %ls", sczBurnPath);
    }
    else
    {
        // Try to launch unelevated and if that fails for any reason, try launch our process normally (even though that may make it elevated).
        hr = ProcExecuteAsInteractiveUser(sczBurnPath, sczParameters, &hProcess);
        if (FAILED(hr))
        {
            hr = ShelExecUnelevated(sczBurnPath, sczParameters, L"open", NULL, nCmdShow);
            if (FAILED(hr))
            {
                hr = ShelExec(sczBurnPath, sczParameters, L"open", NULL, nCmdShow, NULL, NULL);
                ExitOnFailure1(hr, "Failed to launch parent process: %ls", sczBurnPath);
            }
        }
    }
#else
    hr = ProcExec(sczBurnPath, sczParameters, nCmdShow, &hProcess);
    ExitOnFailure1(hr, "Failed to launch parent process with unelevate disabled: %ls", sczBurnPath);
#endif

LExit:
    ReleaseHandle(hProcess);
    ReleaseStr(sczParameters);
    ReleaseStr(sczBurnPath);

    return hr;
}
Пример #2
0
static HRESULT RunRunOnce(
    __in const BURN_REGISTRATION* pRegistration,
    __in int nCmdShow
    )
{
    HRESULT hr = S_OK;
    LPWSTR sczNewCommandLine = NULL;
    LPWSTR sczBurnPath = NULL;
    HANDLE hProcess = NULL;

    hr = RegistrationGetResumeCommandLine(pRegistration, &sczNewCommandLine);
    ExitOnFailure(hr, "Unable to get resume command line from the registry");

    // and re-launch
    hr = PathForCurrentProcess(&sczBurnPath, NULL);
    ExitOnFailure(hr, "Failed to get current process path.");

    hr = ProcExec(sczBurnPath, 0 < sczNewCommandLine ? sczNewCommandLine : L"", nCmdShow, &hProcess);
    ExitOnFailure(hr, "Failed to re-launch bundle process after RunOnce: %ls", sczBurnPath);

LExit:
    ReleaseHandle(hProcess);
    ReleaseStr(sczNewCommandLine);
    ReleaseStr(sczBurnPath);

    return hr;
}
Пример #3
0
static HRESULT RunRunOnce(
    __in_z_opt LPCWSTR wzCommandLine,
    __in int nCmdShow
    )
{
    HRESULT hr = S_OK;
    LPWSTR sczNewCommandLine = NULL;
    LPWSTR sczBurnPath = NULL;
    HANDLE hProcess = NULL;
    int argc = 0;
    LPWSTR* argv = NULL;

    // rebuild the command line without the runonce switch
    if (wzCommandLine && *wzCommandLine)
    {
        argv = ::CommandLineToArgvW(wzCommandLine, &argc);
        ExitOnNullWithLastError(argv, hr, "Failed to get command line.");

        for (int i = 0; i < argc; ++i)
        {
            if (!((argv[i][0] == L'-' || argv[i][0] == L'/') && CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, &argv[i][1], -1, BURN_COMMANDLINE_SWITCH_RUNONCE, -1)))
            {
                PathCommandLineAppend(&sczNewCommandLine, argv[i]);
            }
        }
    }

    // and re-launch
    hr = PathForCurrentProcess(&sczBurnPath, NULL);
    ExitOnFailure(hr, "Failed to get current process path.");

    hr = ProcExec(sczBurnPath, 0 < sczNewCommandLine ? sczNewCommandLine : L"", nCmdShow, &hProcess);
    ExitOnFailure1(hr, "Failed to re-launch bundle process after RunOnce: %ls", sczBurnPath);

LExit:
    if (argv)
    {
        ::LocalFree(argv);
    }

    ReleaseHandle(hProcess);
    ReleaseStr(sczNewCommandLine);
    ReleaseStr(sczBurnPath);

    return hr;
}