writeValue
Category: Registry Operations
Namespace: web.registry.writeValue
Description
Writes a string value to the Windows Registry under HKEY_CURRENT_USER. Automatically creates the key if it doesn't exist.
Syntax
const success = await web.registry.writeValue({
keyPath: 'Software\\MyApp',
valueName: 'Setting',
value: 'MyValue'
});
Parameters
- keyPath (required) - Registry key path under HKEY_CURRENT_USER (e.g.,
'Software\\MyApp') - valueName (required) - Name of the registry value to write
- value (required) - String value to write
- valueType (optional) - Currently ignored; always writes as string (REG_SZ)
- rootKey (optional) - Currently ignored; always uses HKEY_CURRENT_USER
Returns
Promise<boolean> - Returns a promise that resolves with true if successful, false otherwise
Examples
Simple example
const success = await web.registry.writeValue({
keyPath: 'Software\\MyApp',
valueName: 'Username',
value: 'JohnDoe'
});
if (success) {
console.log('Value saved successfully');
}
Save application settings
// Save user preferences
const success = await web.registry.writeValue({
keyPath: 'Software\\MyApp\\Settings',
valueName: 'Theme',
value: 'dark'
});
if (success) {
console.log('Theme preference saved');
}
Save multiple settings
const settings = {
'Language': 'en',
'FontSize': '14',
'AutoSave': 'true'
};
for (const [name, value] of Object.entries(settings)) {
await web.registry.writeValue({
keyPath: 'Software\\MyApp\\Settings',
valueName: name,
value: value
});
}
console.log('All settings saved');
Use Cases
- Save application settings to the registry
- Store user preferences between sessions
- Save configuration values
- Remember last used file paths
- Store application state
Notes
- Always operates under
HKEY_CURRENT_USERroot key - Automatically creates the key if it doesn't exist
- Always writes as string type (REG_SZ)
- The
valueTypeparameter is currently ignored - The
rootKeyparameter is currently ignored - Returns
falseif the operation fails (e.g., permission denied)