WebExeBuilder Documentation

keyExists

Category: Registry Operations

Namespace: web.registry.keyExists

Description

Checks whether a registry key exists under HKEY_CURRENT_USER.

Syntax

const exists = await web.registry.keyExists({
    keyPath: 'Software\\MyApp'
});

Parameters

  • keyPath (required) - Registry key path under HKEY_CURRENT_USER to check
  • rootKey (optional) - Currently ignored; always uses HKEY_CURRENT_USER

Returns

Promise<boolean> - Returns a promise that resolves with true if the key exists, false otherwise

Examples

Simple example

const exists = await web.registry.keyExists({
    keyPath: 'Software\\MyApp'
});

if (exists) {
    console.log('Application registry key exists');
} else {
    console.log('First time running - no registry key');
}

Check before reading

const keyPath = 'Software\\MyApp\\Settings';
const exists = await web.registry.keyExists({ keyPath });

if (exists) {
    // Key exists, safe to read values
    const theme = await web.registry.readValue({
        keyPath: keyPath,
        valueName: 'Theme'
    });
} else {
    // First run, use defaults
    console.log('Using default settings');
}

Initialize on first run

const exists = await web.registry.keyExists({
    keyPath: 'Software\\MyApp'
});

if (!exists) {
    // First time running, create default settings
    await web.registry.writeValue({
        keyPath: 'Software\\MyApp',
        valueName: 'FirstRun',
        value: new Date().toISOString()
    });
    console.log('Application initialized');
}

Use Cases

  • Check if application has been run before
  • Verify registry key exists before reading values
  • Detect first-time application launch
  • Validate registry structure
  • Check for specific configuration sections

Notes

  • Always operates under HKEY_CURRENT_USER root key
  • Only checks if the key exists, not if it has any values
  • Returns false for non-existent keys (not an error)
  • Use valueExists() to check for specific values within a key