Link to home
Start Free TrialLog in
Avatar of nomar2
nomar2

asked on

Check with VB.Net Code whether a program is open or not

I am using VB.Net code

I have a piece of code built that needs another program open before it can run properly.

I know when the program is open it appears as SimplyAccounting.exe in Task Manager..is there a way I can test this...
if open continue...
if not open MsgBox "Program must be open"
Avatar of NotLogical
NotLogical
Flag of Canada image

Hi, please see below for the code...

You can use it like this:

        If (IsProcessRunning("SimplyAccounting.exe")) Then
            MessageBox.Show("It is running")
        Else
            MessageBox.Show("Process not found...")
        End If
    Public Function IsProcessRunning(ByVal strProcess As String) As Boolean
        Dim pProcList() As Process
 
        ' Did user pass-in a valid process name?
        If (String.IsNullOrEmpty(strProcess)) Then
            ' No - return "not found"
            IsProcessRunning = False
            Exit Function
        End If
 
        ' Retrieve process list
        pProcList = Process.GetProcesses
 
        ' Traverse process list
        For Each pProcess As Process In pProcList
            ' Compare names
            Try
                If (pProcess.MainModule.ModuleName = strProcess) Then
                    ' We found it!
                    IsProcessRunning = True
                    Exit Function
                End If
            Catch
            End Try
        Next
 
        ' Not found...
        IsProcessRunning = False
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nomar2
nomar2

ASKER

Just getting back to office will check this now ...Thanks