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:
  1. strComputer = "."
  2.  
  3. Set SINK = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
  4. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  5. objWMIService.ExecNotificationQueryAsync SINK, "SELECT * FROM Win32_IP4RouteTableEvent"
  6.  
  7. Wscript.Echo "Waiting for routing table change..."
  8.  
  9. Do
  10.    WScript.Sleep 1000
  11. Loop
  12.  
  13.  
  14. Sub SINK_OnObjectReady(objLatestEvent, objAsyncContext)
  15.  
  16.     WScript.Echo "Routing table changed"
  17.  
  18. 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:
  1. Option Explicit
  2. Dim SINK
  3. Dim objWMIService
  4.  
  5. Private Sub Form_Load()
  6.     Dim strComputer
  7.    
  8.     strComputer = "."
  9.    
  10.     Set SINK = CreateObject("WbemScripting.SWbemSink")
  11.     Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  12.     objWMIService.ExecNotificationQueryAsync SINK, "SELECT * FROM Win32_IP4RouteTableEvent"
  13. End Sub
  14.  
  15.  
  16. Public Sub SINK_OnObjectReady(objLatestEvent, objAsyncContext)
  17.     MsgBox ("Routing table changed")
  18. End Sub