Solved

Run another application from within VB6

Posted on 2002-07-18
13
507 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
 
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
IT, Stop Being Called Into Every Meeting

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 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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

15 Experts available now in Live!

Get 1:1 Help Now