Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27199

How can I apply WMI code in a winform?

$
0
0
Code:

Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

    Public Class WMIReceiveEvent

        Public Overloads Shared Function Main() As Integer

            Try

                Dim query As New WqlEventQuery( _
                    "SELECT * FROM Win32_ProcessStartTrace")

                Dim watcher As New ManagementEventWatcher(query)
                Console.WriteLine("Waiting for an event...")

                Dim eventObj As ManagementBaseObject = watcher.WaitForNextEvent()

                Console.WriteLine("{0} event occurred.", eventObj("__CLASS"))

                ' Cancel the event subscription
                watcher.Stop()
                Return 0

            Catch err As ManagementException

                MessageBox.Show("An error occurred while trying to receive an event: " & err.Message)
            End Try
        End Function

    End Class
End Namespace

I tried making it but it will stop after it will get the first event. I tried removing the watcher.stop but did not work
Code:

Imports System
Imports System.Management
Imports System.Windows.Forms
Public Class Form1
    Dim applist(2) As String
    Dim b As Boolean = True




    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Try

            Dim query As New WqlEventQuery( _
                "SELECT * FROM Win32_ProcessStartTrace")

            Dim watcher As New ManagementEventWatcher(query)
            MsgBox("Waiting for an event...")

            Dim eventObj As ManagementBaseObject = watcher.WaitForNextEvent()

            MsgBox("{0} event occurred.")

            ' Cancel the event subscription
            ' watcher.Stop()

        Catch err As ManagementException

            MessageBox.Show("An error occurred while trying to receive an event: " & err.Message)
        End Try

    End Sub


End Class


Viewing all articles
Browse latest Browse all 27199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>