一個比較完整的Inno Setup 安裝腳本

[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;

 ------------------以下爲迅雷的安裝腳本-----------------


[Setup]

AppName=迅雷5

AppVerName=迅雷 5.7.2.371 DDR1.5 去廣告版

DefaultDirName={pf}\Thunder\

DefaultGroupName=迅雷5

OutputbaseFilename=Thunder-ddr5.7.2.371Setup

Compression=lzma

SolidCompression=yes

WizardImageFile=embedded\WizardImage.bmp

WizardSmallImageFile=embedded\WizardSmallImage.bmp

AppMutex=thunder5_app_mutex

[Types]

Name: "default"; Description: "默認安裝"

Name: "custom"; Description: "自定義安裝"; Flags: iscustom

Name: "full"; Description: "完全安裝"

[Components]

Name: "main"; Description: "迅雷5"; Types:default custom full; Flags: fixed

Name: "Plugins"; Description: "其他插件"; Types: full

Name: "Plugins\kankan"; Description: "迅雷看看"; Types: full

Name: "Plugins\gougou"; Description: "狗狗搜索排行"; Types: full

Name: "Plugins\tingting"; Description: "迅雷聽聽1.2"; Types: full

[Tasks]

Name: desktopicon; Description: "創建桌面快捷方式"; Flags: checkedonce

Name: associate; Description: "在開始菜單創建程序組";Flags: checkedonce

[Files]

;主文件安裝

Source: "pureThunder\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs ignoreversion

;配置文件安裝

Source: "Profiles\*"; DestDir: "{app}\Profiles"; Flags:uninsneveruninstall onlyifdoesntexist

;註冊文件安裝

Source: "comfile\*"; DestDir: "{app}\ComDlls"; Flags:ignoreversion regserver restartreplace uninsrestartdelete

;迅雷看看安裝

Source: "KanKan\files\*"; DestDir: "{app}\Components\KanKan"; Components: Plugins\kankan; Flags:ignoreversion

Source: "KanKan\regdll\*"; DestDir: "{app}\Components\KanKan"; Components: Plugins\kankan; Flags:ignoreversion regserver restartreplace uninsrestartdelete

;狗狗搜索安裝

Source: "plugins\GouGouTop\*"; DestDir: "{app}\plugins\GouGouTop";Components: Plugins\gougou; Flags: ignoreversion

;聽聽安裝

Source: "plugins\TingTing\*"; DestDir: "{app}\plugins\TingTing";Components: Plugins\tingting; Flags: ignoreversion

;複製vc6運行庫

Source: "msvcp60.dll"; DestDir:"{sys}\"; Flags: onlyifdoesntexist uninsneveruninstall

[INI]

;狗狗搜索插件信息寫入

Filename: "{app}\Program\addins.ini"; Section: "{{1FC7CAC6-2DA8-4cb0-B440-CCC0CA}"; Key: "Name"; String: "狗狗搜索排行";Components: Plugins\gougou

Filename: "{app}\Program\addins.ini"; Section: "{{1FC7CAC6-2DA8-4cb0-B440-CCC0CA}"; Key: "File"; String: "..\Plugins\GouGouTop\GouGouTop.dll" ;Components: Plugins\gougou

Filename: "{app}\Program\addins.ini"; Section: "{{1FC7CAC6-2DA8-4cb0-B440-CCC0CA}"; Key: "Enable"; String: "1" ;Components: Plugins\gougou

;迅雷聽聽插件信息寫入

Filename: "{app}\Program\addins.ini"; Section: "{{200A93B9-365D-4F4A-9C4F-57F645A7B9D2}"; Key: "Name"; String: "聽聽插件";Components: Plugins\tingting

Filename: "{app}\Program\addins.ini"; Section: "{{200A93B9-365D-4F4A-9C4F-57F645A7B9D2}"; Key: "File"; String: "..\Plugins\TingTing\TingTing.dll" ;Components: Plugins\tingting

Filename: "{app}\Program\addins.ini"; Section: "{{200A93B9-365D-4F4A-9C4F-57F645A7B9D2}"; Key: "Enable"; String: "1" ;Components: Plugins\tingting

[Registry]

Root: HKLM; Subkey: "SOFTWARE\Thunder Network\ThunderOem\thunder_backwnd"; ValueName: "Path"; ValueType: String; ValueData: "{app}\Thunder.exe"; Flags: uninsdeletekey

Root: HKLM; Subkey: "SOFTWARE\Thunder Network\ThunderOem\thunder_backwnd"; ValueName: "Version"; ValueType: String; ValueData: "5.7.2.371"; Flags: uninsdeletekey

Root: HKCU; Subkey: "Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下載全部鏈接"; ValueType: String; ValueData: "{app}\Program\GetAllUrl.htm"; Flags: uninsdeletevalue

Root: HKCU; Subkey: "Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下載全部鏈接"; ValueName: "Contexts"; ValueType: dword; ValueData: 243; Flags: uninsdeletevalue

Root: HKCU; Subkey: "Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下載"; ValueType: String; ValueData: "{app}\Program\GetUrl.htm"; Flags: uninsdeletevalue

Root: HKCU; Subkey: "Software\Microsoft\Internet Explorer\MenuExt\使用迅雷下載"; ValueName: "Contexts"; ValueType: dword; ValueData: 34; Flags: uninsdeletevalue

[Run]

Filename: "{app}\DDR迅雷設置中心.exe"; Description: "運行迅雷設置中心";

;Filename: "{app}\Program\SetupHelper.exe"; Parameters: "/register_plugins";

;Filename: "{app}\Program\SetupHelper.exe"; Parameters: "/open_firewall";

;Filename: "{app}\Program\SetupHelper.exe"; Parameters: "/for_all_users";

[Icons]

Name: "{commondesktop}\迅雷";Filename: "{app}\Thunder.exe";Tasks:desktopicon

Name: "{group}\啓動迅雷"; Filename: "{app}\Thunder.exe";Tasks:associate

Name: "{group}\DDR迅雷設置中心"; Filename: "{app}\DDR迅雷設置中心.exe";Tasks:associate

Name: "{group}\卸載迅雷"; Filename: "{uninstallexe}";Tasks:associate

;[UninstallRun]

;[UninstallDelete]

;Type: filesandordirs ; Name: "{app}";

[Code]

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);

var

DeleteProfile: string;

DeleteConfirm: Boolean;

begin

case CurUninstallStep of

//卸載後的收尾工作

usPostUninstall:

begin

// 確認是否刪除整個目錄

DeleteProfile := ExpandConstant('{app}');

DeleteConfirm :=MsgBox('是否保留用戶配置文件與歷史記錄?' mbConfirmation MB_YESNO) = idYes;

if DeleteConfirm=False then

DelTree(DeleteProfile True True True);

if DeleteConfirm=True then

DelTree(DeleteProfile '\Program'TrueTrueTrue);

end;

end;

end;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章