const child_process = require('child_process');//引入模块
const keyPath = 'HKEY_CURRENT_USER\\Software\\equipmentcode';//选择要修改或者保存或者删除的路径(操作路径)
function addKey(keyPath, name, value) {
return new Promise((resolve, reject) => {
try {
// eslint-disable-next-line max-len
// reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v electron.app.Electron /t REG_SZ /d hello.exe /f
// reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v electron.app.Electron /f
const result = child_process.exec(`reg add ${keyPath} /v ${name} /t REG_SZ /d ${value} /f`);
resolve(result);
} catch (error) {
reject(error);
}
});
}
addKey(keyPath,'devNum','123454643543453')//调用,测试成功
function deleteKey(keyPath, value) {
return new Promise((resolve, reject) => {
try {
// reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v electron.app.Electron /f
const result = child_process.exec(`reg delete ${keyPath} /v ${value} /f`);
resolve(result);
} catch (error) {
reject(error);
}
});
}
//查
child_process.exec(`REG QUERY ${keyPath} /v devNum`,function(error,stdout,stderr){
console.log('stdout:'+stdout);
console.log('stderr:'+stderr);
if(error != null){
console.log('exec error:'+error);
}
});
nodejs 增删改查window注册表数据
于 2021-10-22 11:11:12 首次发布