fresc81 / node-winreg Goto Github PK
View Code? Open in Web Editor NEWnode module that provides access to the Windows Registry through the REG commandline tool
node module that provides access to the Windows Registry through the REG commandline tool
The path getter has a bug in it
instead of (host):
this.defineGetter('path', function () { return (_host.length == 0 ? '' : '\\' + host + '\') + _hive + _key; });
it should be (_host)
this.defineGetter('path', function () { return (_host.length == 0 ? '' : '\\' + _host + '\') + _hive + _key; });
First of all, thank you for this useful module.
I am currently using it and I would like to stub some Registry instance methods with sinonjs in my tests.
Unfortunatly I can't do it as the Registry's prototype is frozen.
Would you consider unfrozing ? And if not, what approach would you suggest to stub Registry methods ?
I am trying to Query Windows Install Date on a Windows 8.1 system
HKLM
\SOFTWARE\Microsoft\Windows NT\CurrentVersion
InstallDate
and for some reason it is coming up as 0. I am not sure if this is an access/permissions issue on Windows 8.1 or a bug here.
I tested on XP (with your header patch) and Windows 7 pro and it works fine.
I do know that if I query this key via a js file and Cscript it does show correctly.
var shell = new ActiveXObject("WScript.Shell");
var i = shell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate");
WScript.StdOut.Write(i);
function getPath(callback){
var Winreg = require('winreg');
var regKey = new Winreg({
hive: Winreg.HKCU,
key: '\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
});
var myPath = regKey.values(function(err, items) {
for (var i in items) {
if (items[i].name === 'Personal') {
callback(items[i].value);
}
}
});
}
check this out
if the Personal value is in chinese, the value in the callback will be messy code.
does anybody know how to resolve this?
I am trying to write some keys to HKCR - this does not seem to work:
ERROR: Access is denied.
at mkErrorMsg (app\node_modules\winreg\lib\registry.js:117:12)
at ChildProcess.<anonymous> (app\node_modules\winreg\lib\registry.js:735:10)
Is this expected? Should access to HKCR be restricted for an application NOT running in admin mode (even if the user is an admin)?
I expected to be able to read the docs online rather than having to npm install them on my local machine, but the link in the readme.me points to http://fresc81.github.io/node-winreg/ which is literally that same readme, but with different CSS =)
Is the actual documentation somewhere online so people can just look things up instead of having to run more npm commands just to see how to use the API?
winreg
can still access reg.exe
even when process.platform
is not win32
.
WSL runtime can be tested with package like is-wsl
.
It works with "node launcher". However if I use "pkg" to compile this node program and run it, Then..
{ ProcessUncleanExitError: QUERY command exited with code 1:
ERROR: The system was unable to find the specified registry key or value.
at mkErrorMsg (D:\snapshot\Maple\node_modules\winreg\lib\registry.js:111:12)
at ChildProcess. (D:\snapshot\Maple\node_modules\winreg\lib\registry.js:632:10)
at ChildProcess.emit (events.js:159:13)
at maybeClose (internal/child_process.js:943:16)
at Socket.stream.socket.on (internal/child_process.js:363:11)
at Socket.emit (events.js:159:13)
at Pipe._handle.close [as _onclose] (net.js:558:12) name: [Getter], message: [Getter], code: [Getter] }
TypeError: Cannot read property 'value' of null
at D:\snapshot\Maple\launcher.js:0:0
at ChildProcess. (D:\snapshot\Maple\node_modules\winreg\lib\registry.js:632:7)
at ChildProcess.emit (events.js:159:13)
at maybeClose (internal/child_process.js:943:16)
at Socket.stream.socket.on (internal/child_process.js:363:11)
at Socket.emit (events.js:159:13)
at Pipe._handle.close [as _onclose] (net.js:558:12)
Please check it, Thanks!
In the case that the key already exists, you get hit with a prompt that you can do nothing about.
So we should use the /f
parameter in this case as well (it's already been added to the other methods).
When registry editing is prohibited, then keyExists
return false.
keyExists
should throw same ProcessUncleanExitError
like other functions:
C: ADD command exited with code 1:
ERROR: Registry editing has been disabled by your administrator.
keyExists
should check for error message "The system was unable to find the specified registry key or value." too. Since reg.exe
fails with error code 1 for various reasons. Note: seems to me, that reg.exe
does not localize messages (while regedit.exe does localize).
See https://www.online-tech-tips.com/windows-xp/registry-disabled-by-administrator/ :
Is this possible?
I am setting REG_SZ
with "C:\Users\vilicvane\AppData\Roaming\npm\node_modules\desktop-matters\node_modules\startup-run\bin\hideexec.exe" "C:\Program Files\nodejs\node.exe" "C:\Users\vilicvane\AppData\Roaming\npm\node_modules\desktop-matters\node_modules\startup-run\bld\daemon\main.js" "{\"name\":\"desktop-matters\",\"command\":\"C:\\Program Files\\nodejs\\node.exe\",\"args\":[\"C:\\Users\\vilicvane\\AppData\\Roaming\\npm\\node_modules\\desktop-matters\\bld\\cli\\main.js\",\"--startup\"],\"cwd\":\"C:\\Users\\vilicvane\",\"env\":{},\"log\":\"C:\\Users\\vilicvane\\desktop-matters.log\",\"respawn\":1000}"
, and with 1.2.5 it no longer works.
Possibly due to the shell: false
update.
I'm trying to read the (Default) REG_SZ value from some keys, but it seems they are ignored? Is this intentional or am I missing something?
when querying for the subkeys of a key
in
for (var i = 0, l = lines.length; i < l; i++)
the first line from the reg query contains only "\r"
to avoid returning this you apparently "skip" it with the code
if (line.length > 0) {
log(line);
if (lineNumber != 0) {
items.push(line);
}
++lineNumber;
}
but for lines with only "\r", trim removes them and so the line.length is 0 and lineNumber is not incremented and so the first line with something other than spaces or \r is skipped.
lines[0].length -> 1
lines[0].trim().length ->0
Have not done it yet but it would seem that just removing the if (lineNumber != 0) and simply pushing the line would work but am not sure it that is the only reason this was placed here.
In any case I am having other issues but found this along the way and easier to report now so perhaps its the other issue which I have not found yet
Windows creates a value for every key called "(Default)" and Im unable to change it.
If I create a key
var rootKey = new winreg({
hive: winreg.HKCR,
key: '\\Test'
});
At this point the value "(Default)" as been created by windows automatically set to nothing.
Using the code below I try and set the value to "Some value"
rootKey.set("(Default)", winreg.REG_SZ, "Some value", function() {});
This code just ends up creating a new one called "(Default)" rather then changing the value.
Export ProcessUncleanExitError
so as minifiers do not change it's name and is possible to check the error by instanceof
.
ERROR in ./~/winreg/lib/registry.js
Module not found: Error: Can't resolve 'child_process' in 'c:\Project\machine\node_modules\winreg\lib'
on a cleaned project in angular 2.
var Registry = require('winreg');
Hi all,
Genymotion is a very popular Android emulator, which is preferred by developers due to its speed and ease to use. The issue is that it contains an "reg.exe". If the user manually adds its directories to the PATH before the Windows directory, node-winreg tries to use it.
The fix would be to always use %windir%\system32\reg.exe
Hi,
I get the following error when I run this library in electron(after I pack it into a .exe via electron-builder)
{ Error\n at mkErrorMsg (C:\\Users\\denimuser\\AppData\\Local\\Programs\\my-events\\resources\\app\\webpack:\\src\\uninstaller\\registry.js:111:12)\n at ChildProcess.<anonymous> (C:\\Users\\denimuser\\AppData\\Local\\Programs\\my-events\\resources\\app\\webpack:\\src\\uninstaller\\registry.js:541:10)\n at emitTwo (events.js:106:13)\n at ChildProcess.emit (events.js:194:7)\n at maybeClose (internal/child_process.js:899:16)\n at Socket.<anonymous> (internal/child_process.js:342:11)\n at emitOne (events.js:96:13)\n at Socket.emit (events.js:191:7)\n at Pipe._handle.close [as _onclose] (net.js:510:12) name: [Getter], message: [Getter], code: [Getter] }","timestamp":"2018-03-05 04:03:38"}
Hello
we get the following ERROR if a space is in the key or value of the set method
ProcessUncleanExitError: ADD command exited with code 1:
FEHLER: Ungültige Syntax.
Geben Sie "REG ADD /?" ein, um die Syntax anzuzeigen.
method call:
key.set("URL Protocol", WinReg.REG_SZ, '', (err)=> {
});
or
key2.set(WinReg.DEFAULT_VALUE, WinReg.REG_SZ, '"ExeFileFolder\ExeFileName" "--deeplink=%1"', (err)=> {
});
Info:
it works on CMD
`
C:>reg add HKCU\SOFTWARE\Classes\testKB /v "URL Protocol" /t REG_SZ /d "" /f
Der Vorgang wurde erfolgreich beendet.
C:>reg query HKCU\SOFTWARE\Classes\testKB /v "URL Protocol"
HKEY_CURRENT_USER\SOFTWARE\Classes\testKB
URL Protocol REG_SZ
`
update 1:
key.set("\"URL Protocol\"",..
results in exteme cpu usage and forever running thread
update 2:
version 1.2.4 works!!! (with pure NodeJS and in my electron v18 app)
version 1.2.5 also NOT ok if I took the set method from 1.2.4 (very strange)
so I do not close the issue because 1.2.5 should also work
Prerequisite: A key exists in the registry with value " " (space).
Actual behaviour:
result in callback is null:
regKey.get(key, (error, result) => {
// result is null
})
Expected behaviour:
result.value in callback is " ".
I found that your regex pattern is too restrictive (ITEM_PATTERN). Register name can have - and \ as well.
You can use
ITEM_PATTERN = /^([a-zA-Z0-9_\s-]+)\s(REG_SZ|REG_MULTI_SZ|REG_EXPAND_SZ|REG_DWORD|REG_QWORD|REG_BINARY|REG_NONE)\s+([^\s].*)$/
Might be a duplicate of #16 but for the sake of consistency i'll add it here as well.
I'm running as admin (the title of the window says Administrator: Command Prompt).
I can't view and/or edit the key with the Regedit either, even when running as admin.
I can't even change the permissions of the key with Regedit.
My guess is our system admins have locked it down in a way I can't override but that's just a guess so far.
I am using Node 5.3.0, NPM 3.3.12... (also tried in Node 4.2.3, NPM 2.14.7)
The following simple functional test works in 0.0.13, but fails with the error shown below in 0.0.14:
> var winreg = require('winreg');
undefined
> var regKey = winreg({hive:winreg.HKLM});
undefined
> regKey.keys(function (err, data) {console.log(data);});
TypeError: Cannot read property 'on' of null
at captureOutput (C:\Users\Shawn\winreg-test\node_modules\winreg\lib\registry.js:50:15)
at Registry.keys (C:\Users\Shawn\winreg-test\node_modules\winreg\lib\registry.js:304:16)
at repl:1:8
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
> .exit
@fresc81, I noticed that there are some pull requests, one of which is my own, that have been hanging around for a long time. If you are busy or no longer have interest in the project, any chance you can assign another contributor to the project? I'm willing to do it myself if needed.
This is because you use the /va
argument.
/va delete all values under this key.
Erase
is a good name for this operation, so I'd suggest updating the docs that it doesn't actually delete the key, and make another function that deletes the key and all descendant keys.
Just leave out the /va
argument for the Registry.delete() function. Eg: https://github.com/Zren/atom-windows-context-menu/blob/master/lib/registry.js#L506
Hi,
I am trying to set a Registry key/value in windows 7 (32 Bit). However, I keep getting the error:
[Error: process exited with code 1]
The code I am using is:
var Winreg = require('winreg');
regKey = new Winreg({
hive: Winreg.HKLM,
key: '\System\CurrentControlSet\Control\Session Manager\Environment'
});
regKey.set('SOME_KEY', Winreg.REG_SZ, '1', function (err) {
console.log(err);
});
What am I doing wrong?
Other methods like regKey.values() and regKey.get() work fine.
Any help would be great. Thanks :)
I'm trying to write a string value to start up key in HKLM but nothing is written and no errors are shown. Can anyone shine some light on what is happening??? I can do the same to current user HKCU but not the HKLM. Do not know if there is some sort of privileges I need to set or something.
Here is code for HKCU that works:
var Winreg = require('winreg')
, regKey = new Winreg({
hive: Winreg.HKCU, // HKEY_CURRENT_USER
key: '\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' // key containing autostart programs
})
Here is for HKLM that does not work
var Winreg = require('winreg')
, regKey = new Winreg({
hive: Winreg.HKLM, // HKEY_LOCAL_MACHINE
key: '\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' // key containing autostart programs
})
My string value:
regKey.set('RunMyProg', 'REG_SZ', 'Some command ..... here', function () {});
Any help would be much appreciated.
Thanks in advance.
Hi,
how to specify the default value on registry.get method using Registry.DEFAULT_VALUE?
Found in documentation for get method this , but not sure how to use it:
the value name, use Registry.DEFAULT_VALUE or an empty string for the default value
For example:
ServerRegKey.get('serverName', function (err, item) {
if(!err){
serverName = item.value;
} else {
console.log('---bin.js--55-- Error on getting server name', err);
}
})
Thanks!
After the 0.0.14 update today, a portion of code we were using to get the path of ms build no longer returns any values. The version specified in our packages.json is version 0.0.11, but there are no other releases available besides 0.0.14.
The snippet that's broken is pasted below:
var regKey = new Winreg({
hive: Winreg.HKLM,
key: "\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\4.0"
});
var pathValueName = gulp.isOSWin64() ? "MsBuildToolsPath" : "MsBuildToolsPath32";
//BROKEN LINE
regKey.get(pathValueName, function (err, item) {
if (err) {
deferred.reject(err);
}
var msBuildPath = item.value + 'MSBuild.exe';
Is there a place which has previous releases of winreg hosted? Or are we using the function incorrectly?
Is there a way to force accessing a specific registry view?
The REG.EXE command allows the following switches:
/reg:32 Specifies the key should be accessed using the 32-bit registry view.
/reg:64 Specifies the key should be accessed using the 64-bit registry view.
I'm specifically trying to access a key under HKLM\Software\Wow6432Node\...
No license file associated with this project - can you use MIT License? That would help others using/modifying this.
running node in a bash shell, for example, function getRegExePath() (in registry.js) fails calling path.join because process.env.windir is undefined. As a workaround, i added the following at the top of my main code:
// hack to allow reg to run in other shells
process.env.windir ||= "C:\\Windows"
I am finding this library quite hard to use with all the asynchronous callbacks. I am trying to compile a list of installed software and patches which requires looping through multiple keys and stepping down into each one to retrieve multiple subkeys. Therefore I need some way to guarantee I can append all this data to my lists after all callbacks are completed. So, is there anyway I can do this? Does this library perhaps support promises?
I cannot read this key with winreg:
var VS7 = new WinReg({
hive: WinReg.HKLM,
key: '\\' + path.join('SOFTWARE', wowNode, 'Microsoft', 'VisualStudio', 'SxS', 'VS7')
});
VS7.get('12.0', callback); // result is null
All of the other values in that key work fine just not that one. I'm assuming it has to do with the fact that it's a number? Or has a .
perhaps? I don't know what's going wrong, there is no error its just null.
I have a eletron app which used this lib to get/set ProxyServer on windows and everything works fine when try get/set the reg value.
But the strange thing is that when my program runs for a while it always crashes, stacktrace as below:
RangeError: Invalid string length
at Socket.<anonymous> (d:\Workspace\dssToolbox\node_modules\winreg\lib\registry.js:98:34)
at Socket.emit (d:\Workspace\dssToolbox\lib\events.js:526:35)
at addChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:324:12)
at readableAddChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:297:9)
at Socket.push (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:234:10)
at Pipe.onStreamRead (d:\Workspace\dssToolbox\lib\internal\stream_base_commons.js:190:23)
at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {stack: 'RangeError: Invalid string length
at Sock…Trampoline (node:internal/async_hooks:130:17)', message: 'Invalid string length'}
I located the code in registry.js,:
function captureOutput(child) {
// Use a mutable data structure so we can append as we get new data and have
// the calling context see the new data
var output = {'stdout': '', 'stderr': ''};
child.stdout.on('data', function(data) { output["stdout"] += data.toString(); });
child.stderr.on('data', function(data) { output["stderr"] += data.toString(); });
return output;
}
And add some log:
function captureOutput(child) {
// Use a mutable data structure so we can append as we get new data and have
// the calling context see the new data
var output = {'stdout': '', 'stderr': ''};
child.stdout.on('data', function(data) {
try {
output["stdout"] += data.toString();
} catch (error) {
console.log(error);
console.log(output["stdout"].length);
console.log(data.toString());
throw error;
}
});
child.stderr.on('data', function(data) { output["stderr"] += data.toString(); });
return output;
}
After crash, i got:
RangeError: Invalid string length
at Socket.<anonymous> (d:\Workspace\dssToolbox\node_modules\winreg\lib\registry.js:98:34)
at Socket.emit (d:\Workspace\dssToolbox\lib\events.js:526:35)
at addChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:324:12)
at readableAddChunk (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:297:9)
at Socket.push (d:\Workspace\dssToolbox\lib\internal\streams\readable.js:234:10)
at Pipe.onStreamRead (d:\Workspace\dssToolbox\lib\internal\stream_base_commons.js:190:23)
at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {stack: 'RangeError: Invalid string length
at Sock…Trampoline (node:internal/async_hooks:130:17)', message: 'Invalid string length'}
registry.js:100
536870814
registry.js:101
ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)? ֵ ProxyServer �Ѵ��ڣ�Ҫ������(Yes/No)?
It seems that the length of the output.stdout
keeps increasing until it exceeds the upper limit.
How should I solve it (or just try-catch it)?
Any help will be very appreciated.
Hey there! Great package. Have you thought about releasing version 1.0.0?
See: https://docs.npmjs.com/getting-started/semantic-versioning
If a project is going to be shared with others, it should start at 1.0.0, though some projects on npm don't follow this rule.
It's easier to automatically inherit bugfixes and improvements for free if we can just depend on ^1.0.0
of winreg
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.