 
- 帖子
- 505
- 积分
- 1230
- 技术
- 1
- 捐助
- 0
- 注册时间
- 2009-5-28
|
嗯,就是这个vbs代码吧
Hive = "HKEY_LOCAL_MACHINE"
KeyPath = "Software\333"
ValueName = "444"
Set ws = CreateObject("WScript.Shell")
Set Sink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")
Set objWMIServices = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\.\root\default")
objWMIServices.ExecNotificationQueryAsync Sink, _
"Select * from RegistryValueChangeEvent Where " & _
"Hive = '"&Hive&"' and " & _
"KeyPath = '"&Replace(KeyPath,"\","\\")&"' and " & _
"ValueName = '"&ValueName&"'"
WScript.Echo "Listening for Registry Change Events..." & vbCrLf
Do : WScript.Sleep 1000 : Loop
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
Value = ws.RegRead(Hive&"\"&KeyPath&"\"&ValueName)
WScript.Echo "Registry Value Changed: " & Value
if CStr(Value)="29" then ws.Run "a.bat" ',0 '后面加0表示隐藏窗口运行
End Sub
但是如何第一次运行这个vbs,当数值大于29时就好像无法执行a.bat 了,另外发现当数值由其他数变化到29时才会执行a.bat ,而且会弹出错误的窗口。甚至个别时候数值变化到29也无法执行a.bat
这2个问题还得您需要修正一下代码,弄成运行后监视到数值大于29时就全自动执行a.bat,和修正弹出错误的窗口
弹出错误的窗口的原因可能是
Hive = "HKEY_LOCAL_MACHINE"
KeyPath = "Software\333"
ValueName = "444"
....
Value = ws.RegRead(Hive&"\"&KeyPath&"\"&ValueName) |
|