Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am drawing a blank and have this which I know is wrong

VB
Dim myProcesses As Process() = Process.GetProcessesByName("iexplore")
Dim myProcess As Process
For Each myProcess In myProcesses
   If myProcess.ProcessName.ToString IsNot Nothing Then
      MsgBox(myProcess.ProcessName.ToString)
   ElseIf myProcess.ProcessName.ToString Is "" Then
      MsgBox("closed")
   End If
Next myProcess
Posted
Updated 4-Nov-11 9:10am
v2
Comments
Dr.Walt Fair, PE 4-Nov-11 15:10pm    
Fixed code formatting.

1 solution

That should work I think.
I found this[^] using Google. Works like a charm for me :)
Converted to VB:
VB
Public Function IsProcessOpen(ByVal name As String) As Boolean
   For Each clsProcess As Process In Process.GetProcesses
      If clsProcess.ProcessName.Contains(name) Then
         Return True
      End If
   End If
   Return False
End function

Here's how to check for IE:
VB
If IsProcessOpen("iexplore") Then
   MessageBox.Show("IE is now open!")
Else
   MessageBox.Show("IE is now closed!")
End If

I recommend use of MessageBox over MsgBox, since MessageBox replaces MsgBox in .NET :)
Hope it helps!
 
Share this answer
 
Comments
wiswalld 5-Nov-11 8:32am    
I don't know why but it still will not work. always says Closed
Sander Rossel 5-Nov-11 8:46am    
Could you post your code?
Also, make sure IE is actually open sometimes ;)
wiswalld 5-Nov-11 9:45am    
I must be missing something or a reference because I always get closed
wiswalld 5-Nov-11 9:46am    
Imports SHDocVw
Imports System.Diagnostics
Imports System.Threading
Imports mshtml
Imports System.Net



Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If IsProcessOpen("iexplore") Then
MessageBox.Show("IE is now open!")
Else
MessageBox.Show("IE is now closed!")
End If
End Sub

Public Function IsProcessOpen(ByVal name As String) As Boolean
For Each clsProcess As Process In Process.GetProcesses
If clsProcess.ProcessName.Contains(name) Then
Return True
End If
Return False
Next
End Function
End Class
Sander Rossel 5-Nov-11 10:07am    
Not sure why you have those Imports... If this is all you have in your Class you certainly won't need them.
Your code looks correct. Try debugging it and see if anything that looks like "iexplore" is actually returned by Process.GetProcesses. And once again, make sure you have IE open.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900