• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

MENU FOR SOME EXE

Hi All,

I have several separate applications (exe).
Now, I want to put it into a separate application that shows those exe to select.

How could I do it ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 6
  • 2
  • 2
1 Solution
 
MisbahCommented:
let us assume you have three applications,
in the menu, add three items (app1, app2, app3)

when the user select a menu item, run the application

in the menu_selection_changed event , write a code like this:

if  (menuItem = "app1")
System.Diagnostics.Process.Start("C:\app1.exe")

else if (menuItem = "app2")
System.Diagnostics.Process.Start("C:\app2.exe")


is this solution clear ?
0
 
emi_sastraAuthor Commented:
Hi  Dr-Hussain,

Show I use mdi form or just a form with several buttons.
Since the main menu for application is simple.

How if the user select the opened application ?
How to check if the application is running and ask user to choose to open another one or activate the current running instance ?

Thank you.
0
 
MisbahCommented:
use p1.HasExited to check that, see the code below:

  ProcessStartInfo pinfo1 = new ProcessStartInfo();
  pinfo1.FileName = "c:\\app1.exe";


            Process p1 = Process.Start(pinfo1);
            p1.WaitForExit();  // if you use this, then the user will be allowed only to interact with app1.exe and after he finish then he can interact with the main application to run other apps .

// you can also use 
          if(  p1.HasExited )
{
 // app1 was closed
}
else
{
// app1 is still running
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
emi_sastraAuthor Commented:
Below is my code :

Public Class frmMain

    Private Sub btnInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInventory.Click

        Dim strApplicationName As String = Application.StartupPath & "\" & "ERV_INVENTORY.EXE"

        Process.Start(strApplicationName)
    End Sub

    Private Sub btnFinance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinance.Click

    End Sub

    Private Sub btnGeneralLedger_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGeneralLedger.Click

    End Sub
End Class


Where to put your code  ?

Thank you.
0
 
emi_sastraAuthor Commented:
Your code in vb :

Dim pinfo1 As New ProcessStartInfo()
pinfo1.FileName = "c:\app1.exe"


Dim p1 As Process = Process.Start(pinfo1)
p1.WaitForExit()
' if you use this, then the user will be allowed only to interact with app1.exe and after he finish then he can interact with the main application to run other apps .
' you can also use
            ' app1 was closed
If p1.HasExited Then
            ' app1 is still running
Else
End If

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"How if the user select the opened application ? ... How to check if the application is running and ask user to choose to open another one or activate the current running instance ?"

Here's an example:
    Private Sub btnInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInventory.Click
        Dim strApplicationName As String = System.IO.Path.Combine(Application.StartupPath, "ERV_INVENTORY.EXE")
        Dim strProcessName As String = System.IO.Path.GetFileNameWithoutExtension(strApplicationName)
        Dim ps() As Process = Process.GetProcessesByName(strProcessName)
        If ps.Length = 0 Then
            Process.Start(strApplicationName)
        Else
            If MessageBox.Show("Activate the previous instance?", "Inventory is already running.", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
                AppActivate(ps(0).Id)
            Else
                Process.Start(strApplicationName)
            End If
        End If
    End Sub

Open in new window

0
 
emi_sastraAuthor Commented:
Hi  Idle_Mind,

Please see below code,  ps.Length always return 0 ?

Option Explicit On

Public Class frmMain

    Dim strApplicationName As String = ""
    Dim strAppName As String = ""

    Private Sub btnInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInventory.Click

        Open_Application("ERV_INVENTORY.BAT")

    End Sub

    Private Sub btnFinance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinance.Click
        Open_Application("ERV_FINANCE.BAT")
    End Sub

    Private Sub btnGeneralLedger_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGeneralLedger.Click
        Open_Application("ERV_GL.BAT")
    End Sub

    Private Sub Open_Application(ByVal strAppBatchFileName As String)

        strApplicationName = Application.StartupPath & "\" & strAppBatchFileName
        strAppName = Replace(strApplicationName, ".BAT", ".EXE")

        Try

            If Me.Is_Application_Running(strAppName) Then
                Dim ps() As Process = Process.GetProcessesByName(strAppName)

                If MessageBox.Show("Activate the previous instance?", "Application is already running.", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
                    AppActivate(ps(0).Id)
                Else
                    Dim p As New Process()

                    p.EnableRaisingEvents = False
                    p.StartInfo.UseShellExecute = False
                    p.StartInfo.CreateNoWindow = True
                    p.StartInfo.FileName = strApplicationName
                    p.Start()
                End If
            Else
                Dim p As New Process()

                p.EnableRaisingEvents = False
                p.StartInfo.UseShellExecute = False
                p.StartInfo.CreateNoWindow = True
                p.StartInfo.FileName = strApplicationName
                p.Start()

            End If

        Catch ex As Exception
            MsgBox(ex.ToString)
            MsgBox("Error Opening Application ...!", MsgBoxStyle.Information, Me.Text)
        End Try

    End Sub

    Private Sub btn_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
                btnInventory.MouseHover, _
                btnFinance.MouseHover, _
                btnGeneralLedger.MouseHover

        Me.Cursor = Cursors.Hand

    End Sub


    Private Sub btn_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles _
                btnInventory.MouseLeave, _
                btnFinance.MouseLeave, _
                btnGeneralLedger.MouseLeave

        Me.Cursor = Cursors.Default

    End Sub

    Private Function Is_Application_Running(ByVal strProcessName As String) As Boolean

        Try

            Dim ps() As Process = Process.GetProcessesByName(strProcessName)

            If ps.Length = 0 Then Return False

            Return True

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        Return False

    End Function
 
End Class

What's the problem ?

Thank you.
0
 
emi_sastraAuthor Commented:
I get it.

Function Is_Application_Running :

   Dim ps() As Process = Process.GetProcessesByName(strProcessName)

should be :

 Dim ps() As Process = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(strProcessName))

Thank you.
0
 
emi_sastraAuthor Commented:
Great.

Thank you very much for your help.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Exactly...was just about to point that out.  =)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now