Solved

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

Posted on 2013-02-04
10
147 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL LINE CONTINUATION ISSUE 12 34
Modal Popup Extender control 1 26
Problem with SelectList in .NET MVC application 1 18
get combo value in class 5 10
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

825 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