Inno Setup 製作安裝程式[支援靜默安裝.NET環境]

來源:互聯網
上載者:User

1.貼源碼

; 指令碼由 Inno Setup 指令碼嚮導 產生!
; 有關建立 Inno Setup 指令檔的詳細資料請查閱協助文檔!

#define MyAppName "TestSet"
#define MyAppVersion "1.0"
#define MyAppPublisher "ZCF"
#define MyAppURL "http://www.zcfsky.com/"
#define MyAppExeName "TestApp.exe"

[Setup]
; 注: AppId的值為單獨標識該應用程式。
; 不要為其他安裝程式使用相同的AppId值。
; (產生新的GUID,點擊 工具|在IDE中產生GUID。)
AppId={{A7293410-B577-4984-939A-4969DC799A5C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}/{#MyAppName}/測試程式/
UsePreviousAppDir=yes
DefaultGroupName=TestApp
AllowNoIcons=yes
OutputBaseFilename=setup
SetupIconFile=D:/安裝程式/TestApp/book.ico
Compression=lzma
SolidCompression=yes

:管理員權限
PrivilegesRequired=admin

[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; OnlyBelowVersion: 0,6.1
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "D:/安裝程式/TestApp/TestApp.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:/安裝程式/TestApp/TestApp.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:/安裝程式/TestApp/readme.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:/安裝程式/TestApp/include/dotnetfx.exe"; DestDir: "{tmp}"; Check:IsNeedInstall ; CopyMode:onlyifdoesntexist;Flags: ignoreversion deleteafterinstall
; 注意: 不要在任何共用系統檔案上使用“Flags: ignoreversion”

[Icons]
Name: "{group}/{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"
Name: "{group}/查看述檔案"; Filename: "{app}/readme.txt"
Name: "{group}/{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}/{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"; Tasks: desktopicon;
Name: "{userappdata}/Microsoft/Internet Explorer/Quick Launch/{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"; Tasks: quicklaunchicon

[code]
var
isNeedDF : Boolean;
function IsNeedInstall():Boolean;
begin
  isNeedDF := true;
  if (RegKeyExists(HKLM, 'Software/Microsoft/.NETFramework/policy/v2.0')) then
  begin
  isNeedDF := false;
  Result := false;
  end
  else
  Result := true;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
pt:string;
ResultCode:Integer;
begin
  if(CurStep=ssPostInstall) then
  begin
    if isNeedDF then
    begin
      pt:=  ExpandConstant('{tmp}/dotnetfx.exe');
      if(FileExists(pt)) then
      begin
        if(not Exec(pt,'/q:a /c:"install.exe /qb"','',SW_HIDE,ewWaitUntilTerminated,ResultCode)) then
        begin
          MsgBox('.NET運行環境安裝失敗,請手動安裝!', mbInformation, MB_OK);
        end;
      end
      else
      begin
        MsgBox('未找到檔案'+pt, mbInformation, MB_OK);
      end;
    end
    else
      MsgBox('You Neednt Install .NET Framework 2.0', mbInformation, MB_OK);
  end;
end;

[Messages]
BeveledLabel= CoSail Software Co,Ltd.

[Run]
Filename: "{app}/{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: unchecked nowait postinstall skipifsilent

2.關鍵位置解釋

[Tasks]程式碼片段Flags: unchecked 去掉預設就是選擇的
[Files]程式碼片段中加上Check:IsNeedInstall ;就是一個檢查是否處理的判斷,其中IsNeedInstall是在[Code]程式碼片段中自訂的一個函數。

[Run]程式碼片段Flags加一個unchecked就是安裝完畢,"運行本程式"不勾選,預設沒有這一項。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.