Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6 KiB

  1. VERSION 5.00
  2. Begin VB.Form Form1
  3. Caption = "WBEM NT Event Log Sample"
  4. ClientHeight = 3285
  5. ClientLeft = 60
  6. ClientTop = 345
  7. ClientWidth = 10695
  8. LinkTopic = "Form1"
  9. ScaleHeight = 3285
  10. ScaleWidth = 10695
  11. StartUpPosition = 3 'Windows Default
  12. Begin VB.CommandButton Command2
  13. Caption = "Stop Listening"
  14. Height = 375
  15. Left = 5760
  16. TabIndex = 2
  17. Top = 2760
  18. Width = 1575
  19. End
  20. Begin VB.CommandButton Command1
  21. Caption = "Listen for Events"
  22. Height = 375
  23. Left = 3480
  24. TabIndex = 1
  25. Top = 2760
  26. Width = 1575
  27. End
  28. Begin VB.ListBox List
  29. Height = 2010
  30. ItemData = "execnquery.frx":0000
  31. Left = 240
  32. List = "execnquery.frx":0002
  33. TabIndex = 0
  34. Top = 600
  35. Width = 10095
  36. End
  37. End
  38. Attribute VB_Name = "Form1"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Dim objServices As SWbemServices
  44. Dim WithEvents objSink As SWbemSink
  45. Attribute objSink.VB_VarHelpID = -1
  46. Dim objEvents As SWbemEventSource
  47. Private Sub Command1_Click()
  48. Dim objEvent As SWbemObject
  49. Command1.Enabled = False
  50. Command2.Enabled = True
  51. On Error Resume Next
  52. objServices.ExecNotificationQueryAsync objSink, "select * from __instancecreationevent where targetinstance isa 'Win32_NTLogEvent'"
  53. End Sub
  54. Private Sub Command2_Click()
  55. Command2.Enabled = False
  56. Command1.Enabled = True
  57. objSink.Cancel
  58. End Sub
  59. Private Sub Form_Load()
  60. ' The following sample registers to be informed whenever an instance
  61. ' of the class MyClass is created
  62. Command1.Enabled = False
  63. Command2.Enabled = False
  64. Set objSink = New SWbemSink
  65. Set objServices = GetObject("winmgmts:{impersonationLevel=impersonate,(Security)}")
  66. Command1.Enabled = True
  67. End Sub
  68. Private Sub objSink_OnCompleted(ByVal iHResult As WbemScripting.WbemErrorEnum, ByVal objWbemErrorObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
  69. Debug.Print "Cancelled"
  70. End Sub
  71. Private Sub objSink_OnObjectReady(ByVal objWbemObject As WbemScripting.ISWbemObject, ByVal objWbemAsyncContext As WbemScripting.ISWbemNamedValueSet)
  72. Debug.Print "Got event"
  73. List.AddItem objWbemObject.TargetInstance.Message
  74. List.Refresh
  75. End Sub