INF安装例子
;
[Setup]
; 注意: AppId 的值是唯一识别这个程序的标志。
; 不要在其他程序中使用相同的 AppId 值。
; (在编译器中点击菜单“工具 -> 产生 GUID”可以产生一个新的 GUID)
AppId={{DC1559D2-A4CC-471F-8FDF-45F4278AFAEA}
AppName=我的程序
AppVerName=我的程序 1.5
AppPublisher=我的公司
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
DefaultDirName={pf}\我的程序
DefaultGroupName=我的程序
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Languages]
Name: "chinese"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "test.inf"; Flags: dontcopy
[code]
//安装inf的函数
function InstallInf(const InfFile, InfSection: string): Boolean;
var
ResultCode: Integer;
begin
if Exec(ExpandConstant('{sys}\rundll32.exe'), 'advpack.dll,LaunchINFSection '+AddQuotes(ExpandConstant(InfFile))+','+ExpandConstant(InfSection), ExpandConstant('{src}'), SW_HIDE, ewWaitUntilTerminated, ResultCode) then
{如果上面的代码有问题,就改用下面这行}
// if Exec(ExpandConstant('{sys}\rundll32.exe'), 'setupapi,InstallHinfSection '+ExpandConstant(InfSection)+' 132 '+AddQuotes(ExpandConstant(InfFile)), ExpandConstant('{src}'), SW_HIDE, ewWaitUntilTerminated, ResultCode) then
Result:= (ResultCode = 1); {假设正常安装的返回代码是1的话}
end;
//定义按钮和要执行的操作
procedure MyButtonOnClick(Sender: TObject);
var
tmpinf, srcinf: String;
bbb: Boolean;
begin
tmpinf:= ExpandConstant('{tmp}\test.inf');
srcinf:= ExpandConstant('{src}\test.inf');
ExtractTemporaryFile('test.inf'); //解压文件
if RenameFile(tmpinf, srcinf) then //移动文件到程序所在目录
if InstallInf(srcinf, 'DefaultInstall') then
//ShellExec('Install', srcinf, '', ExpandConstant('{src}'), SW_SHOW, ewWaitUntilTerminated, ResultCode) then //安装inf
bbb := True;
//处理返回代码
if bbb then
MsgBox('安装成功!!', mbInformation, MB_OK) else
begin
MsgBox('安装失败!!', mbCriticalError, MB_OK);
end;
DeleteFile(srcinf);
end;
//创建按钮
procedure InitializeWizard();
var
MyButton: TButton;
begin
with WizardForm do
begin
MyButton := TButton.Create(WizardForm);
with MyButton do begin
Left := ScaleX(208);
Top := ScaleX(192);
Width := ScaleX(75);
Height := ScaleX(23);
Caption := '安装inf';
OnClick := @MyButtonOnClick; //按钮点击事件
Parent := WizardForm;
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
var
ResultCode: Integer;
begin
if CurPageID = wpWelcome then
WizardForm.NextButton.Enabled:= False; //禁用下一步按钮
end;