Solved

pop up message after shellExecute.

Posted on 2004-10-08
6
2,104 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
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.

830 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