• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:



I have a small problem. I use the API waitforsingleobject.
I makeing a program that runs MS Publisher 97 Setup prog. with some switches (/qt (means quietmode)). But wenn I start the program and press the button that starts the installtionprog. And the program is started. But it hangs wenn it should look for installed objects....

Anyone know what the problem is? It's Delphi or Publisher that bugs, or?

I use Delphi 2.0.....

  • 3
  • 2
1 Solution
Have you checked whether or not the installation program also locks up when you run it seperately, and not from within your D2 application??
If it also locks up when you run it seperately, then it is not your delphi application...

TimeManAuthor Commented:

I have test that. It is not locking...

Send me a snippet of your code and I'll tell you whats wrong with it.

Things to check:
1. Is your WaitForSingleObject set to time-out or not?
2. Are you using the CreateProcess to execute your program (and detecting if its done with WaitForSingleObject?)

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

TimeManAuthor Commented:

Here it comes


function WinExecAndWait32(FileName:String; Visibility : integer):integer;
   zAppName: array[0..512] of char;
   zCurDir: array[0..255] of char;
   WorkDir: string;
   StartupInfo: TStartupInfo;
   ProcessInfo: TProcessInformation;
   StartupInfo.cb := Sizeof(StartupInfo);
   StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
   StartupInfo.wShowWindow := Visibility;
   if not CreateProcess(nil,
      zAppName,    { pointer to command line string }
      nil,         { pointer to process security attributes }
      nil,         { pointer to thread security attributes }
      false,       { handle inheritance flag }
      CREATE_NEW_CONSOLE or  { creation flags }
      nil,         { pointer to new environment block }
      nil,         { pointer to current directory name }
      StartupInfo, { pointer to STARTUPINFO }
      ProcessInfo) then Result := -1 { pointer to PROCESS_INF }
      WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
      GetExitCodeProcess(ProcessInfo.hProcess, Result);

procedure TForm1.Button1Click(Sender: TObject);
WinExecAndWait32 ('c:\temp\pub\setup.exe /qt',0);
Your app was doing okay, but it wasnt proceessing any messages (keyboard, screen refresh, etc) and the setup program was probably taking too long, so it seemed like your program was locked up (it is! but the setup program, running quietly wasnt)

your app locked up because of the following line:

>> WaitForSingleObject( ProcessInfo.hProcess, INFINITE );

I modified a portion of your code to make it a little bit more user friendly.

First, I added a local variable in your WinExecAndWait32 method

>> var                     // additional variables
>>   dwWait : DWORD;       //

Second, I modified the portion where you WaitForSingleObject so that app messages are processed while the object is signaled
(1000 means, it processes app messages every 1 second)

>> repeat
>>   dwwait := WaitForSingleObject( ProcessInfo.hProcess, 1000 );
>>   GetExitCodeProcess(ProcessInfo.hProcess, Result);
>>   Application.ProcessMessages;
>> until dwwait <> WAIT_TIMEOUT;

And last, If you don't want the user to be able to do anything else while your setup program is running (or to prevent them from doing anything stupid) you'll need to have something like this when invoking the WinExecAndWait32 method

>> procedure TForm1.BitBtn1Click(Sender: TObject)
>> const
>>   bInWait: boolean = False;
>> var
>>   Result : Integer;
>> begin
>>   //  don't launch MYPROGRAM.EXE if we are already
>>   //  waiting for MYPROGRAM.EXE to  finish
>>   if bInWait then Exit;
>>   // notify ourself that we have launched MYPROGRAM.EXE
>>   bInWait := True;
>>   try
>>     // launch MYPROGRAM.EXE
>>     Result := WinExecAndWait32( 'C:\MYPROGRAM.EXE', 0 );
>>   finally
>>     case Result of
>>     // check Result for errors
>>     end;      
>>     // notify ourself that we're done messing around
>>     // with MYPROGRAM.EXE
>>     bInWait := False;
>>   end;
>> end;

I tested the above modification and it worked perfectly, running different setup programs, as well as some time-critical apps I've written.

I hope this got to you in time to be useful.


TimeManAuthor Commented:

I havent test it yet...but it seems to work better than mine...


Featured Post

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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now