返回列表 发帖
回复 60# powerbat


    很感谢您,最后请求了

另外:
Hive = "HKEY_LOCAL_MACHINE"
KeyPath = "Software\333"
ValueName = "444"
shuzhi =29
gaiwei =20
这样的话
    if CStr(Value)="29" then
        ws.Popup "注册表值变成了29", 3, "通知"
        ws.RegWrite Hive&"\"&KeyPath&"\"&ValueName, 20, "REG_DWORD"
这里该如何修改呢?
如果想同时这样监视2个数值的话,不知道如何添加代码?
最后的求助了实在不好意思,完美后我就关闭问题了

TOP

另外一个数值的注册表路径是什么?

TOP

本帖最后由 wh1234567 于 2012-6-11 14:14 编辑

回复 62# powerbat


    另外一个数值的注册表路径是:
Hive2 = "HKEY_LOCAL_MACHINE"
KeyPath2 = "Software\2012"
ValueName2 = "0610"
shuzhi2 =98(这里是指要监视的数值)
gaiwei2 =70(这里是指要修改为的数值)

TOP

Hive = "HKEY_LOCAL_MACHINE"
KeyPath = "Software\333"
ValueName = "444"
shuzhi = 29
gaiwei = 20
Hive2 = "HKEY_LOCAL_MACHINE"
KeyPath2 = "Software\2012"
ValueName2 = "0610"
shuzhi2 = 98
gaiwei2 = 70
strTitle = "注册表监视"
nShowTime = 3
WQL = "Select * from RegistryValueChangeEvent Where (" & _
    "Hive = '"&Hive&"' and " & _
    "KeyPath = '"&Replace(KeyPath,"\","\\")&"' and " & _
    "ValueName = '"&ValueName&"') OR (" & _
    "Hive = '"&Hive2&"' and " & _
    "KeyPath = '"&Replace(KeyPath2,"\","\\")&"' and " & _
    "ValueName = '"&ValueName2 & "') "
Set ws = CreateObject("WScript.Shell")
CheckReg ValueName
CheckReg ValueName2
Set Sink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
Set objWMIServices = GetObject("winmgmts:" & _
    "{impersonationLevel=impersonate}!\\.\root\default")
objWMIServices.ExecNotificationQueryAsync Sink, WQL
ws.Popup "Listening for Registry Change Events...", nShowTime, strTitle, 4096
Do : WScript.Sleep 1000 : Loop
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
    'WScript.Echo wmiObject.GetObjectText_()
    CheckReg wmiObject.ValueName
End Sub
Sub CheckReg(VName)
  On Error Resume Next
  RegFullPath = Hive & "\" & KeyPath & "\" & ValueName
  RegFullPath2 = Hive2 & "\" & KeyPath2 & "\" & ValueName2
  if VName=ValueName then
      Value = ws.RegRead(RegFullPath)
      if Err then
        ws.RegWrite RegFullPath, gaiwei, "REG_DWORD"
        Err.Clear
      end if
      if CStr(Value)=CStr(shuzhi) then
        ws.Popup RegFullPath & " 变成了 " & shuzhi, nShowTime, strTitle, 4096
        ws.RegWrite RegFullPath, gaiwei, "REG_DWORD"
      end if
  end if
  if VName=ValueName2 then
      Value = ws.RegRead(RegFullPath2)
      if Err then
        ws.RegWrite RegFullPath2, gaiwei2, "REG_DWORD"
        Err.Clear
      end if
      if CStr(Value)=CStr(shuzhi2) then
        ws.Popup RegFullPath2 & " 变成了 " & shuzhi2, nShowTime, strTitle, 4096
        ws.RegWrite RegFullPath2, gaiwei2, "REG_DWORD"
      end if
  end if
End SubCOPY
2

评分人数

    • zqz0012005: 乐于助人PB + 10 技术 + 1
    • wh1234567: 谢谢您给我满意的答案,很感激您,可惜我再 ...技术 + 1

TOP

完全搞定,谢谢powerbat

TOP

返回列表