kessler / node-regedit

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
MIT License
277 stars 45 forks source link

unsupported hive error on putValue() #11

Closed alexcroox closed 9 years ago

alexcroox commented 9 years ago

So I have the following in an attempt to allow Windows 8 to auto start a nodewebkit app that has to run in sysadmin mode (not without asking the user first and warning them of the risks of course...)

 var keyPath = 'HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System';

    regedit.list(keyPath, function(err, result) {
        console.log('Registry results', result);
        console.log('Registry errors', err);

        if(!err) {

            var keys = result[keyPath];

            if(typeof keys.values.EnableLUA !== "undefined") {

                console.log('Found LUA!', keys.values.EnableLUA.value);

                regedit.putValue({
                    keyPath: {
                        'EnableLUA': {
                            value: 1,
                            type: 'REG_DWORD'
                        }
                    }
                }, function(error) {
                    console.log('Updating registry', error);
                });

            } else {
                console.log('Failed to find policy system');
            }
        } else {
            console.log('Failed to find any registry values');
        }
    });

And the putValue() errors out with code: 25122 message: "unsupported hive"

I know the path is correct because it correctly reads the value of it before it tries to modify it.

alexcroox commented 9 years ago

Ah my fault, putValue has to have a string for the path (even though keyPath in my example is a string).

regedit.putValue({
                    'HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System': {

worked for me

mantasmarcinkus commented 7 years ago

For clarification if anyone gets this error it is because you tried to set key of a JSON object with a variable

var registryKey = 'HKCU\\SOFTWARE\\myApp';
regedit.putValue({ registryKey: { ... });

which would generate JSON object:

{ registryKey: { .... } }

if you want to have your registry key to get value for registry key from a config of some sort, do this (ES6):

var registryKey = 'HKCU\\SOFTWARE\\myApp';
const registryValue = {[registryKey]: {
        key: {
          value: 1,
          type: 'REG_DWORD',
        },
      }};

regedit.putValue(registryValue);