var ExeFile:String;
begin
ExeFile:='执行程序名' //含绝对路径
If FileExists(ExeFile) then
WinExec(Pchar(ExeFile),SW_SHOWNORMA)
Else ShowMessage(ExeFile+' 不存在!');
end;
CreateProcess调用
function runprocbycmd(cmd:string):integer;
var
sInfo : TStartupInfo;
pInfo : TProcessInformation;
exitCode : Cardinal;
begin
SetCurrentDir(getworkpath);
try
FillChar(sInfo,sizeof(sInfo),#0);
sInfo.cb := SizeOf(sInfo);
sInfo.dwFlags := STARTF_USESHOWWINDOW;
sInfo.wShowWindow := SW_NORMAL;
if not CreateProcess(nil,pchar(cmd),nil,nil,false,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, sInfo, pInfo) then
MessageBox(Application.handle,pchar(srunprocfalse),pchar(serror),MB_OK or MB_ICONSTOP)
else
begin
WaitForSingleObject(pInfo.hProcess,INFINITE);
GetExitCodeProcess(pInfo.hProcess,exitCode);
end;
finally
result:=exitCode;
end;
end;
function ExecFile(s:string): Integer;
var
ShellExecInfo: TShellExecuteInfo;
begin
if s<> '' then
begin
ZeroMemory(@ShellExecInfo, SizeOf(TShellExecuteInfo));
with ShellExecInfo do
begin
cbSize := SizeOf(TShellExecuteInfo);
Wnd := Application.Handle;
lpFile := PChar(s);
ShellExecInfo.lpDirectory:=pchar(ExtractFilePath(s));
nShow:=SW_SHOW;
end;
ShellExecuteEx(@ShellExecInfo);
end;
result:=0;
end;