Solved

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

Posted on 2013-02-04
10
148 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
  • 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
Independent Software Vendors: 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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