Solved

Run another application from within VB6

Posted on 2002-07-18
13
514 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:DrD
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 3

Expert Comment

by:RodStephens
ID: 7163402
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
 
LVL 3

Expert Comment

by:RodStephens
ID: 7163407
Oops. The Shell statement needs quotes:

  Shell "C:\Somewhere\program_name.exe"
 
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7163465
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
3 Use Cases for Connected Systems

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

 
LVL 2

Expert Comment

by:Ber
ID: 7163615
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
 

Author Comment

by:DrD
ID: 7163726
To Ber

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

Do you have any code suggestions?

Thanks,

David
0
 
LVL 2

Accepted Solution

by:
priya_pbk earned 100 total points
ID: 7164164
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7164338
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
 

Author Comment

by:DrD
ID: 7165616
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7166314
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7166317
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
 

Author Comment

by:DrD
ID: 7166931
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
 

Author Comment

by:DrD
ID: 7167334
Thanks for your help - all of you!

This is a GREAT Bunch of People

David
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7167989
thanks David!

-priya
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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