locked
MDIParent form Launch third party software RRS feed

  • Question

  • I have a MDI Application with a MDIParent form and two Child forms called form1 and form2. What I need to do is.
     Launch the third party software from MDIparent form and if it  already open then not to open again.

    Thanks,

    BVN
    Tuesday, June 16, 2009 2:01 PM

Answers

  • Tested

    Although WinMail is a single instance program I could see that it works in the debugger
    Imports System.Diagnostics
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim stnr As New StartNonRunningProcess()
            stnr.StartNonRunningProcess("C:\Program Files (x86)\Windows Mail\WinMail.Exe")
        End Sub
    End Class
    Friend Class StartNonRunningProcess
        Public Sub StartNonRunningProcess(ByVal Application As String)
            Dim localByName As Process() = Process.GetProcessesByName(IO.Path.GetFileNameWithoutExtension(Application))
            For Each pRunning As Process In localByName
                If pRunning.HasExited = False Then Return
            Next
            Process.Start(Application)
        End Sub
    End Class

    Success
    Cor
    • Marked as answer by BVN2002 Tuesday, June 16, 2009 7:23 PM
    Tuesday, June 16, 2009 6:54 PM

All replies

  • You could launch the application by using the process.start method.

    To see if the application is running already, you could enumerate through all the running processes using the Process.GetProcesses().
    If this post is useful, mark it as answer.
    Tuesday, June 16, 2009 2:16 PM
  • Hi

    Why do you not create your own class then you can start it from everywhere for instance like this

    Imports System.Diagnostics
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim stnr As New StartNonRunningProcess()
            stnr.StartNonRunningProcess("IExplore")
        End Sub
    End Class
    
    
    Friend Class StartNonRunningProcess
        Public Sub StartNonRunningProcess(ByVal Application As String)
            Dim localByName As Process() = Process.GetProcessesByName(Application)
            For Each pRunning As Process In localByName
                If pRunning.HasExited = False Then Return
            Next
            If localByName Is Nothing Then
                Process.Start(Application)
            End If
        End Sub
    End Class
    

    Success
    Cor
    Tuesday, June 16, 2009 3:16 PM
  •  

    Hi CodeCruiser,

    I have a button on my MDIParent, when it clicked then third party application is launch, the problem is every time it clicked another instance open. 
    My code show below.

    Dim
    FormFast As String = "C:\Program Files\FormFast\FormFastDataManager.exe"

    Process.Start(FormFast, 1)

    Thank you.

    BVN

    Tuesday, June 16, 2009 3:39 PM
  • As i suggested in my first comment, use the Process.GetProcesses method to retrieve all the programs currently running and then if this program is not already running then start it.
    If this post is useful, mark it as answer.
    Tuesday, June 16, 2009 3:50 PM
  • Check this link

    http://www.devx.com/dotnet/Article/7914



    If this post is useful, mark it as answer.
    Tuesday, June 16, 2009 3:51 PM
  • Hi Cor,

    I've tried implement your code in my MDIParent form, and I have this code in the button

     

    Private Sub button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click

     

    Dim stnr As New StartNonRunningProcess()

    stnr.StartNonRunningProcess(

    "C:\Program Files\FormFast\FormFastDataManager.exe")

     

    End Sub

    And the Friend Class in the MDIParent itself.  The third party program will launch every time the button is clicked.  If I change Friend Classe from

    If localByName Is Nothing Then
                Process.Start(Application)
            End If

    to

    If localByName IsNot Nothing Then
                Process.Start(Application)
            End If

    If I am using your original code then third party program not launch at all.  What am I doing wrong?

    Thank for your help.

    BVN

    Tuesday, June 16, 2009 4:41 PM
  • Code Cruiser,

    Thank you for your suggestion and info link, I've tried all that but nothing seem to work for me.

    Thanks :-((

    BVN
    Tuesday, June 16, 2009 4:43 PM
  • Use the getfilenamewithoutextentsions from the IO.Path method and use that to get the getprocessbyName

    http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx

    Tuesday, June 16, 2009 4:47 PM
  • If the suggestions from COR and CODECRUISER does not solve this issue, may be you try to get the application with windowtitle. Below is the code i used in one of my program
     Public Sub CheckApplicationRuning(ByVal applicationNameWithoutExtension As String)
            Dim proc, processT() As Process
            processT = Process.GetProcessesByName(applicationNameWithoutExtension)
            For Each proc In processT
                If proc.HasExited = False Then
                    Return
                Else
                    System.Diagnostics.Process.Start("Applicationname you want to run")
    
                End If
            Next
        End Sub
        Public Sub CheckprocessByWindowTitle(ByVal appTitlename As String)
            Dim wintitle As String = ""
            Dim applicationName As String = ""
            For Each p As Process In Process.GetProcesses()
                wintitle = p.MainWindowTitle
                If String.Compare(wintitle, appTitlename, True) = 0 Then
                    applicationName = p.MainModule.FileName
                    applicationName = Path.GetFileNameWithoutExtension(applicationName)
                    Call IsApplicationRuning(applicationName)
                End If
            Next
        End Sub
    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, June 16, 2009 5:31 PM
  • Hi KayMaf,

    Thank you for your reply,  there is one little problem I got in your code, IsApplicationRunning is Not Declared, Any idea why? Do I need Imports NameSpace for it, if then what is it namespace?

    Thank you so much.

    BVN
    Tuesday, June 16, 2009 5:59 PM
  • Sorry for that, is my mistake, change it to Call CheckApplicationRuning(applicationName)

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Tuesday, June 16, 2009 6:01 PM
  • Thanks Kaymaf,

    Here is what I have in MDIParent Form

    Public

     

    Sub CheckApplicationRuning(ByVal applicationNameWithoutExtension As String)

     

    Dim proc, processT() As Process

    processT = Process.GetProcessesByName(applicationNameWithoutExtension)

     

    For Each proc In processT

     

    If proc.HasExited = False Then

     

    Return

     

    Else

    System.Diagnostics.Process.Start(

    "C:\Program Files\FormFast\FormFastDataManager.exe")

     

    End If

     

    Next

     

    End Sub

     

    Public Sub CheckprocessByWindowTitle(ByVal appTitlename As String)

     

    Dim wintitle As String = ""

     

    Dim applicationName As String = ""

     

    For Each p As Process In Process.GetProcesses()

    wintitle = p.MainWindowTitle

     

    If String.Compare(wintitle, appTitlename, True) = 0 Then

    applicationName = p.MainModule.FileName

    applicationName = Path.GetFileNameWithoutExtension(applicationName)

     

    Call CheckApplicationRuning(applicationName)

     

    End If

     

    Next

     

    End Sub

    And I have this code in my Button, the button is on MDIParent form.

    Private

     

    Sub button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click

     

    Dim FormFast As String = "C:\Program Files\FormFast\FormFastDataManager.exe"

    Process.Start(FormFast)

     

     

    End Sub

    Third party app. still launch every time the button is clicked.
    I greatly appreciate your help.

    BVN 

    Tuesday, June 16, 2009 6:31 PM
  • Tested

    Although WinMail is a single instance program I could see that it works in the debugger
    Imports System.Diagnostics
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim stnr As New StartNonRunningProcess()
            stnr.StartNonRunningProcess("C:\Program Files (x86)\Windows Mail\WinMail.Exe")
        End Sub
    End Class
    Friend Class StartNonRunningProcess
        Public Sub StartNonRunningProcess(ByVal Application As String)
            Dim localByName As Process() = Process.GetProcessesByName(IO.Path.GetFileNameWithoutExtension(Application))
            For Each pRunning As Process In localByName
                If pRunning.HasExited = False Then Return
            Next
            Process.Start(Application)
        End Sub
    End Class

    Success
    Cor
    • Marked as answer by BVN2002 Tuesday, June 16, 2009 7:23 PM
    Tuesday, June 16, 2009 6:54 PM
  • Cor,

    That is work, thank you soooooo Much................!

    BVN
    Tuesday, June 16, 2009 7:24 PM