[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

CLOSE APPLICATIONS FROM MAIN APPLICATION

Hi All,

I have several applications that run from a main Application.

I want to close all opened applications if the main application is closed with condition
I want to close just like I close the applications  from within the application itself.

When the application is close from the application itself, it has to do some closing stuff before ending the application.

How could I do it ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 3
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You could do something like:
Public Class Form1

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim ProcessName As String = "SomeProcessName"
        For Each proc As Process In Process.GetProcessesByName(ProcessName)
            proc.CloseMainWindow()
        Next
    End Sub

End Class

Open in new window

0
 
emi_sastraAuthor Commented:
Hi Idle_Mind,

The child application could have many instance running.
Since we allow it.

  If Me.Is_Application_Running(strAppName) Then
                Dim ps() As Process = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(strAppName))

                If MessageBox.Show("Open New Application?", "Application is already running.", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No 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 = System.IO.Path.GetFileNameWithoutExtension(strAppName)
                    p.StartInfo.Arguments = ERV_Global.strLoginUserID & _
                                            " " & _
                                            ERV_Global.strLoginUserName.Trim & _
                                            " " & _
                                            ERV_Global.strLoginPassword.Trim
                    p.Start()
                End If
Endi


Thank you.
0
 
emi_sastraAuthor Commented:
I try this, is is ok ?

 Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim ProcessName As String = "ERV_INVENTORY.EXE"

        For Each proc As Process In Process.GetProcessesByName(ProcessName)
            proc.CloseMainWindow()
        Next

        ProcessName = "ERV_FINANCE.EXE"

        For Each proc As Process In Process.GetProcessesByName(ProcessName)
            proc.CloseMainWindow()
        Next

        ProcessName = "ERV_GL.EXE"

        For Each proc As Process In Process.GetProcessesByName(ProcessName)
            proc.CloseMainWindow()
        Next

    End Sub

Thank you.
0
 
emi_sastraAuthor Commented:
Great, it works.

Thank you very much for your help.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sorry...was out rock climbing.  Looks like you got it all figured out!  =)
0

Featured Post

Technology Partners: 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!

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