用这个研究研究HINSTANCE 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 );
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
);
DELPHI怎样调用WINRAR压缩文件http://www.anywolfs.com/liuhui/article.asp?id=256
WINRAR命令行简体中文说明
delphi调用winrar好弄,关键问题是,那一堆的自解压参数写在哪
参数写这里
LPCTSTR lpParameters,
你说的参数是WinRAR.exe S -ibck -r -k -o+ -y 1.EXE bin\*.* 后面的这些参数吧,我说的参数是自解压命令中的参数,比如解压后运行,执行程序图标,快捷方式等,如下
Path=c:\Bin6
SavePath
Setup=UpGrade.exe
Title=********系统
Text
{
******系统
}
Shortcut=D, "main.exe", "", "******系统", "******系统", "main.exe"
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(0, 'open', 'C:\Program Files\WinRAR\WinRar.exe', 'a abc.rar Unit1.pas', 0, SW_SHOW );
end;end.
请注意,我要做的是自解压文件,不是压缩包
那自解压的那些参数呢,怎么设置
所有的命令行参数都在里边
x 带绝对路径解压 例子: rar x -av- -c- dime 10cents.txt 解压指定的文件到当前路径。AV 检查和注释显示被禁用。
rar: String;
MyFile: String;
desc: TStringList;
hi: HICON;
ico: TICON;
begin
OpenDialog1.Title := '请选择Winrar.exe';
OpenDialog1.FileName := 'winrar.exe';
OpenDialog1.Filter := 'Winrar.exe|winrar.exe';
OpenDialog1.Options := [ofPathMustExist, ofFileMustExist];
if Not OpenDialog1.Execute then Exit;
rar := OpenDialog1.FileName;
OpenDialog1.Title := '请选择打包的可执行文件';
OpenDialog1.FileName := 'project1.exe';
OpenDialog1.Filter := '*.exe|*.exe';
if Not OpenDialog1.Execute then Exit;
MyFile := OpenDialog1.FileName;
desc := TStringList.Create;
try
desc.Add('Title=Test self Extract');
desc.Add('Silent=1');
desc.Add('TempMode');
desc.Add('Setup='+ExtractFileName(MyFile));
desc.Add('Overwrite=1');
desc.SaveToFile('mydesc.txt');
hi:=ExtractIcon( HInstance,PAnsiChar(Application.ExeName),0);
ico := TIcon.Create;
try
ico.Handle := hi;
ico.SaveToFile('myico.ico');
finally
ico.Free;
end;
Shellexecute(Handle,'open',PAnsiChar('"'+rar+'"'),PAnsiChar('a -ibck -zmydesc.txt -iiconmyico.ico -ep -sfx '+ChangeFileExt( ExtractFileName(MyFile), '.sfx.exe')+' "'+MyFile+'"'),Nil,SW_SHOW);
Shellexecute(Handle,'open','explorer.exe','.\',Nil,SW_SHOW);
finally
desc.Free;
end;
end;