我要在一个delphi中调用另外的exe程序,请问如何实现,给程序语句,谢谢了
解决方案 »
- EXCEL问题
- 求购:Delphi 5.X分布式多层应用系统篇/电子商务篇
- 如何在Microsoft Agent中的动画精灵上面添加右键菜单哪?
- 关于COM口的数据通信的问题,各位高手请帮帮忙!
- 如果在canvas上画条线后再删除该线但不会影响到canvas上原有的内容?
- 我的一个 paradox话费清单数据库 Telrec.db 因死机造成索引头损坏而无法打开,央求诸位专家指点如何进行修复,这个数据库对我太重要了。1
- 二进制文件的读写问题(在线等待)
- 如何在表单显示一个GIF文件?
- webbrowser疑惑
- NMHTTP控件能否边下载边读取?
- 提示midas.ddl装载出错,急用....谢谢
- 如何实现模板的问题!帮我解决了给100分 200409
CreateProcess(...)uses
ShellAPI;ShellExecute(...)
ShellExecute
有分我就接!!:)
ShellExecute
microsoft建议用后一个!
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;
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;
BEGIN
AEXE := 'C:\KK.EXE';
Winexec(Pchar(AEXE),SW_NORMAL)
END;
WinExec
ShellExecute
ShellExecute(GetDesktopWindow(), NIl, 'rundll32.exe','shell32.dll,Control_RunDLL timeDate.cpl', Nil, 0);
建议用后一种,它除了可以调用EXE外,还可以调用别的程序,比如说文本
begin
ExeFile:='执行程序名' //含绝对路径
If FileExists(ExeFile) then
WinExec(Pchar(ExeFile),SW_SHOWNORMA)
Else ShowMessage(ExeFile+' 不存在!');
end;