En  Fa
Discovering: Tips & Tricks  > Languages  > Delphi Tips  > Run an application with more control to it
 
 

Run an application with more control to it

   

Run an application with more control to it

Description

This code allows to run any application regardless of its extension with more control

Delphi code

Function RunProcess(Const AppPath:String;
    MustWait:Boolean=False;AppParams:String='';
    Visibility:Word=SW_SHOWNORMAL):DWord;
Var
  SI:TStartupInfo;
  PI:TPROCessINFORMATION;
  Proc:THandle;
  zFileName:Array[0..Max_Path*2]of char;
  zParams:Array[0..Max_Path]of char;
begin
FillChar(SI,SizeOf(SI),0);
SI.cb:=SizeOf(Si);
Si.wShowWindow:=Visibility;
If Not CreateProcess(strPCopy(zFilename,AppPath),
    StrPCopy(zParams,APpParams),
    nil,nil,False,NORMAL_PRIORITY_CLASs    ,nil,nil,SI,PI) then
  Raise EXCeption.CreateFmt('Failed to execute program '+
  apppath+'.Error Code %d',[GetlastError]);
Proc:=PI.hProcess;
CloseHandle(Pi.HThread);
If MustWait then
  If WaitForSingleObject(Proc,infinite)<>Wait_Failed then
    GetExitCodeProcess(Proc,Result);
CloseHandle(Proc);
end;

Details
      
Writer: Salar Khalilzadeh
Date Sent: 6/14/2008 7:34 AM
Views: 486
Votes: 0
Rating:   from Not Rated

Your Rating:

bookmark this
 

There is no comment for this topic.
Language:

Copyright © 2009 SoftProjects.org | About | Valid XHTML | CSS