標籤:
一個比較完整的Inno Setup 安裝指令碼,增加了對ini檔案設定的功能,一個安裝包常用的功能都具備了。
- [Setup]
- ; 注: AppId的值為單獨標識該應用程式。
- ; 不要為其他安裝程式使用相同的AppId值。
- ; (產生新的GUID,點擊 工具|在IDE中產生GUID。)
- AppId={{A9861883-31C5-4324-BD9A-DC3271EEB675}
- ;程式名
- AppName=ISsample
- ;版本號碼
- AppVerName=ISsample 1.0.0.0
- ;發行者名
- AppPublisher=Hkiss
- ;相關串連
- AppPublisherURL=http://zwkufo.blog.163.com
- AppSupportURL=http://zwkufo.blog.163.com
- AppUpdatesURL=http://zwkufo.blog.163.com
- ;預設安裝目錄
- DefaultDirName={pf}\ISsample
- ;預設開始菜單名
- DefaultGroupName=ISsample
- ;是否開啟->可選安裝開始功能表項目
- ;AllowNoIcons=yes
- ;安裝協議
- ;LicenseFile=C:\Example\原始檔案\agreement.txt
- ;安裝前查看的文字檔
- ;InfoBeforeFile=C:\Example\原始檔案\Setup_New.txt
- ;安裝後查看文字檔
- ;InfoAfterFile=C:\Example\原始檔案\Setup_Old.txt
- ;輸出檔案夾
- OutputDir=C:\Example\InnoSetup\out
- ;輸出檔案名
- OutputBaseFilename=setup
- ;安裝表徵圖
- SetupIconFile=C:\Example\原始檔案\title.ico
- ;安裝需要輸入密碼
- ;Password=123
- ;Encryption=yes
-
- ;壓縮相關
- Compression=lzma
- SolidCompression=yes
-
- ;可以讓使用者忽略選擇語言相關
- ShowLanguageDialog = yes
- ;備忘版本資訊
- VersionInfoCompany=HTTP://www.Hkiss.COM
- VersionInfoDescription=ISsample 漢化增強版
- VersionInfoVersion=1.0.0.0
- VersionInfoCopyright=Copyright (C) 2007-2008 Hkiss
-
- ;製作選擇語言
- [Languages]
- Name: "chs"; MessagesFile: "compiler:Default.isl" ;LicenSeFile :"C:\Example\原始檔案\chs\agreement.txt"
- Name: "en"; MessagesFile: "compiler:Languages\English.isl";LicenSeFile :"C:\Example\原始檔案\en\agreement.txt"
-
- ;使用者定製任務
- [Tasks]
- Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
- Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
- Name: "Tasks_1" ; Description:"使用者自訂任務1"; Flags: unchecked
- Name: "Tasks_2" ; Description:"使用者自訂任務2"; Flags: unchecked
- ;選擇了組件才會出現的定製任務
- Name: "Tasks_3" ; Description:"使用者自訂任務3";Components: c1 ; Flags: unchecked
-
- ;檔案安裝
- [Files]
- ;多語言安裝環境設定 公用參數Languages 來設定
- Source: "C:\Example\原始檔案\enfile.txt"; DestDir: "{app}"; Languages: en ; Flags: ignoreversion
- Source: "C:\Example\原始檔案\chsfile.txt"; DestDir: "{app}"; Languages: chs ; Flags: ignoreversion
- ;使用者自訂任務 Tasks
- Source: "C:\Example\原始檔案\Tasks\tasks_1.txt"; DestDir: "{app}\Tasks"; Flags: ignoreversion ;Tasks : Tasks_1
- Source: "C:\Example\原始檔案\Tasks\tasks_2.txt"; DestDir: "{app}\Tasks"; Flags: ignoreversion ;Tasks :Tasks_2
- Source: "C:\Example\原始檔案\Tasks\tasks_Components.txt"; DestDir: "{app}\Tasks"; Flags: ignoreversion ;Tasks :Tasks_2
- ;使用者定義組件安裝
- Source: "C:\Example\原始檔案\Components\Components_1.txt"; DestDir: "{app}\Components"; Flags: ignoreversion ; Components: a1;
- Source: "C:\Example\原始檔案\Components\Components_2.txt"; DestDir: "{app}\Components"; Flags: ignoreversion ; Components: a2;
- Source: "C:\Example\原始檔案\Components\Components_3.txt"; DestDir: "{app}\Components"; Flags: ignoreversion ; Components: a3;
- Source: "C:\Example \原始檔案\Components\Components_4.txt"; DestDir: "{app} \Components"; Flags: ignoreversion ; Components: a1 a2 a3;
-
- ;使用者註冊自訂Dll檔案 regserver 註冊 noregerror 不顯示錯誤資訊
- Source: "C:\Example\原始檔案\jmail.dll"; DestDir: "{app}"; Flags: ignoreversion regserver
- ;添加讀我檔案
- Source: "C:\Example\原始檔案\ISsample.txt"; DestDir: "{app}"; Flags: ignoreversion
- ;添加一個檔案到快取檔案夾{Tmp} deleteafterinstall 安裝後刪除
- Source: "C:\Example\原始檔案\test.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall
-
- Source: "C:\Example\原始檔案\ISsample.chm"; DestDir: "{app}"; Flags: ignoreversion
- Source: "C:\Example\原始檔案\ISsample.exe"; DestDir: "{app}"; Flags: ignoreversion
- Source: "C:\Example\原始檔案\ISsample.dll"; DestDir: "{app}"; Flags: ignoreversion
- Source: "C:\Example\原始檔案\ISsample.ini"; DestDir: "{app}"; Flags: ignoreversion
- Source: "C:\Example\原始檔案\ISsample.rar"; DestDir: "{app}"; Flags: ignoreversion
- Source: "C:\Example\原始檔案\ISsample_sys.dll"; DestDir: "{win}\System32"; Flags: ignoreversion
- Source: "C:\Example\原始檔案\log\*"; DestDir: "{app}\log"; Flags: ignoreversion recursesubdirs createallsubdirs
- ; 注意: 不要在任何共用系統檔案上使用“Flags: ignoreversion”
- ;安裝類型設定
- [Types]
- Name: Full ;Description:"完整安裝"; Flags: iscustom
- Name: Compact ;Description:"簡潔安裝";
- Name: Custom; Description:"自訂安裝";
- ;組件安裝
- [Components]
- Name: c1; Description: "自訂任務3" ; Types: Full
- Name: a1; Description: "安裝Components_1"; Types: Full Compact Custom ;
- Name: a2; Description: "安裝Components_2"; Types : Full Compact
- Name: a3; Description: "安裝Components_3"; Types : Full
-
- ;開始菜單,案頭捷徑
- [Icons]
- Name: "{group}\ISsample"; Filename: "{app}\ISsample.exe"
- Name: "{group}\{cm:ProgramOnTheWeb,ISsample}"; Filename: "http://zwkufo.blog.163.com"
- Name: "{group}\{cm:UninstallProgram,ISsample}"; Filename: "{uninstallexe}"
- Name: "{commondesktop}\ISsample"; Filename: "{app}\ISsample.exe"; Tasks: desktopicon
- Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\ISsample"; Filename: "{app}\ISsample.exe"; Tasks: quicklaunchicon
- ;添加一個協助文擋
- Name: {group}\ISsample 1.0.0.0 協助文檔;Filename: {app}\ISsample.chm
-
- ;用來在程式安裝完成後 在安裝程式顯示最終對話方塊之前執行程式 常用與運行主程式 顯示讀我檔案 刪除臨時檔案
- [Run]
- Filename: "{app}\ISsample.exe"; Description: "{cm:LaunchProgram,ISsample}"; Flags: nowait postinstall skipifsilent
- Filename: "{app}\ISsample.txt"; Description: "查看顯示讀我檔案"; Flags: postinstall skipifsilent shellexec
-
- ;更改顯示在程式中顯示的訊息文本
- [Messages]
- BeveledLabel=HKiss科技
- ;卸載對話方塊說明
- ConfirmUninstall=您真的想要從電腦中卸載ISsample嗎?%n%n按 [是] 則完全刪除 %1 以及它的所有組件;%n按 [否]則讓軟體繼續留在您的電腦上.
- ;定義解壓說明
- ;StatusExtractFiles=解壓並複製主程式檔案及相關庫檔案...
-
- ;用於在使用者系統中建立,修改或刪除ini檔案健值
- [INI]
- Filename: "{app}\cfg.ini"; Section: "Startup Options"; Flags: uninsdeletesection
- Filename: "{app}\cfg.ini"; Section: "Startup Options"; Key: "server ip"; String: "127.0.0.1"
- Filename: "{app}\cfg.ini"; Section: "Startup Options"; Key: "server port"; String: "8080"
-
- ;用於在使用者系統中建立,修改或刪除註冊表健值
- [Registry]
- Root: HKLM ;SubKey:"Software\ISsample";ValueType:dword;ValueName:config;ValueData:10 ;Flags:uninsdeletevalue
- ;在執行指令碼
- [code]
- //全域變數
- var MyProgChecked: Boolean;
-
- //判斷程式是否存在
- //初始華程式事件
- function InitializeSetup(): boolean;
- var Isbl: boolean; //聲明變數
- var Isstr: string;
- begin //開始
- Isbl := true; //變數賦值
- Isstr := ‘歡迎‘;
- if RegValueExists(HKEY_LOCAL_MACHINE, ‘SOFTWARE\ISsample‘, ‘config‘) then
- begin
- MsgBox(‘已安裝過,請先卸載在安裝‘,mbConfirmation, MB_OK);
- isbl := false;
- end else
- begin
- //MsgBox(‘無值‘,mbConfirmation, MB_OK);
- isbl := true;
- end;
-
- //下面是個麻煩的 條件陳述式 end else 注意
- //if MsgBox(Isstr, mbConfirmation, MB_OKCANCEL) = IDOK then
- //begin
- // isbl := true;
- // MsgBox(‘執行了‘, mbConfirmation, MB_OK);
- //end else
- //begin
- // isbl := false;
- //MsgBox(‘執行了‘, mbConfirmation, MB_OK);
- //end;
-
- Result := Isbl;
- end; //結束
-
- procedure CurStepChanged(CurStep: TSetupStep);
- var Isstr :string;
- begin
- if CurStep=ssInstall then //實際安裝前調用
- begin
- //MsgBox(‘CurStepChanged:實際安裝前調用‘, mbConfirmation, MB_OKCANCEL); //安裝完成後調用
- end;
- if CurStep=ssPostInstall then
- begin
- Isstr := ExpandConstant(‘{tmp}\tmp.rar‘);
- // if FileExists(Isstr) then
- // begin
- // MsgBox(‘檔案存在‘,mbConfirmation, MB_OK);
- // end else
- // begin
- // MsgBox(‘檔案不存在‘,mbConfirmation, MB_OK);
- // end;
- // MsgBox(‘CurStepChanged:實際安裝後調用‘, mbConfirmation, MB_OKCANCEL);
- end;
- end;
-
- //下一步 按鈕按鈕 事件
- function NextButtonClick(CurPageID: Integer): Boolean;
- var ResultCode: Integer;
- var IsSetup : Boolean;
- begin
- IsSetup := true ;
- case CurPageID of
- wpSelectDir:
- MsgBox(‘NextButtonClick:‘ #13#13 ‘You selected: ‘‘‘ + WizardDirValue + ‘‘‘.‘, mbInformation, MB_OK); //WizardDirValue 路徑
- wpSelectProgramGroup:
- MsgBox(‘NextButtonClick:‘ #13#13 ‘You selected: ‘‘‘ + WizardGroupValue + ‘‘‘.‘, mbInformation, MB_OK); //開始菜單名
- wpReady:
- begin
- if not RegValueExists(HKEY_LOCAL_MACHINE, ‘SOFTWARE\Test‘, ‘config‘) then begin
- if MsgBox(‘程式執行需要Test.ext,是否安裝!‘, mbConfirmation, MB_YESNO) = idYes then begin
- ExtractTemporaryFile(‘test.exe‘);
- if not Exec(ExpandConstant(‘{tmp}\test.exe‘), ‘‘, ‘‘, SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
- MsgBox(‘Test.exe出錯:‘ #13#13 ‘ ‘ + SysErrorMessage(ResultCode) + ‘.‘, mbError, MB_OK);
- end else begin
- IsSetup := false ;
- end ;
- BringToFrontAndRestore();
- end;
- end;
- end;
- Result := IsSetup;
- end;
一個比較完整的Inno Setup 安裝指令碼(轉)