Solved

pop up message after shellExecute.

Posted on 2004-10-08
6
2,098 Views
Last Modified: 2013-11-28
The following code opens the applicaiton I need.

ShellExecute Me.hwnd, "open", "C:\Program Files\myprogram.exe", vbNullString, vbNullString, 1

I want a pop up message AFTER the myapplication.exe opens. If I use the simple msgbox command even after the shellExecute, the msgbox opens before the application.


Thank you.

0
Comment
Question by:Aiysha
6 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 12259938
Hi Aiysha,
The only way I've been able to do this is using the FindWindow windows API, first, you'll need to use a tool like SPY to find out the Window Class of the application you are shelling out to, run spy, under the File menu, select the Find Window tool, drag the bullseye over to your application window and drop it... the name of the Window Class appears in the Spy dialog... write this down.  Now, in your code, copy the FindWindow API from the Windows API viewer and paste it in your declaration section.  Then, your code would look something like this:

ShellExecute Me.hwnd, "open", "C:\Program Files\myprogram.exe", vbNullString, vbNullString, 1

Do While FindWindow(vbNullString, "rctrl_renwnd32") = 0
Loop

Or, if you know what the title bar of the application will say, then do this

Do While FindWindow("MyAppTitle", vbNullString) = 0
Loop

You will loop until such a window opens (careful of getting into an endless loop)

Cheers!
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12260046
You may want to do this


Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "C:\Program Files\myprogram.exe",  , True
Set wshShell = Nothing
msgbox now
0
 

Author Comment

by:Aiysha
ID: 12260145
Thanx for all the responses.

EDDYKT,
When I use your code I get the follwing error at Run

Method 'Run' of object 'IWshSheel3' failed.   .. is there a library missing? Please comment.

Thank you.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 12260246
Because you have space

use this

wshShell.Run Chr(34) & "C:\Program Files\myprogram.exe" & Chr(34),  , True
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12260358
You could try waiting for the application to initialize by waiting for it to reach an idle state:

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
Private Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Const INFINITE = -1&
Private Const PROCESS_ALL_ACCESS = 0

Private Sub OpenApp(ByVal appName As String)
    Dim ret As Long
    Dim pid As Long
    Dim hProcess As Long
   
    pid = Shell(appName)
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
    ret = WaitForInputIdle(hProcess, INFINITE)
    Call CloseHandle(hProcess)
End Sub
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12267681
Reason is simple. Your program is not getting enough time before it pops up the message. Launching the application involves disk I/O and other system security checks (in case of certain OSs). Hence, the popup gets displayed before you can see the app.

The solution is to wait for the application to load. Idle Mind's solution is neatest. However, even a dummy loop stuffed with a DoEvents will do.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
E-commerce cart for beginners 7 135
Hide vba in gp 7 83
clicking a shape in a frame array vb6 3 40
Help with retrieving partial value from a column using VB.NET 4 44
Read about why website design really matters in today's demanding market.
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

867 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

22 Experts available now in Live!

Get 1:1 Help Now