Solved

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

Posted on 2013-02-04
10
145 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I've requested that this question be deleted for the following reason:

Was answered 2 years ago
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now