Help About createprocess

Help About createprocess

Post by ston » Tue, 05 Dec 2000 13:00:52



Hello !
I must run another application in delphi app, and waiting for that
application exit.
the program codes  are showed below:

var
  cmdline:string;
    bCreateProcess: boolean;
    lpStartupInfo: TStartupInfo;
    lpProcessInformation: TProcessInformation;
begin
      cmdline:='C:\WINDOWS\CALC.EXE';
      bCreateProcess := CreateProcess( PChar(cmdline),nil,
                     nil, nil, True,               NORMAL_PRIORITY_CLASS,
nil, nil,
                     lpStartupInfo, lpProcessInformation);
      if bCreateProcess then
         WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);
end;

The return value bCreateProcess is always false  ,and the .EXE can't be
actived.
Why??
        Thanks.

 
 
 

Help About createprocess

Post by M.H. Avegaar » Sun, 31 Dec 1899 09:00:00


Use:

// Run application and wait for it to finish, return the exit code
function RunAndWait(const FileName: String): DWORD;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  Result := STILL_ACTIVE;
  GetStartupInfo(StartupInfo);
  if CreateProcess(nil, PChar(FileName), nil, nil, IsConsole,
    NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
  try
    if WaitForSingleObject(ProcessInfo.hProcess, INFINITE) = WAIT_OBJECT_0
then
      GetExitCodeProcess(ProcessInfo.hProcess, Result);
  finally
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
  end;
end;



Quote:> Hello !
> I must run another application in delphi app, and waiting for that
> application exit.
> the program codes  are showed below:

> var
>   cmdline:string;
>     bCreateProcess: boolean;
>     lpStartupInfo: TStartupInfo;
>     lpProcessInformation: TProcessInformation;
> begin
>       cmdline:='C:\WINDOWS\CALC.EXE';
>       bCreateProcess := CreateProcess( PChar(cmdline),nil,
>                      nil, nil, True,               NORMAL_PRIORITY_CLASS,
> nil, nil,
>                      lpStartupInfo, lpProcessInformation);
>       if bCreateProcess then
>          WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);
> end;

> The return value bCreateProcess is always false  ,and the .EXE can't be
> actived.
> Why??
>         Thanks.


 
 
 

Help About createprocess

Post by ston » Wed, 06 Dec 2000 11:35:38


Thank you Mr.  M.H. Avegaart.

>Use:

>// Run application and wait for it to finish, return the exit code
>function RunAndWait(const FileName: String): DWORD;
>var
>  StartupInfo: TStartupInfo;
>  ProcessInfo: TProcessInformation;
>begin
>  Result := STILL_ACTIVE;
>  GetStartupInfo(StartupInfo);
>  if CreateProcess(nil, PChar(FileName), nil, nil, IsConsole,
>    NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
>  try
>    if WaitForSingleObject(ProcessInfo.hProcess, INFINITE) = WAIT_OBJECT_0
>then
>      GetExitCodeProcess(ProcessInfo.hProcess, Result);
>  finally
>    CloseHandle(ProcessInfo.hThread);
>    CloseHandle(ProcessInfo.hProcess);
>  end;
>end;



>> Hello !
>> I must run another application in delphi app, and waiting for that
>> application exit.
>> the program codes  are showed below:

>> var
>>   cmdline:string;
>>     bCreateProcess: boolean;
>>     lpStartupInfo: TStartupInfo;
>>     lpProcessInformation: TProcessInformation;
>> begin
>>       cmdline:='C:\WINDOWS\CALC.EXE';
>>       bCreateProcess := CreateProcess( PChar(cmdline),nil,
>>                      nil, nil, True,               NORMAL_PRIORITY_CLASS,
>> nil, nil,
>>                      lpStartupInfo, lpProcessInformation);
>>       if bCreateProcess then
>>          WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);
>> end;

>> The return value bCreateProcess is always false  ,and the .EXE can't be
>> actived.
>> Why??
>>         Thanks.