emi_sastra
asked on
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.
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.
ASKER
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.
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.
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
}
ASKER
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(strApplicati onName)
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(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles btnGeneralLedger.Click
End Sub
End Class
Where to put your code ?
Thank you.
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(strApplicati
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(ByV
End Sub
End Class
Where to put your code ?
Thank you.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_INVE NTORY.BAT" )
End Sub
Private Sub btnFinance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinance.Click
Open_Application("ERV_FINA NCE.BAT")
End Sub
Private Sub btnGeneralLedger_Click(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles btnGeneralLedger.Click
Open_Application("ERV_GL.B AT")
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 (strAppNam e)
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.UseShellExecut e = False
p.StartInfo.CreateNoWindow = True
p.StartInfo.FileName = strApplicationName
p.Start()
End If
Else
Dim p As New Process()
p.EnableRaisingEvents = False
p.StartInfo.UseShellExecut e = 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.MouseHove r
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.MouseLeav e
Me.Cursor = Cursors.Default
End Sub
Private Function Is_Application_Running(ByV al strProcessName As String) As Boolean
Try
Dim ps() As Process = Process.GetProcessesByName (strProces sName)
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.
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_INVE
End Sub
Private Sub btnFinance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinance.Click
Open_Application("ERV_FINA
End Sub
Private Sub btnGeneralLedger_Click(ByV
Open_Application("ERV_GL.B
End Sub
Private Sub Open_Application(ByVal strAppBatchFileName As String)
strApplicationName = Application.StartupPath & "\" & strAppBatchFileName
strAppName = Replace(strApplicationName
Try
If Me.Is_Application_Running(
Dim ps() As Process = Process.GetProcessesByName
If MessageBox.Show("Activate the previous instance?", "Application is already running.", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult
AppActivate(ps(0).Id)
Else
Dim p As New Process()
p.EnableRaisingEvents = False
p.StartInfo.UseShellExecut
p.StartInfo.CreateNoWindow
p.StartInfo.FileName = strApplicationName
p.Start()
End If
Else
Dim p As New Process()
p.EnableRaisingEvents = False
p.StartInfo.UseShellExecut
p.StartInfo.CreateNoWindow
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.MouseHove
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.MouseLeav
Me.Cursor = Cursors.Default
End Sub
Private Function Is_Application_Running(ByV
Try
Dim ps() As Process = Process.GetProcessesByName
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.
ASKER
I get it.
Function Is_Application_Running :
Dim ps() As Process = Process.GetProcessesByName (strProces sName)
should be :
Dim ps() As Process = Process.GetProcessesByName (System.IO .Path.GetF ileNameWit houtExtens ion(strPro cessName))
Thank you.
Function Is_Application_Running :
Dim ps() As Process = Process.GetProcessesByName
should be :
Dim ps() As Process = Process.GetProcessesByName
Thank you.
ASKER
Great.
Thank you very much for your help.
Thank you very much for your help.
Exactly...was just about to point that out. =)
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
else if (menuItem = "app2")
System.Diagnostics.Process
is this solution clear ?