provides access to the windows registry through the REG tool, with additional unicode support.
npm install winreg-utf8shell
npm install winreg-utf8
`
Example Usage ##
Let's start with an example. The code below lists the autostart programs of the current user.
`javascript
var Registry = require('winreg')
, regKey = new Registry({ // new operator is optional
hive: Registry.HKCU, // open registry hive HKEY_CURRENT_USER
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' // key containing autostart programs
})
// list autostart programs
regKey.values(function (err, items / array of RegistryItem /) {
if (err)
console.log('ERROR: '+err);
else
for (var i=0; i console.log('ITEM: '+items[i].name+'\t'+items[i].type+'\t'+items[i].value);
});
`
Troubleshooting ##
$3
Since Windows Vista access to certain Registry Hives (HKEY_LOCAL_MACHINE or short HKLM for example) is restricted to processes that run in a security elevated context even if the user that starts the process is an admin. You can start a console within that context by right clicking the console shortcut and selecting the item with the shield icon called "Run as administrator" from the context menu.
Under some rare circumstances access to Registry Hives or particular keys may also be blocked by some antivirus programs or the Windows Group Policy Editor (google for gpedit.msc).
You can also use the regedit.exe tool shipped with Windows to check if you actually have access.
$3
The Microsoft Windows console isn't capable of handling UTF-8 encoded text unless you set it up properly. If you see weird question marks for certain characters, it's probhably a problem with the encoding.
By default the console is setup to use an encoding that suits the language of the Windows operating system installation. Windows uses codepages to specify encodings for the console. The codepage is a unique number which is assigned to each encoding.
If you want to query the currently selected codepage you can type the command chcp (w/o parameters). To set a new codepage (UTF-8 for this example) you pass the codepage number as the only argument to chcp. The codepage value for UTF-8 is 65001.
You can easily do this from within your nodejs script by using the child_process.execSync(...) function like the following example shows.
`javascript
var execSync = require('child_process').execSync;
console.log(execSync('chcp').toString());
console.log(execSync('chcp 65001').toString());
`
An even better approach would be to extract and store the value returned by a call to chcp prior setting the console to UTF-8 and resetting the codepage after your script is done.
In case where a child process doesn't inherit the changed code page, e.g. an Electron application, you can simply create the Registry object with utf8: true option, then chcp 65001 is executed each time before it operates the Registry.
`javascript
regKey = new Registry({
hive: Registry.HKCU, // open registry hive HKEY_CURRENT_USER
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' // key containing autostart programs
utf8: true // decode value using utf-8
});
// ...
``