openai/codex · error · anyhow::Error

RegCreateKeyExW failed

Error message

RegCreateKeyExW failed: {status} ({error})

What it means

RegCreateKeyExW returned a nonzero status while creating/opening the SpecialAccounts\UserList registry key under HKLM for hiding sandbox users from the Windows login screen. Typically ERROR_ACCESS_DENIED when the process is not elevated, or the registry path is locked.

Solutions

  1. Run the sandbox setup step from an elevated (administrator) process
  2. Check the formatted error text for the specific Win32 error and address it (permissions, corrupted hive)
  3. Retry after elevation is granted
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/windows-sandbox-rs/src/hide_users.rs:124 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/b5447179b2313d1d. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/windows-sandbox-rs/src/hide_users.rs:124

fn create_userlist_key() -> anyhow::Result<HKEY> {
    let key_path = to_wide(USERLIST_KEY_PATH);
    let mut key: HKEY = 0;
    let status = unsafe {
        RegCreateKeyExW(
            HKEY_LOCAL_MACHINE,
            key_path.as_ptr(),
            0,
            std::ptr::null_mut(),
            REG_OPTION_NON_VOLATILE,
            KEY_WRITE,
            std::ptr::null_mut(),
            &mut key,
            std::ptr::null_mut(),
        )
    };
    if status != 0 {
        return Err(anyhow!(
            "RegCreateKeyExW failed: {status} ({error})",
            error = format_last_error(status as i32)
        ));
    }
    Ok(key)
}

/// Sets HIDDEN|SYSTEM on `path` if needed, returning whether it changed anything.
fn hide_directory(path: &Path) -> anyhow::Result<bool> {
    let wide = to_wide(path);
    let attrs = unsafe { GetFileAttributesW(wide.as_ptr()) };
    if attrs == INVALID_FILE_ATTRIBUTES {
        let err = unsafe { GetLastError() } as i32;
        return Err(anyhow!(
            "GetFileAttributesW failed for {}: {err} ({error})",
            path.display(),
            error = format_last_error(err)
        ));

View on GitHub (pinned to 339751715c)