- 帖子
- 752
- 积分
- 4553
- 技术
- 139
- 捐助
- 0
- 注册时间
- 2010-8-24
|
37楼
发表于 2012-6-7 14:26
| 只看该作者
本帖最后由 powerbat 于 2012-6-7 14:27 编辑
回复 36# wh1234567
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>cd /d D:\
D:\>type a.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
D:\>type a.bat
@echo hello&pause
D:\>start /b cscript a.vbs
Listening for Registry Change Events...
D:\>reg add hklm\Software\333 /v 444 /d 28 /f
操作成功结束
Registry Value Changed: 28
D:\>reg add hklm\Software\333 /v 444 /d 29 /f
操作成功结束
Registry Value Changed: 29
==============================================================================
vbs自动运行a.bat弹出了一个窗口:
hello
请按任意键继续. . .
==============================================================================
D:\>reg add hklm\Software\333 /v 444 /d 27 /f
操作成功结束
Registry Value Changed: 27
D:\>reg add hklm\Software\333 /v 444 /d 29 /f
操作成功结束
Registry Value Changed: 29
==============================================================================
vbs自动运行a.bat弹出了一个窗口:
hello
请按任意键继续. . .
==============================================================================
D:\>
再看不懂你就不要学批处理了。。。 |
|