ExecuteProcess - with Command Line Support

王朝delphi·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

ExecuteProcess - with Command Line Support

This proc is a Delphi wrapper around

the Win32 API "CreateProcess". It is

a better idea to use this instead of

ShellExecute or other 16-bit functions when you're program is to

run in a 32-bit environment

procedure ExecuteProcess(FileName: String;

Params: String; Show: Integer);

var

StartUpInfo: TStartUpInfo;

ProcessInfo: TProcessInformation;

begin

if Params[1] <> ' ' then

Params := ' ' + Params;

FillChar(StartUpInfo, SizeOf(TStartUpInfo), 0);

with StartUpInfo do

begin

cb := SizeOf(TStartUpInfo);

dwFlags := STARTF_USESHOWWINDOW;

wShowWindow := Show;

end;

if not (CreateProcess(PChar(FileName), PChar(Params),

nil, nil, False, NORMAL_PRIORITY_CLASS,

nil, nil, StartUpInfo, ProcessInfo))

then

RaiseLastWin32Error;

end;

//Modified version of ExecuteProcess that works with

//a Command-Line Parameter

procedure ExecuteProcess( FileName,

Params : String;

Show : Integer );

var

StartUpInfo: TStartUpInfo;

ProcessInfo: TProcessInformation;

begin

Params := Trim(Params);

if Params<>'' then

FileName := FileName + ' ' + Params;

GetStartupInfo( StartUpInfo );

with StartUpInfo do begin

cb := SizeOf(TStartUpInfo);

dwFlags := STARTF_USESHOWWINDOW;

wShowWindow := Show;

end;

if not (CreateProcess( nil, PChar(FileName), nil,

nil, False, NORMAL_PRIORITY_CLASS, nil,

nil, StartUpInfo, ProcessInfo))

then

RaiseLastWin32Error; //From SysUtils Unit

end;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航