Solved

pop up message after shellExecute.

Posted on 2004-10-08
6
2,110 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
Independent Software Vendors: 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Choosing a core focus or particular set of features and options can be tough. To help out, we’re going to highlight a handful of things your business needs on one of your social media pages. In other words, if one of these is missing, you should imp…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month5 days, 17 hours left to enroll

627 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