Jump to content

Trying to convert this VBscript to Autoit


kpu
 Share

Recommended Posts

I used VA converter to convert it along with some minor changes I made to correct it, but can't get it to work. This script should monitor regkeytree for changes. See the VBscript below code.

#include <file.au3>
Dim $strComputer,$wmiServices,$wmiSink
$strComputer = @ComputerName
$wmiServices = ObjGet("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default")

$wmiSink = ObjCreate("WbemScripting.SWbemSink", "SINK_") 
 $wmiServices.ExecNotificationQueryAsync ($wmiSink, _
    "SELECT * FROM RegistryKeyChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' " & _
        "AND KeyPath='SYSTEM\\CurrentControlSet\\Control\\lsa'") 
 
;_FileWriteLog ("log.log","Listening for Registry Change Events..." & @CRLF )
 
While 1 
  Sleep (1000) 
Wend 
 
Func SINK_OnObjectReady($wmiObject, $wmiAsyncContext) 
    _FileWriteLog ("log.log","Received Registry Change Event" & @CRLF & $wmiObject.GetObjectText)
EndFunc

Here's the acctual VBSscript

strComputer = "."
Set wmiServices = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")

Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_") 
 
wmiServices.ExecNotificationQueryAsync wmiSink, _ 
    "SELECT * FROM RegistryKeyChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' " & _
        "AND KeyPath='SYSTEM\\CurrentControlSet\\Control\\lsa'" 
 
WScript.Echo "Listening for Registry Change Events..." & vbCrLf 
 
While(1) 
    WScript.Sleep 1000 
Wend 
 
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext) 
    WScript.Echo "Received Registry Change Event" & vbCrLf & _ 
        wmiObject.GetObjectText_() 
End Sub
Link to comment
Share on other sites

I think that you need to break out your event handler definition into a seperate statement... try this:

$wmiSink = ObjCreate("WbemScripting.SWbemSink") 
$sink = ObjEvent($wmiSink, "SINK_")

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Thanks Dale!

Here's the updated and working code. I had to make some other small changes, but it works good.

#include <file.au3>
Dim $strComputer,$wmiServices,$wmiSink
$strComputer = @ComputerName
$wmiServices = ObjGet("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\default")
    
$wmiSink = ObjCreate("WbemScripting.SWbemSink")
$sink = ObjEvent($wmiSink, "SINK_")
$wmiServices.ExecNotificationQueryAsync ($wmiSink, _
    "SELECT * FROM RegistryKeyChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' " & _
        "AND KeyPath='SYSTEM\\CurrentControlSet\\Control\\lsa'")

_FileWriteLog ("log.log","Listening for Registry Change Events...")
While 1
  Sleep (1000)
Wend

Func SINK_OnObjectReady($wmiObject, $wmiAsyncContext)
    MsgBox(32,"",$wmiObject.GetObjectText_());Received Registry Change Event" & $wmiObject.GetObjectText)
    _FileWriteLog ("log.log","Received Registry Change Event " & $wmiObject.GetObjectText_() & @CRLF)
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...