{"record":{"id":"c2e794b736c23898","repo":"rustdesk/rustdesk","slug":"failed-to-open-registry-key-subkey-err","errorCode":null,"errorMessage":"Failed to open registry key {subkey}: {err}","messagePattern":"Failed to open registry key (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/platform/windows.rs","lineNumber":3660,"sourceCode":"fn build_msi_uninstall_command(product_code: &str) -> String {\n    format!(\n        \"set \\\"RUSTDESK_MSI_EXIT_CODE=\\\"\\n\\\nMsiExec.exe /X {product_code} /norestart REBOOT=ReallySuppress\\n\\\nset \\\"RUSTDESK_MSI_EXIT_CODE=%ERRORLEVEL%\\\"\\n\\\nif \\\"%RUSTDESK_MSI_EXIT_CODE%\\\"==\\\"{MSI_EXIT_SUCCESS_REBOOT_REQUIRED}\\\" echo MSI uninstall succeeded with a reboot recommendation; continuing without reboot.\\n\\\nif \\\"%RUSTDESK_MSI_EXIT_CODE%\\\"==\\\"{MSI_EXIT_SUCCESS_REBOOT_INITIATED}\\\" echo MSI uninstall succeeded with a reboot request; continuing without forcing reboot.\\n\\\nif not \\\"%RUSTDESK_MSI_EXIT_CODE%\\\"==\\\"0\\\" if not \\\"%RUSTDESK_MSI_EXIT_CODE%\\\"==\\\"{MSI_EXIT_SUCCESS_REBOOT_REQUIRED}\\\" if not \\\"%RUSTDESK_MSI_EXIT_CODE%\\\"==\\\"{MSI_EXIT_SUCCESS_REBOOT_INITIATED}\\\" exit /b %RUSTDESK_MSI_EXIT_CODE%\\n\\\nver > nul\"\n    )\n}\n\nfn get_reg_string_of(subkey: &str, name: &str) -> ResultType<Option<String>> {\n    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);\n    let path = subkey.strip_prefix(HKLM_PREFIX).unwrap_or(subkey);\n    let key = match hklm.open_subkey(path) {\n        Ok(key) => key,\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(None),\n        Err(err) => bail!(\"Failed to open registry key {subkey}: {err}\"),\n    };\n    match key.get_value::<String, _>(name) {\n        Ok(value) => Ok(Some(value)),\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),\n        Err(err) => bail!(\"Failed to read {name} from registry key {subkey}: {err}\"),\n    }\n}\n\nfn get_windows_installer_state(subkey: &str) -> ResultType<Option<bool>> {\n    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);\n    let path = subkey.strip_prefix(HKLM_PREFIX).unwrap_or(subkey);\n    let key = match hklm.open_subkey(path) {\n        Ok(key) => key,\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(None),\n        Err(err) => bail!(\"Failed to open registry key {subkey}: {err}\"),\n    };\n    match key.get_value::<u32, _>(REG_NAME_WINDOWS_INSTALLER) {\n        Ok(value) => Ok(Some(value == MSI_WINDOWS_INSTALLER_VALUE)),","sourceCodeStart":3642,"sourceCodeEnd":3678,"githubUrl":"https://github.com/rustdesk/rustdesk/blob/91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540/src/platform/windows.rs#L3642-L3678","documentation":"`get_reg_string_of` opens an HKLM subkey (path stripped of the HKLM prefix) to read a string value. A missing key is treated as `Ok(None)`, but any other open failure (e.g. access denied, invalid key name) bails with this error including the subkey and the io error.","triggerScenarios":"Calling registry-reading helpers with a subkey that exists in name but cannot be opened — typically `ERROR_ACCESS_DENIED` from reading protected uninstall keys without elevation, or a malformed subkey path with invalid characters.","commonSituations":"Running the client without administrator rights while reading `HKLM\\...\\Uninstall\\...` keys restricted by ACLs; 32/64-bit registry view mismatch (key exists only in WOW64 view); typo in subkey constant.","solutions":["Run the process elevated (as administrator) so HKLM keys are readable","Verify the subkey string is correct and exists (regedit / `reg query`); note NotFound is already handled as None so this error means something other than absence","Check bitness: open the 64-bit view explicitly (KEY_WOW64_64KEY) if the key lives in the native view","Inspect the embedded io error for the exact Win32 code (5 = access denied, 87 = invalid parameter)"],"exampleFix":"// caller handling\nmatch get_reg_string_of(subkey, \"DisplayVersion\") {\n    Ok(v) => { /* None means key/value missing */ }\n    Err(e) if e.to_string().contains(\"Failed to open registry key\") => {\n        // not elevated or key unreadable — retry elevated or degrade gracefully\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"// probe readability beforehand (elevated check)\nlet hklm = RegKey::predef(HKEY_LOCAL_MACHINE);\nlet readable = hklm.open_subkey(path).map(|_| ()).is_ok();\nif !readable { /* request elevation or skip */ }","typeGuard":null,"tryCatchPattern":"match get_reg_string_of(subkey, name) {\n    Ok(Some(v)) => v,\n    Ok(None) => default_value,\n    Err(e) => { log::warn!(\"{e}\"); default_value }\n}","preventionTips":["Run registry-reading install checks elevated","Treat Ok(None) as 'absent' and this error as 'access/validity' — handle them differently","Verify subkey constants against regedit output","Consider WOW64 view (KEY_WOW64_64KEY) when reading native keys"],"tags":["windows","registry","hklm","permissions"],"backgroundTag":"permission-denied","analyzedSha":"91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540","analyzedAt":"2026-09-10T19:53:44.083Z","contentChangedAt":"2026-09-10T19:53:44.083Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}