Run another application from within VB6

I have two VB applications, VB1.exe and VB2.exe. I want to open and run them from (say) VB1.exe  --- This would be the same as opening both of them sequentially using the "run" command on the Desktop.

I want to be able to open both of them, toggle between them, and then close both of them using VB6 command buttons on a VB6 form...

Any Ideas?

I will probably need a code snippet, because I am not very expert.

Thanks

David
DrDAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RodStephensCommented:
You can start the second application from the first using:

   Shell C:\Somewhere\program_name.exe

Unfortunately this doesn't give you control over the other application once it starts.

There are ways to get a handle to the other program, but in this case it may be easiest to just kill any program that has the right title. For example, if your second program is named "Program2", kill any program with that title.

For an example that kills other programs, look at:

    http://www.vb-helper.com/HowTo/killapp.zip
0
RodStephensCommented:
Oops. The Shell statement needs quotes:

  Shell "C:\Somewhere\program_name.exe"
 
0
rspahitzCommented:
Or close the other app by activating it and sending keystrokes to close it:

from VB1.exe:

AppActivate "VB2.exe title"
SendKeys "%Fx" ' send Alt-F followed by x, which assumes that you have a "File" menu with an "eXit" function in it.

--
SendKeys is a bit kludgy, but might work well enough in this case.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

BerCommented:
You can use the shell command as stated above, alternatively you can use the ShellExecute API to open your app. To close the other app look at this page...

http://www.desaware.com/articles/CloseL3.htm

Cheers...
Ber...

0
DrDAuthor Commented:
To Ber

I looked at the article, but found it very difficult to understand..

Do you have any code suggestions?

Thanks,

David
0
priya_pbkCommented:
hi DrD,

try this:

In your vb application which calls the VB1.exe and VB2.exe, write this in the code window. Place 3 command button on the form first.

'General Declaration in your form
Private Declare Function FindWindow _
       Lib "user32" Alias "FindWindowA" _
       (ByVal lpClassName As String, _
       ByVal lpWindowName As String) _
       As Long

Private Declare Function SendMessage _
       Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       lParam As Long) _
       As Long

'In the form

Private Sub Command1_click 'start the exes
Call Shell("C:\myDirectory\VB1.exe, vbNormalFocus)
Call Shell("C:\myDirectory\VB2.exe, vbNormalFocus)
End Sub

Private Sub killFirst_click()
Dim lpClassName As String
         Dim lpCaption As String
         Dim Handle As Long

         Const NILL = 0&
         Const WM_SYSCOMMAND = &H112
         Const SC_CLOSE = &HF060&

         lpCaption = "First App" 'put the caption of the first form

      '* Determine the handle to the Calculator window.
         Handle = FindWindow(lpClassName$, lpCaption$)

      '* Post a message to Calc to end its existence.
         Handle = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)

End Sub

'similarly kill the second application also.

Hope this helped!!

-priya


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
inthedarkCommented:
If you want to communicate between the Apps you can use DDE.
Or you can use WindSock control to send data to and fro.

But why not go for simple approach and bind the two apps into an ActiveX Exe with using a one thread per object model.

Make your principle forms as an MDI form and any other forms as MDI children. The then app. can easily control the other forms.
0
DrDAuthor Commented:
To inthedark

Your suggestion sounds interesting.... I would like to try the ActiveX approach.

Do you have any further information?

Also, would this work with one VB6 and one VB.net app?

Thanks to all of you!

David
0
inthedarkCommented:
Sorry DrD, VB6 mix with VB.NET won't work.

In the old days you created subroutines which you compiled to objects which could then be linked together. You could link anything.  You may be able to convert the VB6 source to VB.NET. If this is a corporate project it seems madness to be supporting 2 platforms?

0
inthedarkCommented:
Back to basics, what are these 2 apps doing? Why do they need to be seperate exe files? Possible because you don't have the source code for one of them?
0
DrDAuthor Commented:
To inthedark

No, I have the source code for both of them, but the VB6 app won't convert to VB.net without oodles of extra work. I commissioned the VB.net app because this is where most people seem to be going. I will have to decide which platform to continue with. Right now, it seems to be better to go with VB6 because I wrote all of the VB6 app myself, and there isn't much in the VB.Net part.


Thanks

David
0
DrDAuthor Commented:
Thanks for your help - all of you!

This is a GREAT Bunch of People

David
0
priya_pbkCommented:
thanks David!

-priya
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.