怎样用Delphi中的一个按钮执行系统中的一个.exe程序(50分)

  • 主题发起人 主题发起人 葡萄
  • 开始时间 开始时间

葡萄

Unregistered / Unconfirmed
GUEST, unregistred user!
望高手指点~~
 
winexec('calc.exe',SW_SHOW)
 
uses ShellApi;<br><br>ShellExecute(handle,nil,pchar('yourfile.exe'),nil,nil,sw_shownormal);
 
uses Shellapi;<br><br>shellexecute(handle,nil,pchar('calc.exe'),nil,nil,sw_shownormal);
 
uses WinProcs; &nbsp; <br>&nbsp;<br>begin &nbsp; <br>&nbsp;WinExec(......); &nbsp; <br>&nbsp;...<br>end. &nbsp; <br>
 
&nbsp;ShellExecute( self.Handle &nbsp;,nil, 'calc.exe' , nil,nil,SW_SHOW);
 
shellexecute(handle,nil,pchar('notepad.exe'),nil,nil,sw_shownormal);
 
procedure TLYMain.b1Click(Sender: TObject);<br>var<br>&nbsp; Handle1: Integer;<br>&nbsp; path:string;<br>begin<br>&nbsp; handle1 := findwindow('Tform',nil);// 解决程序重入问题<br>&nbsp; if handle1 &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('已经启动!');<br>&nbsp; end else<br>&nbsp; begin<br>&nbsp; &nbsp; path:=ExtractFilePath(application.ExeName);<br>&nbsp; &nbsp; if not fileexists(path+'*.exe') then<br>&nbsp; &nbsp; &nbsp; showmessage('在路径 " '+path+' " 下没找到程式!');<br>&nbsp; &nbsp; ShellExecute(handle, 'open', pchar(path+'*.exe'),'','', sw_show);<br>&nbsp; end;<br>end;
 
提醒一句,记得加uses ShellApi;<br>:)
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, ShellAPI;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp;<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br><br>ShellExecute(handle,'open','notepad.exe',nil,nil,SW_ShowNormal);<br><br>end;<br><br><br><br>end.
 
还有采用createprocess
 
winexec('exe的具体路径',SW_SHOW)
 
用ShellExecute舒服
 
大家都说了,我也没什么好说的了.
 
后退
顶部