Solved

Need to 'AutoLoad' program2.exe when program1.exe is exited by me

Posted on 2013-02-04
10
149 Views
Last Modified: 2014-01-30
I Am fairly new at programming and am using Visual Studio 2008. I have submitted an attachment to show how I'm loading in seperate programs with a button menu.  What I really want to do is load in program1.exe and when I exit that program, program2.exe will automatically load. Appreciate the code to make this happen. Thanks
AutoLoader-Sample.txt
0
Comment
Question by:nucomputerguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38851774
for external programm Proces.Start
 Private Sub ExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
        Try
            Process.Start("C:\Users\User\Documents\Visual Studio 2010\Projects\FlightManager\FlightManager\bin\Debug\FlightManager.exe")
            Me.Close()

        Catch ex As Exception

        End Try
    End Sub

Open in new window

john...
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38851868
this above code for Program 1 ...make sure to configure  in Program 1  the Application- Shutdown mode ..
so when the form of program 1 closes the application (1) exit also...
0
 

Author Comment

by:nucomputerguy
ID: 38852395
Assume Program1 is Windows Notepad.exe and Program 2 is Windows WordPad.exe. What we are looking for here is when we exit Notepad then WordPad loads automatically.
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!

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38852749
Sorry I misunderstood...it is different for notepad to regognize if the file is open rather than a executable program
http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/a9c1931d-61eb-47c8-8121-101cdeefaa04
for an .exe program you have to continiously check if  it is open and then if not start another process...
0
 

Author Comment

by:nucomputerguy
ID: 38852856
Perhaps I have misled you by using Notepad in the example. The code we need is as follows:

We are trying to create a Visual Basic program that loads in a commercial program we have installed on Windows (like AAA Logo or something with its .exe file). Then once we click to exit that program, Visual Basic automatically loads in another commercial .exe program of our choosing.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38853099
i am Very Sorry for the Delay...it is clear for me ...Please try this....

Dim myfirstProccess As Process
    Dim mysecondProccess As Process

    Private Sub ExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
        Try
            myfirstProccess = New Process
                       myfirstProccess.StartInfo.FileName = "C:\Users\User\Desktop\MynotePad.txt"    
            myfirstProccess.Start()
            myfirstProccess.EnableRaisingEvents = True
            AddHandler myfirstProccess.Exited, AddressOf FirstProcessExited
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub FirstProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
        Try

            mysecondProccess = New Process
            mysecondProccess.StartInfo.FileName = "C:\Users\User\Desktop\Menu.txt"
            mysecondProccess.Start()
            mysecondProccess.EnableRaisingEvents = True

            AddHandler mysecondProccess.Exited, AddressOf SecondProcessExited

            myfirstProccess.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub SecondProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
        mysecondProccess.Close()
    End Sub

    

Open in new window

Hope it hleps....


John (Yiannis)
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38853123
P.S If you want to use an .exe file as a process you have also to insert the full path ...
0
 

Author Comment

by:nucomputerguy
ID: 38853496
Thanks for your response. The code you sent loads both programs at same time. Was wanting to load one program and upon exiting that program, the code loads the second program.
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 38853536
no ....it works exactly the way you want....

Create a new form...add a button and name it ExitBtn ..Double Click and write down this code
Dim myfirstProccess As Process
    Dim mysecondProccess As Process

    Private Sub ExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitBtn.Click
        Try
           ExitBtn.Enabled = False
  myfirstProccess = New Process
            myfirstProccess.StartInfo.FileName = "C:\Users\User\Desktop\MynotePad.txt" 'your full path filename
            myfirstProccess.Start()
            myfirstProccess.EnableRaisingEvents = True
            AddHandler myfirstProccess.Exited, AddressOf FirstProcessExited

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Open in new window


then the events....
Private Sub FirstProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
        Try

            mysecondProccess = New Process
            mysecondProccess.StartInfo.FileName = "C:\Users\User\Desktop\Menu.txt" 'your second full path filename
            mysecondProccess.Start()
            mysecondProccess.EnableRaisingEvents = True

            AddHandler mysecondProccess.Exited, AddressOf SecondProcessExited

            myfirstProccess.Close()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub SecondProcessExited(ByVal sender As Object, ByVal e As System.EventArgs)
        mysecondProccess.Close()
        Me.Invoke(New ExitBtnDelegate(AddressOf EnabledExitBtn), Me.ExitBtn) 'Avoid Cross Thread
    End Sub
    Private Delegate Sub ExitBtnDelegate(ByVal btn As Button)
    Private Sub EnabledExitBtn(ByVal btn As Button)
        btn.Enabled = True
    End Sub

Open in new window

And Here you go....It works..!!
P.S make sure the "Imports System.Diagnostics" namespace
0
 

Author Comment

by:nucomputerguy
ID: 39823260
I've requested that this question be deleted for the following reason:

Was answered 2 years ago
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question