①創(chuàng)建主鍵、創(chuàng)建各類型的鍵值。
②讀取鍵值并分析鍵值類型。
③枚舉主鍵及鍵值。
④判斷鍵或鍵值是否存在。
⑤查詢注冊(cè)表鍵的操作權(quán)限。
⑥監(jiān)視注冊(cè)表根鍵、主鍵、鍵值,當(dāng)發(fā)現(xiàn)變動(dòng)時(shí)提示。
復(fù)制代碼 代碼如下:
'''注冊(cè)表查詢/操作
On Error Resume Next
Const HKEY_CLASSES_ROOT = H80000000'''設(shè)置注冊(cè)表5大根鍵,HKCR-----------①
Const HKEY_CURRENT_USER = H80000001'''HKCU
Const HKEY_LOCAL_MACHINE = H80000002'''HKLM
Const HKEY_Users = H80000003'''HKU
Const HKEY_Current_Config = H80000005'''HKCC
Const REG_SZ = 1'''設(shè)置注冊(cè)表鍵值類型,字符串型---------------------------②
Const REG_EXPAND_SZ = 2'''擴(kuò)展字符串型
Const REG_BINARY = 3'''二進(jìn)制型
Const REG_DWORD = 4'''雙字節(jié)型
Const REG_MULTI_SZ = 7'''多字符串型
Const KEY_QUERY_VALUE = H0001'''查詢注冊(cè)表權(quán)限,查詢數(shù)值-----------------③
Const KEY_SET_VALUE = H0002'''設(shè)置數(shù)值
Const KEY_CREATE_SUB_KEY = H0004'''創(chuàng)建子項(xiàng)
Const DELETE = H00010000'''刪除項(xiàng)值
'''-----------------配置環(huán)境(路徑)----------------------------------------00
strComputer = "."
Set WshShell = WScript.CreateObject("WScript.Shell")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" strComputer "\root\default:StdRegProv")
strKeyRoot = HKEY_LOCAL_MACHINE
Regpath = "HKEY_LOCAL_MACHINE"
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Run"
WshSHell.popup "設(shè)置路徑【HKLM\Software\Microsoft\Windows\CurrentVersion\Run】成功"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----------------創(chuàng)建主鍵"REG_KEY_SZ"----------------------------------01
strKeyPathNew = "Software\Microsoft\Windows\CurrentVersion\Run\User_baomaboy\"'''注意因?yàn)槭切陆ㄖ麈I,要多加個(gè)“\”
oReg.CreateKey strKeyRoot, strKeyPathNew
WshSHell.popup "創(chuàng)建主鍵【HKLM\Software\Microsoft\Windows\CurrentVersion\Run\User_baomaboy\】成功"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----------------創(chuàng)建字符串值"REG_SZ"----------------------------------02
strValueName="1字符串名"
strValue="字符串值"
oReg.SetStringValue strKeyRoot, strKeyPath, strValueName, strValue
WshSHell.popup "創(chuàng)建字符串【HKLM\Software\Microsoft\Windows\CurrentVersion\Run\1字符串名】成功"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----------------創(chuàng)建雙字節(jié)值"REG_DWORD"--------------------------------
strValueName="2雙字節(jié)名"
strValue=1
oReg.SetDWORDValue strKeyRoot, strKeyPath, strValueName, strValue
WshSHell.popup "創(chuàng)建雙字節(jié)值【HKLM\Software\Microsoft\Windows\CurrentVersion\Run\2雙字節(jié)名】成功"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----------------創(chuàng)建多字符串"REG_MULTI_SZ"-----------------------------
strValueName="3多字符串名"
arrStringValues = Array("QQ25926183", "userbaomaboy","LLKJ", "玲瓏科技")
oReg.SetMultiStringValue strKeyRoot, strKeyPath, strValueName, arrStringValues
WshSHell.popup "創(chuàng)建多字符串【HKLM\Software\Microsoft\Windows\CurrentVersion\Run\3多字符串名】成功"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----------------創(chuàng)建擴(kuò)展字符串"REG_EXPAND_SZ"--------------------------
strValueName = "4擴(kuò)展字符串名"
strValue = "%PATHEXT%"
oReg.SetExpandedStringValue strKeyRoot, strKeyPath, strValueName, strValue
WshSHell.popup "創(chuàng)建擴(kuò)展字符串【HKLM\Software\Microsoft\Windows\CurrentVersion\Run\4擴(kuò)展字符串名】成功"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----------------創(chuàng)建二進(jìn)制值"REG_BINVRY_SZ"----------------------------
RegPathEr=Regpath"\Software\Microsoft\Windows\CurrentVersion\Run\5二進(jìn)制值"
WshSHell.RegWrite RegPathEr,1,"REG_BINARY"
WshSHell.popup "創(chuàng)建二進(jìn)制值【HKLM\Software\Microsoft\Windows\CurrentVersion\Run\5二進(jìn)制值】成功"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 讀取字符串值"REG_VALUE"-------------------------------
oReg.GetStringValue strKeyRoot, strKeyPath, "1字符串名", strRunCommand
WshSHell.popup "讀取字符串值:"vbcrlfvbcrlfstrRunCommandvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 讀取雙字節(jié)值"REG_DWORD"-------------------------------
oReg.GetDWORDValue strKeyRoot, strKeyPath, "2雙字節(jié)名", strRunCommand
WshSHell.popup "讀取雙字節(jié)值:"vbcrlfvbcrlfstrRunCommandvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 讀取多字符串值"REG_MULTI_SZ"--------------------------
oReg.GetMultiStringValue strKeyRoot, strKeyPath, "3多字符串名", arrValues
For Each strValue In arrValues
DuoString=DuoStringvbcrlfstrValue
Next
WshSHell.popup "讀取多字符串值:"vbcrlfvbcrlfDuoStringvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 讀取擴(kuò)展字符串"REG_EXPAND_SZ"-------------------------
oReg.GetExpandedStringValue strKeyRoot, strKeyPath, "4擴(kuò)展字符串名", strValue
WshSHell.popup "讀取擴(kuò)展字符串值:"vbcrlfvbcrlfstrValuevbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 讀取二進(jìn)制值"REG_BINVRY_SZ"----------------------------
oReg.GetBinaryValue strKeyRoot, strKeyPath, "5二進(jìn)制值", strValue
For i = lBound(strValue) to uBound(strValue)
ErString=ErStringstrValue(i)
Next
WshSHell.popup "讀取二進(jìn)制值:"vbcrlfvbcrlfErStringvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 枚舉主鍵"SUB_KEY"--------------------------------------
oReg.EnumKey strKeyRoot, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
ArrSubKeyStr=ArrSubKeyStrvbcrlfsubkey
Next
WshSHell.popup "枚舉主鍵:"vbcrlfvbcrlfArrSubKeyStrvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 枚舉鍵值和鍵值類型"KEY_Value_Types"--------------------
oReg.EnumValues strKeyRoot, strKeyPath, arrValueNames, arrValueTypes
For i=0 To UBound(arrValueNames)
If Len(arrValueNames(i)) > 0 Then
Select Case arrValueTypes(i)
Case REG_SZ ValueType=" >>>是:字符串值"
Case REG_EXPAND_SZ ValueType=" >>>是:擴(kuò)展字符串值"
Case REG_BINARY ValueType=" >>>是:二進(jìn)制值"
Case REG_DWORD ValueType=" >>>是:雙字節(jié)值"
Case REG_MULTI_SZ ValueType=" >>>是:多字符串值"
End Select
arrValueStr=arrValueStrvbcrlfarrValueNames(i)ValueType
End If
Next
WshSHell.popup "枚舉鍵值和類型:"vbcrlfvbcrlfarrValueStrvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 枚舉鍵值和鍵值內(nèi)容一"KEY_Value_Contenct"----------------
oReg.EnumValues strKeyRoot, strKeyPath, arrValueNames, arrValueTypes
For i=0 To UBound(arrValueNames)
If Len(arrValueNames(i)) > 0 Then
oReg.GetStringValue strKeyRoot,strKeyPath,arrValueNames(i),strValue'''適應(yīng)于字符串型
ValueStr=ValueStrvbcrlfarrValueNames(i)vbcrlfstrValue
end if
Next
WshSHell.popup "枚舉鍵值和內(nèi)容一:"vbcrlfvbcrlfValueStrvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 枚舉鍵值和鍵值內(nèi)容二"KEY_Value_Contenct"----------------
oReg.EnumValues strKeyRoot, strKeyPath, arrValueNames, arrValueTypes
i=0
For Each strValue in arrValueNames
If Len(strValue) > 0 Then
i=i+1
oReg.GetStringValue strKeyRoot,strKeyPath,strValue,strRunCommand'''適應(yīng)于字符串型
intLength = Len(strRunCommand)
if intLength > 35 then'''美化回顯,(可再加代碼判路徑是否包含斷漢字)
strRunCommand = Left(strRunCommand, 20)"……"Right(strRunCommand, 13)
end if
StrRoot= i".【"strValue"】"vbCRLF" "strRunCommand
ARoot=ARootvbCRLFStrRoot
End If
Next
WshSHell.popup "枚舉鍵值和內(nèi)容二:"vbcrlfvbcrlfARootvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 刪除鍵值"REG_VALUE"-------------------------------------
oReg.DeleteValue strKeyRoot, strKeyPath, "5二進(jìn)制值"
WshSHell.popup "刪除鍵值:"vbcrlfvbcrlfRegpath"\"strKeyPath"\5二進(jìn)制值"vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''----------------- 刪除主鍵"SUB_KEY"---------------------------------------
oReg.DeleteKey strKeyRoot, strKeyPathNew
WshSHell.popup "刪除主鍵:"vbcrlfvbcrlfRegpath"\"strKeyPathNewvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----------------判斷鍵值是否存在-----------------------------------------
strValue="""病毒"""
oReg.GetStringValue strKeyRoot,strKeyPath,strValue,strRunCommand
If IsNull(strRunCommand) Then
WshSHell.popup strValue"此注冊(cè)表鍵值不存在."vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
Else
WshSHell.popup strValue"注冊(cè)表中存在此鍵值."vbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
End If
'''----------------- 檢查注冊(cè)表訪問(wèn)權(quán)限"Check Up Extent Of Power"------------
oReg.CheckAccess strKeyRoot, strKeyPath, KEY_QUERY_VALUE, bHasAccessRight
If bHasAccessRight = True Then
aaa="可以查詢數(shù)值"
Else
aaa="不可查詢數(shù)值"
End If
oReg.CheckAccess strKeyRoot, strKeyPath, KEY_SET_VALUE, bHasAccessRight
If bHasAccessRight = True Then
bbb="可以設(shè)置數(shù)值"
Else
bbb="不可設(shè)置數(shù)值"
End If
oReg.CheckAccess strKeyRoot, strKeyPath, KEY_CREATE_SUB_KEY, bHasAccessRight
If bHasAccessRight = True Then
ccc="可以創(chuàng)建主鍵"
Else
ccc="不可創(chuàng)建主鍵"
End If
oReg.CheckAccess strKeyRoot, strKeyPath, DELETE, bHasAccessRight
If bHasAccessRight = True Then
ddd="可以刪除鍵值"
Else
ddd="不可刪除鍵值"
End If
WshSHell.popup "注冊(cè)表訪問(wèn)權(quán)限:"vbcrlfvbcrlfRegpath"\"strKeyPathvbcrlfvbcrlfaaavbcrlfbbbvbcrlfcccvbcrlfdddvbcrlfvbcrlfvbcrlfvbcrlfvbcrlf"5 秒鐘后本窗口將自動(dòng)關(guān)閉!", 5, "QQ:25926183", 0 + 64
'''-----恢復(fù)注冊(cè)表原樣--------
oReg.DeleteValue strKeyRoot, strKeyPath, "4擴(kuò)展字符串名"
oReg.DeleteValue strKeyRoot, strKeyPath, "3多字符串名"
oReg.DeleteValue strKeyRoot, strKeyPath, "2雙字節(jié)名"
oReg.DeleteValue strKeyRoot, strKeyPath, "1字符串名"
'''-----------------監(jiān)視注冊(cè)表鍵值"REG_KEY_SZ"-------------------------------
'''用以對(duì)注冊(cè)表中HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\1字符串名"分支下的所有更改內(nèi)容進(jìn)行監(jiān)視。
'Set wmiServices = GetObject("winmgmts:root/default")
'Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
'wmiServices.ExecNotificationQueryAsync wmiSink, _
'"SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND " _
'"KeyPath='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run' AND ValueName='1字符串名'"
'WScript.Echo "開始監(jiān)視注冊(cè)表HKLM_Run主鍵鍵值的值的變化......" vbCrLf
'While(1)
'WScript.Sleep 1000
'Wend
'Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
'WScript.Echo ".........注冊(cè)表改變......" vbCrLf _
'"----------監(jiān)視注冊(cè)表鍵值的值變化-----------" vbCrLf _
'wmiObject.GetObjectText_()
'WScript.Quit(0)'''用作發(fā)現(xiàn)修改則提示后退出
'End Sub
'''-----------------監(jiān)視注冊(cè)表主鍵"REG_SubKey_SZ"-----------------------------
'''監(jiān)視注冊(cè)表,以發(fā)現(xiàn)對(duì) HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 的任何更改。
'Set wmiServices = GetObject("winmgmts:root/default")
'Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
'wmiServices.ExecNotificationQueryAsync wmiSink, _
'"SELECT * FROM RegistryKeyChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND " _
'"KeyPath='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run'"
'WScript.Echo "開始監(jiān)視注冊(cè)表HKLM_Run主鍵的鍵值變化......" vbCrLf
'While(1)
'WScript.Sleep 1000
'Wend
'Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
'WScript.Echo ".........注冊(cè)表改變......" vbCrLf _
'"----------監(jiān)視注冊(cè)表主鍵鍵值變化-----------" vbCrLf _
'wmiObject.GetObjectText_()
'WScript.Quit(0)'''用作發(fā)現(xiàn)修改則提示后退出
'End Sub
'''-----------------監(jiān)視注冊(cè)表根鍵"REG_RootKey_SZ"----------------------------
'''監(jiān)視注冊(cè)表,以發(fā)現(xiàn)對(duì) HKLM 的任何更改。
Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
wmiServices.ExecNotificationQueryAsync wmiSink, _
"SELECT * FROM RegistryTreeChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND RootPath=''"
WScript.Echo "開始監(jiān)視注冊(cè)表HKLM根鍵的所有變化......" vbCrLf
While(1)
WScript.Sleep 1000
Wend
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
WScript.Echo ".........注冊(cè)表改變......" vbCrLf _
"----------監(jiān)視注冊(cè)表根鍵所有變化-----------" vbCrLf _
wmiObject.GetObjectText_()
WScript.Quit(0)'''用作發(fā)現(xiàn)修改則提示后退出
End Sub