rustdesk/rustdesk · error

Failed to open Local Port monitor. Error: {}

Error message

Failed to open Local Port monitor. Error: {}

What it means

execute_on_local_port opens the Local Port monitor XCV handle via OpenPrinterW (XCV_MONITOR_LOCAL_PORT). If OpenPrinterW fails it bails with the last OS error. This handle is required to add or delete a local printer port, so the operation cannot proceed.

Source

Thrown at libs/remote_printer/src/setup/port.rs:73

    )?;
    Ok(r.unwrap_or(false))
}

unsafe fn execute_on_local_port(port: &PCWSTR, command: &PCWSTR) -> ResultType<()> {
    let mut dft = PRINTER_DEFAULTSW {
        pDataType: null_mut(),
        pDevMode: null_mut(),
        DesiredAccess: SERVER_WRITE,
    };
    let mut h_monitor: HANDLE = null_mut();
    if FALSE
        == OpenPrinterW(
            XCV_MONITOR_LOCAL_PORT.as_ptr() as _,
            &mut h_monitor,
            &mut dft as *mut PRINTER_DEFAULTSW as _,
        )
    {
        bail!(format!(
            "Failed to open Local Port monitor. Error: {}",
            io::Error::last_os_error()
        ))
    }

    let mut output_needed: u32 = 0;
    let mut status: u32 = 0;
    if FALSE
        == XcvDataW(
            h_monitor,
            command.as_ptr(),
            port.as_ptr() as *mut u8,
            (port.len() + 1) as u32 * 2,
            null_mut(),
            0,
            &mut output_needed,
            &mut status,
        )

View on GitHub (pinned to 91c9fccbb0)

Solutions

  1. Run the process elevated (administrator) — XcvData operations on port monitors require admin access.
  2. Verify the spooler service is running and restart it if wedged.
  3. Check the embedded OS error: ERROR_ACCESS_DENIED means elevation; ERROR_SERVICE_DOES_NOT_EXIST style errors point to a broken spooler/monitor install.
  4. Confirm the Local Port monitor is present under HKLM\SYSTEM\CurrentControlSet\Control\Print\Monitors\Local Port.

Example fix

// before
add_local_port(&port_name)?; // access denied unelevated

// after
if !is_elevated() {
    bail!("Adding a printer port requires administrator privileges");
}
add_local_port(&port_name)?;
Defensive patterns

Strategy: validation

Validate before calling

fn assert_can_manage_ports() -> ResultType<()> {
    if !is_elevated() {
        bail!("port monitor XcvData requires administrator");
    }
    Ok(())
}

Try / catch

match add_local_port(&port) {
    Err(e) if e.to_string().contains("Failed to open Local Port monitor") => {
        if !is_elevated() { relaunch_elevated()?; }
        Err(e)
    }
    r => r,
}

Prevention

When it happens

Trigger: Calling add_local_port or delete_local_port when OpenPrinterW on the "Local Port" monitor XCV object fails — typically due to lack of admin rights (XcvData requires SERVER_ACCESS_ADMINISTER), a stopped spooler, or the Local Port monitor not being installed.

Common situations: Non-elevated process trying to add/delete a port; print spooler not running; corrupted or removed standard port monitors on the machine.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of rustdesk/rustdesk@91c9fccbb0 (2026-09-10). Data as JSON: /api/errors/68a1e2cf46ddec16. Report an issue: GitHub.