Solved

pop up message after shellExecute.

Posted on 2004-10-08
6
2,108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 86

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL VB connection works in one PC and doesn't in another 15 80
Visual Studio 2005 text editor 10 56
pop out of webbrowser1 control vba6 5 52
How do I buy BitCoin? 4 30
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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