I need some help with checking a process or if a certain window name is open on my project.

Right now what I have is:
FSXCheck = Timer
fsx.exe = Flight Simulator X

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FSXCheck.Enabled = True

    End Sub

    Private Sub FSXCheck_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FSXCheck.Tick
        Dim objWMIService, colProcesses
        Dim Process As String
        Process = "fsx.exe"
        objWMIService = GetObject("winmgmts:")
        colProcesses = objWMIService.ExecQuery("Select * from Win32_Process where name='" & Process & "'")
        If colProcesses.Count Then
            ToolStripStatusLabel1.Text = "FSX Status: Connected"
        End If
    End Sub

I Have the process down, but I need to figure out the

If colProcesses.Count Then
            ToolStripStatusLabel1.Text = "FSX Status: Connected"
        End If

And try to get it to say "FSX Status: Not Connected" when the process is not running, that is what I have a problem on.

If anyone could help, that'd be awesome. :)

Recommended Answers

All 3 Replies

Hi,

Just taking a guess here but what does colProcesses.Count actually return?
How about:

If colProcesses.Count > 0 Then
   ToolStripStatusLabel1.Text = "FSX Status: Connected"
Else
      ToolStripStatusLabel1.Text = "FSX Status: Not Connected"
End if

OR

If colProcesses.Count IsNot Nothing then
 ToolStripStatusLabel1.Text = "FSX Status: Connected"
Else
      ToolStripStatusLabel1.Text = "FSX Status: Not Connected"
End if

Thanks man that worked, :)

Glad I could help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.