common/readCmd.js
var exec = require("child_process").exec;
const iconv = require('iconv-lite');
module.exports = function myTest(path,callback) {
return new Promise(function(resolve, reject) {
var cmd = path
exec(cmd,{
encoding: 'buffer'
}, function(err, stdout, stderr) {
if (err) {
console.log(err);
return callback(1,err,null)
} else if (stderr.lenght > 0) {
reject(new Error(stderr.toString()))
return callback(1,stderr.toString(),null);
} else {
var data = iconv.decode(stdout, 'cp936')
console.log('stdout1', iconv.decode(stdout, 'cp936'));
return callback(0,null,data)
}
});
});
};
validatte/registerConfir.js
//安装软件列表路径:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Curre
const myTest = require('../common/readCmd');
const registerPath = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyCo';
// 添加信息
const opertionAdd = 'echo y| reg add ';//默认确认
const operAddInfo = ' /v data2 /t reg_binary /d fe3499';
//查询信息
const opertionQuery = 'reg query '
const operQueryInfo = ' /v data1'
function operRegister(registerPath,opertionsAdd,operInfo){
const completePath = opertionsAdd+registerPath+operInfo;
myTest(`${completePath}`,function(code,err,data){
if(code == 1){
console.log(err);
}else{
console.log(data);
}
})
}
operRegister(registerPath,opertionAdd,operAddInfo);
// operRegister(registerPath,opertionQuery,operQueryInfo);