Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open & activevate an exe from VB

Status
Not open for further replies.

winniepough

Programmer
Feb 19, 2002
14
US
I have a commercial exe that I want to open and activate, How?
I have the XXXX.exe on the form and can drag the curser over it and hit return. It opens and executes. How do I do the same from the code withOUT my manual action. I want to run this program automaticallly.
 
If I understand you question correctly you should look at Shell XXXX.exe. Anything is possible, the problem is I only have one lifetime.
 
If I understand you correctly, you wish to launch an executable from code. The way to do this is to use the Shell command.

Let's say for instance that you wish to launch Wordpad with a text document within a procedure (e.g. a command button click), here's what the code would look like:

Option Explicit

Private Const WordPad = "C:\Program Files\Windows NT\Accessories\wordpad.exe " 'note the space at the end.
Private Const MyFile = "C:\Temp\MyFile.txt"

Private Sub Command1_Click()
'-----------------------------
Call Shell(WordPad + MyFile, vbNormal)
'-----------------------------
End Sub

Gottit?
Hope this helps!

Thanks!
LeGo PiEcE

"The Computer Spock! Destroy it!" - Captain James T. Kirk
 
The reply by LegoPiece works only if I add a command BUTTON and MANUALLY initiate the activataion. I want to activate the exe WITHOUT any manual interaction, activate it when the VB code gets to subroutine. Additionally I have the problem that when I do get the prgram to run with the command button, it only appears in the task bar in orange rather than green, it it not in focus on top, so I cannot issue the ALT-U, etc commands to make it do the action that I want from it. And I cannot ESC to close the pop-up and the ALT-F4 to close it because it is not if focus. The Calling VB form is on top.
I asked the question origianlly, because, I was only able initiate exe via the OLE from a command button, that was my original problem, that is not solved.

I can of course do a "run" from a command line, which initiates the program and I can issuse all the desired control from the keyboard with the exact results that I want.

 
Have you tried the window API CreateProcess
This not only runs the executable from ur code, also allows u control on the executable, i.e u can end the running process at any time.... which is not possible by shell command.... hope this helps.....
 
Winnie,

I'm confused. I just ran the following code, and it launches Wordpad without any manual interaction from the user. I even went further to call the "Shell" command from a sub-routine within my form module. I also modified the second parameter of the Shell program to 'vbnormalfocus', which means that Wordpad is the active window, after it is launched.

Here is the code to do this...

Option Explicit
'................................................
Private Executable As String

Private Sub Form_Load()
'--------------------------------
Call Launch
'--------------------------------
End Sub

Private Sub Launch()
'--------------------------------
Executable = "C:\Program Files\Windows _ NT\Accessories\wordpad.exe"

Call Shell(Executable, vbNormalFocus)
'--------------------------------
End Sub

If this doesn't do what you originally asked, then please fill me in on what I'm missing! :)
Thanks!
LeGo PiEcE

"The Computer Spock! Destroy it!" - Captain James T. Kirk
 
winnie,

I think you may be slightly confused. The example that lego piece provided does indeed happen to require you tp press abutton - but the essential code, which is in the Click event of a command button can just as easily go into a Public Sub, or wherever you want really.
 
strongm - Muchos Gracias Con Queso, Amigo! LOL Thanks!
LeGo PiEcE

"The Computer Spock! Destroy it!" - Captain James T. Kirk
 
MANY many thanks to Strongm and LegoPiece, I am running, Jim
 
Why thank you... we strive for satisfaction. :) Thanks!
LeGo PiEcE

"The Computer Spock! Destroy it!" - Captain James T. Kirk
 
Craigsander in:
Home > Forum Areas > Programmers > Languages > Visual Basic(Microsoft) -Version 5 & 6 Forum
How do i tell if an app is running?
thread222-236844
RE: May have provided the NEXT layer to my unwrapping the onion. I will give it a try.
As I fix one problem, another is uncovered. "You never know what is under the next layer of the onion."
Adding delay Timer() and DoEvents forces a long fixed delay to prevent encountering the RunT ime error..
Response time is of the essence.


Niv3K in: Home > Forum Areas > Programmers > Languages > Visual Basic(Microsoft) -Version 5 & 6 Forum
Open an EXE, tiny new problem, closing the EXE
thread222-227807
provided the major breakthrough which uncovered the above layer.

Thanks
WinniePough
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top