日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

regedit或child_process添加注册表

發布時間:2024/9/27 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 regedit或child_process添加注册表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用regedit包添加注冊表,regedit是對node的子進程模塊進行了封裝,使得我們不用去寫shell腳本或者window命令之類的
安裝
npm install --save regedit
使用,注意這里我是把作者的vbs目錄拷貝到我的項目里了,要不然無法使用,另外是無法往HKEY_CLASSES_ROOT添加的(管理員可以,如果有人知道怎么可以不用管理員身份也可以添加的,請教下我0.0),我 目前是在HKEY_CURRENT_USER添加的,因為這個是允許當前用戶的
var regedit = require('regedit');//添加到注冊表的keyvar regeditList = ['HKCU\\Software\\education', 'HKCU\\Software\\education\\DefaultIcon', 'HKCU\\Software\\education\\shell', 'HKCU\\Software\\education\\shell\\open', 'HKCU\\Software\\education\\shell\\open\\command'];//值的類型var type = ['REG_SZ', 'REG_DEFAULT'];//安裝項目的路徑var execPath = process.execPath;//存放.wsf文件的目錄,我把它vbs的目錄拷貝到我的項目中regedit.setExternalVBSLocation('./src/common/vbs');//首先添加我們需要創建的keyregedit.createKey(regeditList, function(err) {console.log(err);})//往不同的key中添加值和類型,使用了es6語法添加對象的keyvar valuesToPut = {[regeditList[0]]: {[type[1]]: {value: 'education Protocol',type: type[1]},'URL Protocol': {value: '1',type: type[0]}},[regeditList[1]]: {[type[1]]:{value: execPath,type: type[1]}},[regeditList[2]]: {[type[1]]:{value: '1',type: type[1]}},[regeditList[3]]: {[type[1]]:{value: '1',type: type[1]}},[regeditList[4]]: {[type[1]]:{value: execPath,type: type[1]}}}//添加自定義的數據到注冊表regedit.putValue(valuesToPut, function(err) {console.log(err);})//查詢注冊列表regedit.list(regeditList[0], function(err, result) {console.log(err);console.log(result);})
child_process添加注冊表
注意命令的寫法,小心語法錯誤,如果需要看添加注冊表的用法可以在cmd上輸入REG /?,然后輸入REG ADD /?可以看到添加注冊表的命令,自己可以先在cmd上進行寫入,成功后再到程序上編寫,同樣的會有權限的問題出現
var cp = require('child_process');var decoder = new TextDecoder('gbk');//使用這個也沒有解決亂碼問題var iconv = require('iconv-lite');var encoding = 'cp936';var binaryEncoding = 'binary';cp.exec('REG ADD HKEY_CLASSES_ROOT\\education /ve /t REG_SZ /d "education Protocol" /f',{ encoding: binaryEncoding },function(error,stdout,stderr) {//有些亂碼可以顯示出來,有些還是亂碼,也沒找到完全能解決亂碼問題,參考博客:https://ask.csdn.net/questions/167560console.log(iconv.decode(new Buffer(stdout, binaryEncoding), encoding), iconv.decode(new Buffer(stderr, binaryEncoding), encoding));});cp.exec('REG ADD HKEY_CLASSES_ROOT\\education /v "URL Protocol" /t REG_SZ /d "" /f',function(error,stdout,stderr) {});cp.exec('REG ADD HKEY_CLASSES_ROOT\\education\\DefaultIcon /ve /t REG_SZ /d "C:\\Program Files\\fwsd\\education.exe" /f',function(error,stdout,stderr) {});cp.exec('REG ADD HKEY_CLASSES_ROOT\\education\\shell /ve /t REG_SZ /d "" /f',function(error,stdout,stderr) {cp.exec('REG ADD HKEY_CLASSES_ROOT\\education\\shell\\open /ve /t REG_SZ /d "" /f', function(error, stdout, stderr) { cp.exec('REG ADD HKEY_CLASSES_ROOT\\education\\shell\\open\\command /t REG_SZ /d "C:\\Program Files\\fwsd\\education.exe" /f', function(error, stdout, stderr) { }) })});
我想實現的功能是點擊a標簽打開程序,如果是在HKEY_CLASSES_ROOT里注冊的是可以打開的,在HKEY_CURRENT_USER注冊,我目前不知道如何操作,如果有大神知道的,請指點下!

總結

以上是生活随笔為你收集整理的regedit或child_process添加注册表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。