Comparing version 0.0.7 to 0.1.0
@@ -9,3 +9,6 @@ var errors = {} | ||
//TODO: this is an error that is caused by trying to create a registry key in a place where I dont have permission | ||
errors[25123] = new Error('expected to have groups of 4 arguments for each value that is written to the registry') | ||
errors[25123].code = 25123 | ||
//TODO: this is an error that is caused by trying to create a registry key somewhere I dont have permissions to | ||
// where is the reference for these codes....??? | ||
@@ -12,0 +15,0 @@ errors[5] = new Error('access is denied') |
46
index.js
@@ -6,2 +6,3 @@ var util = require('util') | ||
var errors = require('./errors.js') | ||
var os = require('os') | ||
@@ -12,2 +13,27 @@ module.exports.list = function (keys, callback) { | ||
module.exports.arch = {} | ||
var arch = os.arch() === 'x64' ? '64' : '32' | ||
module.exports.getArch = function () { | ||
return arch | ||
} | ||
module.exports.arch.list = function(keys, callback) { | ||
if (arch === '64') { | ||
return module.exports.arch.list64(keys, callback) | ||
} else { | ||
return module.exports.arch.list32(keys, callback) | ||
} | ||
} | ||
module.exports.arch.list32 = function (keys, callback) { | ||
executeCommand(prepareCommand('regList.wsf', keys, '32'), callback) | ||
} | ||
module.exports.arch.list64 = function (keys, callback) { | ||
executeCommand(prepareCommand('regList.wsf', keys, '64'), callback) | ||
} | ||
module.exports.createKey = function (keys, callback) { | ||
@@ -23,3 +49,3 @@ executeCommand(prepareCommand('regCreateKey.wsf', keys), callback) | ||
var cmd = 'regPutValue.wsf ' | ||
var cmd = 'regPutValue.wsf *' | ||
@@ -76,2 +102,4 @@ for (var key in map) { | ||
debug(stdout, stderr) | ||
var result | ||
@@ -109,7 +137,11 @@ try { | ||
function prepareCommand(cmd, args) { | ||
function prepareCommand(cmd, args, architecture) { | ||
architecture = architecture || '*' | ||
cmd += ' ' + architecture | ||
if (typeof args === 'string') { | ||
return cmd += ' ' + wrapDoubleQuotes(args) | ||
} else if (util.isArray(args)) { | ||
return cmd += wrapItemsWithDoubleQuotes(args) | ||
return cmd += ' ' + wrapItemsWithDoubleQuotes(args) | ||
} else { | ||
@@ -124,3 +156,6 @@ return cmd | ||
for (var i = 0; i < arr.length; i++) { | ||
result += ' ' + wrapDoubleQuotes(arr[i]) | ||
if (i > 0) | ||
result += ' ' | ||
result += wrapDoubleQuotes(arr[i]) | ||
} | ||
@@ -131,2 +166,5 @@ | ||
/* | ||
* conditionally wrap items with double quotes if they aren't wrapped already | ||
*/ | ||
function wrapDoubleQuotes(item) { | ||
@@ -133,0 +171,0 @@ if (item[0] !== '"' && item[item.length - 1] !== '"') { |
{ | ||
"name": "regedit", | ||
"version": "0.0.7", | ||
"version": "0.1.0", | ||
"description": "Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -59,2 +59,11 @@ # regedit | ||
### regedit.arch.list32([String|Array], [Function]) | ||
same as list, only force a 32bit architecture on the registry | ||
### regedit.arch.list64([String|Array], [Function]) | ||
same as list, only force a 64bit architecture on the registry | ||
### regedit.arch.list([String|Array], [Function]) | ||
same as list, only force your system architecture on the registry (select automatically between list64 and list32) | ||
### regedit.createKey([String|Array], [Function]) | ||
@@ -61,0 +70,0 @@ Creates one or more keys in the registry |
@@ -27,2 +27,60 @@ var index = require('../index') | ||
// TODO need to find a better way to test the 32bit/64bit scenario | ||
it(target + ' 32bit', function (done) { | ||
index.arch.list32(target, function(err, result) { | ||
if (err) return done(err) | ||
result.should.have.property(target) | ||
var key = result[target] | ||
key.should.have.property('keys') | ||
key.should.have.property('values') | ||
key.keys.should.containEql('Policies') | ||
key.values.should.have.property('ProgramFilesDir') | ||
key.values.ProgramFilesDir.should.have.property('value', 'C:\\Program Files') | ||
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ') | ||
done() | ||
}) | ||
}) | ||
it(target + ' 64bit', function (done) { | ||
index.arch.list64(target, function(err, result) { | ||
if (err) return done(err) | ||
result.should.have.property(target) | ||
var key = result[target] | ||
key.should.have.property('keys') | ||
key.should.have.property('values') | ||
key.keys.should.containEql('Policies') | ||
key.values.should.have.property('ProgramFilesDir') | ||
key.values.ProgramFilesDir.should.have.property('value', 'C:\\Program Files') | ||
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ') | ||
done() | ||
}) | ||
}) | ||
it(target + ' arch auto pick', function (done) { | ||
index.arch.list(target, function(err, result) { | ||
if (err) return done(err) | ||
result.should.have.property(target) | ||
var key = result[target] | ||
key.should.have.property('keys') | ||
key.should.have.property('values') | ||
key.keys.should.containEql('Policies') | ||
key.values.should.have.property('ProgramFilesDir') | ||
key.values.ProgramFilesDir.should.have.property('value', 'C:\\Program Files') | ||
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ') | ||
done() | ||
}) | ||
}) | ||
it('can be applied to several independant keys at once', function (done) { | ||
@@ -29,0 +87,0 @@ index.list(['hklm', 'hkcu'], function (err, result) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
123390
22
1484
126