Solved

pop up message after shellExecute.

Posted on 2004-10-08
6
2,095 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
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.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
Digital marketing agencies have encountered both the opportunities and difficulties that emerge from working with a wide-ranging organizations.
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…
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…

707 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

18 Experts available now in Live!

Get 1:1 Help Now