Solved

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

Posted on 2013-02-04
10
150 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

623 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