I have written some VBScript (.vbs) to detect routing table changes on the local computer that I want to use in a VB6 exe project.
The VBScript code is below and I have confirmed that it is working:
VB Code:
strComputer = "." Set SINK = WScript.CreateObject("WbemScripting.SWbemSink","SINK_") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") objWMIService.ExecNotificationQueryAsync SINK, "SELECT * FROM Win32_IP4RouteTableEvent" Wscript.Echo "Waiting for routing table change..." Do WScript.Sleep 1000 Loop Sub SINK_OnObjectReady(objLatestEvent, objAsyncContext) WScript.Echo "Routing table changed" End Sub
Now this is the VB6 code below. Everything from the VBScript has just been moved into the form code. The program never reacts to a routing table change and the msgbox is never displayed. I cannot figure out why this is not working. Would appreciate any help. Thanks
VB Code:
Option Explicit Dim SINK Dim objWMIService Private Sub Form_Load() Dim strComputer strComputer = "." Set SINK = CreateObject("WbemScripting.SWbemSink") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") objWMIService.ExecNotificationQueryAsync SINK, "SELECT * FROM Win32_IP4RouteTableEvent" End Sub Public Sub SINK_OnObjectReady(objLatestEvent, objAsyncContext) MsgBox ("Routing table changed") End Sub




Reply With Quote