You probably need to remove the trailing slash. If you use this, it will look for the default value for the key you specified, and if it does not find it, it will lead to an error.
Conversely, if you try to access the key as if it were a value without using a trailing slash, you will get the same error.
Some examples of key access attempts:
Fails:
var keyPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion"; var shell = new ActiveXObject("WScript.Shell"); var regValue = shell.RegRead(keyPath); WScript.Echo("Value: " + regValue);
Succeeds (but gives an empty result, since the default value is empty):
var keyPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\"; var shell = new ActiveXObject("WScript.Shell"); var regValue = shell.RegRead(keyPath); WScript.Echo("Value: " + regValue);
Some examples trying to access a value:
Exceeds ( Value: C:\Program Files output):
var keyPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ProgramFilesDir"; var shell = new ActiveXObject("WScript.Shell"); var regValue = shell.RegRead(keyPath); WScript.Echo("Value: " + regValue);
Fails (do not use trailing slash when accessing the value):
var keyPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ProgramFilesDir\\"; var shell = new ActiveXObject("WScript.Shell"); var regValue = shell.RegRead(keyPath); WScript.Echo("Value: " + regValue);
source share