搜索关键字:
1.electron应用自启动,添加、修改、删除注册列表
2.nodejs添加、修改注册自启动注册列表
3.regedit.deleteKey 删除注册列表
4.regedit 添加、删除注册列表
5.npm regedit 添加注册列表
6.nodejs添加、修改、删除注册列表
/**
* @file 添加、删除注册列表的key值
*/
// eslint-disable-next-line camelcase
const child_process = require('child_process');
// 注意:`HKEY_CURRENT_USER`可以简写为`HKCU`,在网上看到的`HKCU`也就是`HKEY_CURRENT_USER`的意思
// 默认的自启动注册列表地址
const keyPath = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\';
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);
}
});
}
// deleteKey(keyPath, 'electron.app.DuGuanjiaTray')
// .then(() => console.log('deleteKey ok '))
// .catch((err) => console.log('deleteKey error', err));
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, 'mytest', 'hello22.exe')
// .then(() => console.log('addKey ok '))
// .catch((err) => console.log('addKey error', err));
// deleteKey(keyPath, 'mytest')
// .then(() => console.log('deleteKey ok '))
// .catch((err) => console.log('deleteKey error', err));
参考 编写注册表reg文件及批处理操作注册表:https://blog.csdn.net/tp7309/article/details/53449792