{"record":{"id":"8d953acb3f695d79","repo":"ramensoftware/windhawk","slug":"regsetvalueex","errorCode":null,"errorMessage":"RegSetValueEx","messagePattern":"RegSetValueEx","errorType":"error_code","errorClass":"SettingsError","httpStatus":null,"severity":"error","filePath":"src/windhawk-core/windows/src/registry.rs","lineNumber":466,"sourceCode":"    }\n\n    fn set_raw(&self, name: &str, value_type: u32, data: &[u8]) -> Result<(), SettingsError> {\n        self.check_name(\"set\", name)?;\n        let Some(hkey) = self.hkey() else {\n            return Err(self.err(\"set\", 0, \"set on a read-only/absent key\"));\n        };\n        let name_w = to_wide(name);\n        // A length the API's u32 cannot hold has no honest value to pass, and a\n        // clamped one would hand the call a length the buffer does not have.\n        let len = u32::try_from(data.len())\n            .map_err(|_| self.err(\"set\", 0, \"value is too large for the registry\"))?;\n        // SAFETY: name_w is NUL-terminated; data/len describe a valid buffer.\n        let rc =\n            unsafe { RegSetValueExW(hkey, name_w.as_ptr(), 0, value_type, data.as_ptr(), len) };\n        if rc == ERROR_SUCCESS {\n            Ok(())\n        } else {\n            Err(self.err(\"set\", rc, \"RegSetValueEx\"))\n        }\n    }\n}\n\n/// Decode a `REG_SZ` byte buffer (UTF-16LE, possibly NUL-terminated).\nfn decode_sz(bytes: &[u8]) -> String {\n    let units: Vec<u16> = bytes\n        .chunks_exact(2)\n        .map(|c| u16::from_le_bytes([c[0], c[1]]))\n        .collect();\n    from_wide_nul(&units)\n}\n\nfn decode_dword(bytes: &[u8]) -> Option<i32> {\n    if bytes.len() == 4 {\n        Some(i32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]))\n    } else {\n        None","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/ramensoftware/windhawk/blob/61d99ed8e182e1af1b60109612b6763ad1b4b74e/src/windhawk-core/windows/src/registry.rs#L448-L484","documentation":"The RegSetValueExW call in set_raw failed with an OS error other than ERROR_SUCCESS; the write to the registry value did not happen. The error message carries the Win32 function name plus the underlying OS error code.","triggerScenarios":"Writing a value when access is denied (ERROR_ACCESS_DENIED), the key handle is invalid, the value type/length combination is rejected, registry quota is exceeded, or the key was deleted concurrently.","commonSituations":"Writing to HKLM without admin rights (UAC); anti-malware or Group Policy locking mod keys; key deleted by another process mid-run; quota limits on very large values.","solutions":["Check the wrapped OS code — ERROR_ACCESS_DENIED means elevate privileges or choose a writable location (e.g. HKCU instead of HKLM).","Re-open the key with KEY_SET_VALUE if the handle may have gone stale.","Verify the key still exists and was not removed concurrently; recreate if needed.","Reduce value size / use an allowed type if the API rejected type or quota."],"exampleFix":"// before\nsettings.set_string(\"key\", \"v\")?; // fails under HKLM without admin\n// after\n// open settings under HKCU (writable) or handle elevation\nmatch settings.set_string(\"key\", \"v\") {\n    Err(e) if e.os_code() == ERROR_ACCESS_DENIED => eprintln!(\"run elevated or use HKCU\"),\n    r => r?,\n}","handlingStrategy":"try-catch","validationCode":"// ensure the key exists and the process has write access (e.g. prefer HKCU over HKLM)","typeGuard":null,"tryCatchPattern":"match settings.set_string(\"k\", \"v\") {\n    Err(e) if e.message().starts_with(\"RegSetValueEx\") => {\n        if e.message().contains(\"access is denied\") { /* elevate or switch to HKCU */ }\n    }\n    r => r?,\n}","preventionTips":["Write to user-writable hives (HKCU) unless elevation is guaranteed.","Handle ERROR_ACCESS_DENIED explicitly with a user-facing hint.","Avoid concurrent deletion of keys being written.","Check the wrapped OS code in the message for the precise cause."],"tags":["registry","win32","regsetvalueex","permissions"],"backgroundTag":"api-error-response","analyzedSha":"61d99ed8e182e1af1b60109612b6763ad1b4b74e","analyzedAt":"2026-09-12T14:02:41.115Z","contentChangedAt":"2026-09-12T14:02:41.115Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}