readValue
Category: Registry Operations
Namespace: web.registry.readValue
Description
Reads a string value from the Windows Registry under HKEY_CURRENT_USER. Returns an empty string if the key or value doesn't exist.
Syntax
const value = await web.registry.readValue({
keyPath: 'Software\\MyApp',
valueName: 'Setting'
});
Parameters
- keyPath (required) - Registry key path under HKEY_CURRENT_USER (e.g.,
'Software\\MyApp') - valueName (required) - Name of the registry value to read
- rootKey (optional) - Currently ignored; always uses HKEY_CURRENT_USER
Returns
Promise<string> - Returns a promise that resolves with the registry value as a string, or an empty string if not found
Examples
Simple example
const value = await web.registry.readValue({
keyPath: 'Software\\MyApp',
valueName: 'Username'
});
console.log('Username:', value);
Read application settings
const theme = await web.registry.readValue({
keyPath: 'Software\\MyApp\\Settings',
valueName: 'Theme'
});
if (theme) {
console.log('Saved theme:', theme);
} else {
console.log('No theme saved, using default');
}
Check if value exists
const lastPath = await web.registry.readValue({
keyPath: 'Software\\MyApp',
valueName: 'LastOpenedPath'
});
if (lastPath) {
// Value exists, use it
console.log('Last path:', lastPath);
} else {
// Value doesn't exist (returns empty string)
console.log('No previous path saved');
}
Use Cases
- Load application settings from the registry
- Retrieve user preferences stored in previous sessions
- Read configuration values
- Check for previously saved data
- Load last used file paths or directories
Notes
- Always operates under
HKEY_CURRENT_USERroot key - Returns empty string if the key or value doesn't exist (not an error)
- Only reads string values (REG_SZ type)
- Use double backslashes (
\\) in key paths for JavaScript strings - The
rootKeyparameter is currently ignored by the implementation