Solved

Problems with WaitForSingleObjectEx()

Posted on 2000-03-27
9
468 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to DocumentFormat 8 74
SignTool Error with Windows 10 5 119
ClickOnce Install - Shortcut Question 3 72
How to LOAD up a .NET Framework website with data? 2 40
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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

912 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

26 Experts available now in Live!

Get 1:1 Help Now