zed-industries/zed · error

ShellExecuteW failed to launch elevated process (code: {resu

Error message

ShellExecuteW failed to launch elevated process (code: {result_code})

What it means

Bailed when ShellExecuteW with the elevated ('runas') launch fails to start the ETW helper subprocess; the raw result code (<= 32) is included. Those codes are the standard ShellExecuteW SE_ERR_* values, e.g. 2 = file not found, 3 = path not found, 5 = access denied (including UAC declined), 31 = no association, 32 = missing DLL.

Source

Thrown at crates/etw_tracing/etw_tracing.rs:611

    let file: Vec<u16> = format!("{}\0", exe_path.to_string_lossy())
        .encode_utf16()
        .collect();
    let parameters: Vec<u16> = format!("{args}\0").encode_utf16().collect();

    let result = unsafe {
        ShellExecuteW(
            None,
            PCWSTR(operation.as_ptr()),
            PCWSTR(file.as_ptr()),
            PCWSTR(parameters.as_ptr()),
            PCWSTR::null(),
            windows::Win32::UI::WindowsAndMessaging::SW_HIDE,
        )
    };

    let result_code = result.0 as usize;
    if result_code <= 32 {
        bail!("ShellExecuteW failed to launch elevated process (code: {result_code})");
    }

    let (stream, _) = listener.accept().context("Accept subprocess connection")?;

    let mut session = EtwSession {
        output_path: output_path.to_path_buf(),
        stream: BufReader::new(stream),
        listener,
        socket_path: sock_path,
    };

    let status: StatusMessage =
        recv_json(&mut session.stream).context("Wait for Started status")?;

    match status {
        StatusMessage::Started => {}
        StatusMessage::Error { message } => {
            bail!("Subprocess reported error during start: {message}");

View on GitHub (pinned to f4178619ac)

Solutions

  1. Map the code: 2/3 = helper exe or path missing, 5 = access denied or UAC declined, 31/32 = association/DLL problems
  2. Verify the helper binary exists at the exact path passed to ShellExecuteW and is executable
  3. Accept the UAC prompt, or launch the parent from an already-elevated shell so no prompt is needed
  4. In non-interactive sessions, run the tracing pipeline from an administrator terminal instead of relying on runas
Defensive patterns

Strategy: fallback

Validate before calling

// Before attempting runas elevation, check whether the process is already elevated
// (e.g. via token-elevation check) and skip ShellExecuteW when it is;
// in non-interactive sessions, skip elevation entirely and surface a clear message.

Try / catch

Catch the bail and map the embedded SE_ERR code (2/3 missing path, 5 denied or UAC declined, 31/32 association/DLL) to a user-actionable message; offer retry so the user can accept the UAC prompt.

Prevention

When it happens

Trigger: The user declines the UAC prompt; the helper executable or its directory is missing at the path passed to ShellExecuteW; group policy blocks elevation; the process runs in a non-interactive session (service/CI) where no UAC prompt can appear.

Common situations: CI or service contexts with no interactive desktop; wrong install layout so the helper path is invalid; antivirus blocking the elevated spawn; standard-user accounts forbidden from elevating.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/ffb9923cda935850. Report an issue: GitHub.