国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

vbs 讀寫注冊表之系統(tǒng)啟動項添加與刪除

2020-07-26 11:19:46
字體:
供稿:網(wǎng)友

核心vbs代碼

'變量定義Dim writeName,writeValue,fileName,regLoaction,regApp'創(chuàng)建注冊表編輯器對象Set regApp=WScript.CreateObject("WScript.Shell")'配置文件名fileName="FullScan.txt"'輸入鍵名writeName="xiaoqiang"'輸入鍵值writeValue="test"'************************腳本運行區(qū)間********************************'根據(jù)配置文件獲取注冊表路徑數(shù)組regLoaction=getRegPathArray(getFileText(fileName))'寫入注冊表write regLoaction,writeName,writeValue'讀取寫入的鍵值 生成并生成結(jié)果文件read regLoaction,writeName'************************函數(shù)定義********************************'讀注冊表Function read(regLoaction,writeName) Dim returnStrArray(),j j=0 If writeName="" or writeValue="" then  msgbox "錯誤!!請輸入鍵名和鍵值" else  for i=0 to ubound(regLoaction) ReDim Preserve returnStrArray(j)    regPath=regLoaction(i)&"/"&writeName   returnStrArray(j)=regPath&"? "&regApp.RegRead(regPath)   j=j+1  Next End if writeResult returnStrArrayEnd Function'寫入注冊表Function write(regLoaction,writeName,writeValue) If writeName="" or writeValue="" then  msgbox "錯誤!!請輸入鍵名和鍵值" else  for i=0 to ubound(regLoaction) regApp.RegWrite regLoaction(i)&"/"&writeName,writeValue  Next End ifEnd Function'輸出結(jié)果文件sub writeResult(contentArray) Const ForReading = 1, ForWriting = 2 Dim fso,f,returnStrArray(),i Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("result.txt", 2,true) for i=0 to ubound(contentArray) f.writeline(contentArray(i)) Next f.close()End Sub'得到注冊表路徑數(shù)組Function getRegPathArray(sourceArray) Dim head,returnStrArray(),j j=0 for i=0 to ubound(sourceArray)  If sourceArray(i)="[HKEY_LOCAL_MACHINE]" then head="HKLM"  elseif sourceArray(i)="[HKEY_USERS]" then   head="HKEY_USERS/.DEFAULT"  elseif sourceArray(i)="[HKEY_CURRENT_USER]" then   head="HKCU"  elseif sourceArray(i)="[HKEY_CLASSES_ROOT]" then   head="HKCR"  elseif sourceArray(i)="[HKEY_CURRENT_CONFIG]" then   head="HKEY_CURRENT_CONFIG"  else   ReDim Preserve returnStrArray(j)   str=head&split(sourceArray(i),"=")(1)   returnStrArray(j)=str   j=j+1  End If Next getRegPathArray=returnStrArrayEnd Function'得到文件內(nèi)容存入數(shù)組Function getFileText(fileName) Const ForReading = 1, ForWriting = 2 Dim fso,f,returnStrArray(),i Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(fileName, 1) i=0 do while f.atendofstream<>true  ReDim Preserve returnStrArray(i)  returnStrArray(i)=f.readline()  i=i+1 loop f.close() getFileText=returnStrArrayEnd Function

//配置文件

FullScan.txt

[HKEY_LOCAL_MACHINE]1=/Software/Microsoft/Windows/CurrentVersion/Run2=/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/Run/3=/Software/Microsoft/Windows/CurrentVersion/RunOnce/4=/Software/Microsoft/Windows/CurrentVersion/RunServicesOnce/5=/Software/Microsoft/Windows/CurrentVersion/RunOnceEx6=/Software/Microsoft/Windows/CurrentVersion/Policies/System/Shell/7=/Software/Microsoft/Windows/CurrentVersion/ShellServiceObjectDelayLoad/8=/Software/Policies/Microsoft/Windows/System/Scripts/[HKEY_CURRENT_USER]1=/Software/Microsoft/Windows/CurrentVersion/Run2=/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/Run/3=/Software/Microsoft/Windows/CurrentVersion/RunOnce/4=/Software/Microsoft/Windows/CurrentVersion/RunServicesOnce/5=/Software/Microsoft/Windows/CurrentVersion/RunOnceEx6=/Software/Microsoft/Windows/CurrentVersion/Policies/System/Shell/7=/Software/Microsoft/Windows/CurrentVersion/ShellServiceObjectDelayLoad/8=/Software/Policies/Microsoft/Windows/System/Scripts/

運行后得到result.txt

HKLM/Software/Microsoft/Windows/CurrentVersion/Run/xiaoqiang? testHKLM/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/Run//xiaoqiang? testHKLM/Software/Microsoft/Windows/CurrentVersion/RunOnce//xiaoqiang? testHKLM/Software/Microsoft/Windows/CurrentVersion/RunServicesOnce//xiaoqiang? testHKLM/Software/Microsoft/Windows/CurrentVersion/RunOnceEx/xiaoqiang? testHKLM/Software/Microsoft/Windows/CurrentVersion/Policies/System/Shell//xiaoqiang? testHKLM/Software/Microsoft/Windows/CurrentVersion/ShellServiceObjectDelayLoad//xiaoqiang? testHKLM/Software/Policies/Microsoft/Windows/System/Scripts//xiaoqiang? testHKCU/Software/Microsoft/Windows/CurrentVersion/Run/xiaoqiang? testHKCU/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer/Run//xiaoqiang? testHKCU/Software/Microsoft/Windows/CurrentVersion/RunOnce//xiaoqiang? testHKCU/Software/Microsoft/Windows/CurrentVersion/RunServicesOnce//xiaoqiang? testHKCU/Software/Microsoft/Windows/CurrentVersion/RunOnceEx/xiaoqiang? testHKCU/Software/Microsoft/Windows/CurrentVersion/Policies/System/Shell//xiaoqiang? testHKCU/Software/Microsoft/Windows/CurrentVersion/ShellServiceObjectDelayLoad//xiaoqiang? testHKCU/Software/Policies/Microsoft/Windows/System/Scripts//xiaoqiang? test

注冊表中的值

以下是武林網(wǎng)小編補充

運行后就會發(fā)現(xiàn)在系統(tǒng)開始自動運行的一些啟動項加入了如上值,所以不建議普通用戶運行。

既然批量添加那么也可以批量刪除

將上面的vbs代碼中的

regApp.RegWrite regLoaction(i)&"/"&writeName,writeValue

替換為

regApp.RegDelete regLoaction(i)&"/"&writeName

發(fā)現(xiàn)直接運行不行,其實注冊表的刪除需要用管理員權(quán)限才可以。

怕有些新手不知道如何管理員權(quán)限運行vbs

其實右鍵cmd中看到 以管理員權(quán)限運行 打開 dos窗口,然后將vbs文件拖到這個dos窗口里面,回車運行即可

然后拖拉

回車后發(fā)現(xiàn),并沒有提示任何錯誤信息,從注冊表中看到,確定這個字段已經(jīng)沒了。完全解決。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 大方县| 苍山县| 曲阜市| 渝中区| 轮台县| 三明市| 潼南县| 元朗区| 藁城市| 正宁县| 临沭县| 岳池县| 察雅县| 喀什市| 宣威市| 宝山区| 武城县| 长岭县| 盘锦市| 班戈县| 保靖县| 高邮市| 保亭| 濮阳县| 余江县| 九江县| 壶关县| 农安县| 洛隆县| 临泽县| 扶风县| 玉溪市| 甘孜县| 阜新| 唐山市| 南平市| 濮阳县| 汉中市| 望都县| 孟津县| 郴州市|