Solved

Problems with WaitForSingleObjectEx()

Posted on 2000-03-27
9
476 Views
Last Modified: 2013-12-03
HI
I am writing a quick app to launch in the auto-run on a CD.
First of all it tests to see if Acrobat Reader is installed by checking if a registry key exists. If true, then it will just launch the "Contents.pdf" file.
If not a message box appears & if OK is selected will launch the reader's setup program.
What I want to do is wait for the setup to finish, THEN launch the "Contents.pdf" file.
I have tried using the WaitForSingleObjectEx() function but it returns immeidiatly.
Any ideas please. Here is my code,
It is written on BCB4 using the VCL for the TRegistry Object:
        TRegistry *Reg = new TRegistry;
        char Instructions[]="\"Adobe Acrobat Reader\" does not appear to be installed on your computer.\nClick 'OK' to install the latest version of the reader.\nIf you click 'Cancel' you will not be able to view the contents of this CDROM.\n";
        PROCESS_INFORMATION pInfo;

        Reg->RootKey = HKEY_LOCAL_MACHINE;
        if(!Reg->KeyExists("Software\\Adobe\\Acrobat"))
        {
        if(IDOK      == MessageBox(Application->Handle,Instructions,"Renault Technical Manual CDROM",MB_OKCANCEL))
        {

        ar40engHandle = ShellExecute(Application->Handle, "open", "Ar40eng.exe", NULL, NULL, SW_NORMAL);
        WaitForSingleObjectEx(
    ar40engHandle,      // handle of object to wait for
    INFINITE,      // time-out interval in milliseconds
    false       // return to execute I/O completion routine if TRUE
   );
   }
   else
        {
        return 0;
        }
   }

        ShellExecute (Application->Handle, "open", "Contents.pdf", NULL, NULL, SW_NORMAL);
        return 0;
0
Comment
Question by:dsch
[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
  • 3
9 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 150 total points
ID: 2660422
You have to use ShellExecuteEx and wait on a process handle.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2660425
Specify SEE_MASK_NOCLOSEPROCESS for SHELLEXECUTEINFO.fMask.

Call WaitFor...(SHELLEXECUTEINFO.hProcess).

Don't forget to CloseHandle(SHELLEXECUTEINFO.hProcess).
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2660432
Something like this:

SHELLEXECUTEINFO s;
s.cbSize=sizeof(SHELLEXECUTEINFO);
s.fMask=SEE_MASK_NOCLOSEPROCESS;
s.hwnd=Application->Handle;
s.lpVerb=0;
s.lpFile="Ar40eng.exe";
s.lpParameters=0;
s.lpDirectory=0;
s.nShow=0;

ShellExecuteEx(&s);

WaitForSingleObject(s.hProcess,INFINITE)
CloseHandle(s.hProcess);
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 15

Expert Comment

by:NickRepin
ID: 2660476
For this particular case (just run an exe) I'd use the CreateProcess instead of ShellExecute.
But probably that doesn't matter.
0
 
LVL 1

Author Comment

by:dsch
ID: 2676674
Thanks Nick,
That works fine.
I do have a problem however, but I think it is a problem with the acrobat setup program.
After it has unpacked the files it has to launch the instalshield program.
For some reason, it cannot start this when my app is still running.  I have made sure that the handle can be inherited (even by trying CreateProcess) but still no joy.  I think my only other option is to close the handle after it is created, start another Thread with a timer and then to check to see it the program is still running. (I havn't tried it though).
Any-way thanks for your help & c u around.
Kind Regards
David
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2676684
It all is not clear for me.
Acrobat setup does some job and then launch the installshield. But install shield does not appear while you are waiting on the acrobat handle. Is that right?
And ishield appears once you closed the handle?
0
 
LVL 1

Author Comment

by:dsch
ID: 2679297
Yes
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2679732
That's strange.
Sorry, cannot help you more.
0
 
LVL 1

Author Comment

by:dsch
ID: 2682941
Cheers anyway,
What I ahve had to do, is close my program after giving a message that 'after installation, eject then replace the CD' (autorun)
Thanks for all your help, it has taught me a bit more as well.
Bye for now
David
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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