{"record":{"id":"73cfe232ab98860f","repo":"rustdesk/rustdesk","slug":"failed-to-read-name-from-registry-key-subkey","errorCode":null,"errorMessage":"Failed to read {name} from registry key {subkey}: {err}","messagePattern":"Failed to read (.+?) from registry key (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/platform/windows.rs","lineNumber":3665,"sourceCode":"if \\\"%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)),\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(None),\n        Err(err) => bail!(\"Failed to read {REG_NAME_WINDOWS_INSTALLER} from {subkey}: {err}\"),\n    }\n}\n","sourceCodeStart":3647,"sourceCodeEnd":3683,"githubUrl":"https://github.com/rustdesk/rustdesk/blob/91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540/src/platform/windows.rs#L3647-L3683","documentation":"After successfully opening the HKLM subkey, `get_reg_string_of` reads a REG_SZ value as `String`. A missing value maps to `Ok(None)`; any other read/convert failure (wrong value type such as REG_DWORD/REG_EXPAND_SZ, decode error, access issue) bails with this message naming the value and subkey.","triggerScenarios":"Reading a registry value that exists but is not a plain REG_SZ string (e.g. it's REG_DWORD or REG_BINARY), or the string contains invalid UTF-16/UTF-8 that winreg cannot convert to String.","commonSituations":"Third-party installers writing DisplayVersion/UninstallString as non-string types; corrupted uninstall entries; value written with unusual encoding by another tool.","solutions":["Inspect the value's type in regedit; if it's not REG_SZ, read it with the appropriate type or treat the entry as unusable","Check the io error in the message: ERROR_INVALID_PARAMETER / type errors indicate a type mismatch rather than absence","Repair the entry by reinstalling the referenced application so the uninstall key is rewritten correctly","If a third party wrote a bad type, delete the stale uninstall subkey and let the installer recreate it"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// ensure the value type is REG_SZ before the typed read\nlet key = hklm.open_subkey(path)?;\nlet is_string = key.query_value(name)\n    .map(|v| matches!(v.vtype, REG_SZ))\n    .unwrap_or(false);\nif !is_string { /* treat as missing or read raw */ }","typeGuard":null,"tryCatchPattern":"match get_reg_string_of(subkey, name) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"Failed to read\") => {\n        log::warn!(\"bad value type: {e}\"); None\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check the value's registry type with query_value before a typed get_value","Repair entries written with the wrong type by third-party installers","Prefer None/default on read failure for non-critical metadata","Reinstall the app to regenerate corrupted uninstall values"],"tags":["windows","registry","type-mismatch","hklm"],"backgroundTag":"type-mismatch","analyzedSha":"91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540","analyzedAt":"2026-09-10T19:53:44.083Z","contentChangedAt":"2026-09-10T19:53:44.083Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}