请问在DELPHI中如何调用当前目录下的可执行文件?

hudspping 2003-08-18 03:42:46
请问诸位高手,我想执行当前目录下的一个EXE文件,需要怎样做才可以实现?
谢谢。
...全文
71 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
Spqk005 2003-08-18
  • 打赏
  • 举报
回复
不会吧
如下
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi;//就加在这边就OK了
hudspping 2003-08-18
  • 打赏
  • 举报
回复
成功,谢谢。
hudspping 2003-08-18
  • 打赏
  • 举报
回复
我怎么加不上呢?
Spqk005 2003-08-18
  • 打赏
  • 举报
回复
你只要把shellapi加到uses 列表中
就可以编译通过!
hudspping 2003-08-18
  • 打赏
  • 举报
回复
请问如何用SHELLAPI编译SHELLEXECUTE
overtime 2003-08-18
  • 打赏
  • 举报
回复
winexec
Spqk005 2003-08-18
  • 打赏
  • 举报
回复
请uses shellapi才能编译ShellExecute

procedure TFDemo.Button2Click(Sender: TObject);
var
path:PChar;
begin
//ce为当前目录下的那个文件夹
path:=Pchar(ExtractFilePath(Application.ExeName)+'ce\calc.exe');
ShellExecute(handle,'open',path,'','', SW_SHOWNORMAL);
end;


程序调试通过,calc.exe为ce目录下的计算器程序
那个可执行目录你可以自己定义
Spqk005 2003-08-18
  • 打赏
  • 举报
回复
请uses shellapi

程序调试通过,calc.exe为ce目录下的计算器程序
Spqk005 2003-08-18
  • 打赏
  • 举报
回复
procedure TFDemo.Button2Click(Sender: TObject);
var
path:PChar;
begin
//ce为当前目录下的那个文件夹
path:=Pchar(ExtractFilePath(Application.ExeName)+'ce\calc.exe');
ShellExecute(handle,'open',path,'','', SW_SHOWNORMAL);
end;
hudspping 2003-08-18
  • 打赏
  • 举报
回复
不好意思,对此帖进行更正,我是想执行当前目录下的一个文件夹下的EXE文件,试了几次总是不行抱歉。
IORILI 2003-08-18
  • 打赏
  • 举报
回复
uses shellapi
ShellExecute(handle,'open','readme.txt','','', SW_SHOWNORMAL);
swxwy 2003-08-18
  • 打赏
  • 举报
回复
winexec;
shellexceute;
shellexceute 需要加入shellipa单元
我不懂电脑 2003-08-18
  • 打赏
  • 举报
回复
ShellExecute
lynew 2003-08-18
  • 打赏
  • 举报
回复
WinExec(lpCmdLine:PChar;uCmdShow:Cardinal);
2312 2003-08-18
  • 打赏
  • 举报
回复

path:=ExtractFilePath(Application.ExeName)+'abc.exe';

winexec(path);
newsofter 2003-08-18
  • 打赏
  • 举报
回复
ExeFileName :=ExtractFilePath(Paramstr(0))+'exe文件名'
例:E:\data\mm.exe
执行:
winexec(ExeFileName,SW_SHOWDEFAULT);
bluemeteor 2003-08-18
  • 打赏
  • 举报
回复
先用path=ExtractFilePath(Application.ExeName));得到当前应用程序所在的路径

然后run=path+"文件名";

最后是运行:

WinExeC,最简单,但是它只能调用可执行程序;
  ShellExecute,可以启动某一可执行程序,也可以启动与你给出的文件相关联的应用程序;
  ShellExecuteEx,和上两者相似,不过传递的参数不一样。

bluemeteor 2003-08-18
  • 打赏
  • 举报
回复
先用path=ExtractFilePath(Application.ExeName));得到当前应用程序所在的路径

然后run=path+"文件名";

最后是运行:

WinExeC,最简单,但是它只能调用可执行程序;
  ShellExecute,可以启动某一可执行程序,也可以启动与你给出的文件相关联的应用程序;
  ShellExecuteEx,和上两者相似,不过传递的参数不一样。

DWGZ 2003-08-18
  • 打赏
  • 举报
回复
抢不到分了
Spqk005 2003-08-18
  • 打赏
  • 举报
回复
ShellExecute(

HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);

查查help下面的WINDOWS SDK
加载更多回复(2)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧