Hi Steve,

    All you scriptors below is an issue I have asked several on. The one 
that resides inside my Unintall app works on an XP but not on a Windows 7.
    In fact both work on the XP machine, only the one inside my app does not 
work on Windows 7.
    The .vbs file at the bottom works on the Windows 7 and alerts each time 
there is a change no matter the folder inside the LocalMachine hive of the 
registry.

    So the qeustion to ask is your connect  object and event routines 
suppose to be the substitute for the standard script CreateObject ?
        Sincerely
        Bruce


    The first one is inside my Uninstall app around line 323 and does not 
work in Windows 7, below that is the script and does work in Windows 7 when 
run outside of any WE app, using WScript.

In Uninstall app around line 323:
Dim strComputer: strComputer = "."
Dim strWMIKeyPath: strWMIKeyPath = 
"KeyPath='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall'"
' Universal way for all OS systems for local machine:
'Set wmiServices = GetObject("winmgmts:" _
'& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")

 Set wmiServices = GetObject("winmgmts:root/default")
' Below is one script create but inside we apps you have to split it into 2 
parts and is not working on windows 7, but does on XP:
Set wmiSink = CreateObject( "WbemScripting.SWbemSink")
wmiSinkConnection = ConnectEvent( wmiSink, "OnObjectReady", 
"Sink_OnObjectReady")
wmiServices.ExecNotificationQueryAsync wmiSink, _
"SELECT * FROM RegistryKeyChangeEvent " _
& "WHERE Hive='HKEY_LOCAL_MACHINE' AND " _
& strWMIKeyPath

Sub Sink_OnObjectReady( wmiObject, wmiAsyncContext)
' It could be failing because of the 2 parms needed.
   msgBox " A registry change has happened! "
End Sub


Below is a standard script that works and reports the registry change:
'RegistryChange.vbs
Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject( _
    "WbemScripting.SWbemSink", "SINK_")
Dim strWMIKeyPath: strWMIKeyPath = 
"KeyPath='SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall'"
wmiServices.ExecNotificationQueryAsync wmiSink, _
"SELECT * FROM RegistryKeyChangeEvent " _
& "WHERE Hive='HKEY_LOCAL_MACHINE' AND " _
& strWMIKeyPath
WScript.Echo "Listening for Registry Key" _
    & " Change Events..." & vbCrLf
While(True)
    WScript.Sleep 1000
Wend
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
    WScript.Echo "Received Registry Change Event" _
        & vbCrLf & wmiObject.GetObjectText_()
End Sub

Reply via email to