【模板下载】innosetup 制作.net安装包的模板

这个模板是在博客园和CodeProject上的代码修改而成的,感谢原作者

模板是2个

innosetup 制作.net 2.0 安装包的模板

innosetup 制作.net 4.0 安装包的模板

下载地址

 innosetup 制作.net 2.0 安装包的模板 代码如下:

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "应用程序名称"
#define MyAppVersion "1.0.0"
#define MyAppPublisher " "
#define MyAppURL "www.qq.com"
#define MyAppExeName "MyApp.exe"
#define IncludeFramework true
#define IsExternal ""
#define IsAdminLoggedOn true
;放置客户端文件的地方
#define SourceFileDir "D:\ClientApp\"


[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{D4CA6231-73B5-4FD9-99E9-2568C4C5A0D1}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
;如果用户选择的文件夹已经存在,是否提示
DirExistsWarning=no
;卸载程序所在的文件夹,将会与我们的程序存在于同一文件夹中
UninstallFilesDir={app}
;卸载程序所使用的图标 在添加删除程序中
UninstallDisplayIcon={app}\{#MyAppName}
 
Compression=lzma
SolidCompression=yes

#if IncludeFramework
  OutputBaseFilename=setup_FW
#else
  OutputBaseFilename=Setup
#endif

;输出目录

OutputDir={#SourceFileDir}\setup
;是否在程序组中允许卸载
Uninstallable=yes

UninstallDisplayName=卸载{#MyAppName}

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

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone; 
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
;Source: "{#SourceFileDir}\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion {#IsExternal}
;创建子文件夹的示例
;Source: "{#SourceFileDir}\a\mbs485.exe"; DestDir: "{app}\a"; Flags: ignoreversion recursesubdirs createallsubdirs
 
 
Source: "D:\ClientApp\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

#if IncludeFramework
;net Framework2.0放在另一个文件夹中
Source: "D:\DotnetFolder\dotnetfx.exe"; DestDir: "{tmp}"; Flags: ignoreversion {#IsExternal}; Check: NeedsFramework
#endif
 

; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Icons]

Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"  ;WorkingDir:   "{app}" 
;桌面快捷方式
;ico2.ico是在桌面显示快捷方式的图标
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon ;WorkingDir:"{app}"; IconFilename: "{app}\ico2.ico"; 
; 快速启动
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon   ;WorkingDir:   "{app}" 
;卸载
Name: "{group}\卸载{#MyAppName}"; Filename: "{uninstallexe}"


[Registry]
;注册表中添加自启动
Root: HKLM; Subkey: "software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "MyStartKey"; ValueData: "{app}\{#MyAppExeName} /s"; Flags: uninsdeletevalue

[Run]
#if IncludeFramework
  ;加入 /passive  看看是否能单独安装此.net 框架
  Filename: {tmp}\dotnetfx.exe; Parameters: "/q:a /c:""install /l /q"""; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: "正在安装程序运行所必须的.NET Framework2.0框架,大概需要2-5分钟,请稍后"
#endif
Filename: {win}\Microsoft.NET\Framework\v2.0.50727\CasPol.exe; Parameters: "-q -machine -remgroup ""{#MyAppName}"""; WorkingDir: {tmp}; Flags: skipifdoesntexist runhidden; StatusMsg: "设置程序访问权限..."
Filename: {win}\Microsoft.NET\Framework\v2.0.50727\CasPol.exe; Parameters: "-q -machine -addgroup 1.2 -url ""file://{app}/*"" FullTrust -name ""{#MyAppName}"""; WorkingDir: {tmp}; Flags: skipifdoesntexist runhidden; StatusMsg: "设置程序访问权限..."

Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

 [UninstallRun]
Filename: {win}\Microsoft.NET\Framework\v2.0.50727\CasPol.exe; Parameters: "-q -machine -remgroup ""MyAppName"""; Flags: skipifdoesntexist runhidden;

[code]

// Indicates whether .NET Framework 2.0 is installed.
function IsDotNET20Detected(): boolean;
var
    success: boolean;
    install: cardinal;
begin
    success := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727', 'Install', install);
    Result := success and (install = 1);
end;

//RETURNS OPPOSITE OF IsDotNet20Detected FUNCTION
//Remember this method from the Files section above
function NeedsFramework(): Boolean;
begin
  Result := (IsDotNET20Detected = false);
end;

//CHECKS TO SEE IF CLIENT MACHINE IS WINDOWS 95
function IsWin95 : boolean;
begin
  Result := (InstallOnThisVersion('4.0,0', '4.1.1998,0') = irInstall);
end;

//CHECKS TO SEE IF CLIENT MACHINE IS WINDOWS NT4
function IsWinNT : boolean;
begin
  Result := (InstallOnThisVersion('0,4.0.1381', '0,4.0.1381') = irInstall);
end;

//GETS VERSION OF IE INSTALLED ON CLIENT MACHINE
function GetIEVersion : String;
var
  IE_VER: String;
begin
  {First check if Internet Explorer is installed}
  if RegQueryStringValue(HKLM,'SOFTWARE\Microsoft\Internet Explorer','Version',IE_VER) then
      Result := IE_VER
else
    {No Internet Explorer at all}
    result := '';
end;

//GETS THE VERSION OF WINDOWS INSTALLER DLL
function GetMSIVersion(): String;
begin
    GetVersionNumbersString(GetSystemDir+'\msi.dll', Result);
end;

//LAUNCH DEFAULT BROWSER TO WINDOWS UPDATE WEBSITE
procedure GoToWindowsUpdate;
var
  ErrorCode: Integer;
begin
  if (MsgBox('是否打开windows更新网站?' + chr(13) + chr(13) + '(Requires Internet Connection)'
            , mbConfirmation, MB_YESNO) = IDYES) then
      ShellExec('open', 'http://windowsupdate.microsoft.com','', '', SW_SHOW, ewNoWait, ErrorCode);
end;

//IF SETUP FINISHES WITH EXIT CODE OF 0, MEANING ALL WENT WELL
//THEN CHECK FOR THE PRESENCE OF THE REGISTRY FLAG TO INDICATE THE
//.NET FRAMEWORK WAS INSTALLED CORRECTLY
//IT CAN FAIL WHEN CUST DOESN'T HAVE CORRECT WINDOWS INSTALLER VERSION
function GetCustomSetupExitCode(): Integer;
begin
  if (IsDotNET20Detected = false) then
    begin
      MsgBox('.NET Framework没有安装成功!',mbError, MB_OK);
      result := -1
    end
end;

//启动的时候进行系统检查,检查系统环境是否符合安装
function InitializeSetup: Boolean;
var
  Version: TWindowsVersion;
  IE_VER: String;
  MSI_VER: String;
  NL: Char;
  NL2: String;
 // ResultCode: integer;        用于在安装程序运行前执行某个程序
begin
     // if Exec(ExpandConstant('{win}\notepad.exe'), '', '', SW_SHOW,
    // ewWaitUntilTerminated, ResultCode) then
  NL := Chr(13);
  NL2 := NL + NL;

  // Get Version of Windows from API Call
  GetWindowsVersionEx(Version);

  // On Windows 2000, check for SP3

  if Version.NTPlatform and
     (Version.Major = 5) and
     (Version.Minor = 0) and
     (Version.ServicePackMajor < 3) then
  begin
    SuppressibleMsgBox('Win2000系统需要安装sp3补丁包.' + NL +
                       '访问' + NL2 +
                       ' *** http://windowsupdate.microsoft.com ***' + NL2 +
                       '来获取补丁包,' + NL +
                       '并安装',
                        mbCriticalError, MB_OK, MB_OK);
    GoToWindowsUpdate;
    Result := False;
    Exit;
  end;

  // On Windows XP, check for SP2
  if Version.NTPlatform and
     (Version.Major = 5) and
     (Version.Minor = 1) and
     (Version.ServicePackMajor < 2) then
  begin
    SuppressibleMsgBox('Winxp系统至少需要安装sp2补丁包' + NL +
                       '访问' + NL2 + ' *** http://windowsupdate.microsoft.com ***' + NL2 +
                       '来获取补丁包,' + NL +
                       '并安装',
                       mbCriticalError, MB_OK, MB_OK);
    GoToWindowsUpdate;
    Result := False;
    Exit;
  end;

  //IF WINDOWS 95 OR NT DON'T INSTALL
  if (IsWin95) or (IsWinNT) then
  begin
    SuppressibleMsgBox('本程序不能运行在win95或 Windows NT系统上.',
      mbCriticalError, MB_OK, MB_OK);
    Result := False;
    Exit;
  end;

  //CHECK MSI VER, NEEDS TO BE 3.0 ON ALL SUPPORTED SYSTEM EXCEPT 95/ME, WHICH NEEDS 2.0)
  MSI_VER := GetMSIVersion
  if ((Version.NTPlatform) and (MSI_VER < '3')) or ((Not Version.NTPlatform) and (MSI_VER < '2')) then
    begin
      SuppressibleMsgBox('您的windows系统需要更新.' + NL +
                         '访问*** http://windowsupdate.microsoft.com *** 来获取更新,' + NL +
                         'and then reinstall this program',
                         mbCriticalError, MB_OK, MB_OK);
      GoToWindowsUpdate;
      Result := False;
      Exit;
  end;

  //CHECK THE IE VERSION (NEEDS TO BE 5.01+)
  IE_VER := GetIEVersion;
  if IE_VER < '5.01' then
    begin
      if IE_VER = '' then
        begin
          MsgBox('需要IE为5.0或以上版本.' + NL2 +
                 '您没有安装IE浏览器或者浏览器损坏' + NL +
                 '请升级您的浏览器程序', mbInformation, MB_OK);
        end
      else
        begin
          MsgBox('需要IE为5.0或以上版本.' + NL2 +
                 '您的IE版本为 ' + IE_VER + '.' + NL2 +
                 '请升级您的浏览器程序.', mbInformation, MB_OK);
        end

      GoToWindowsUpdate;
      result := false;
      exit;
  end;

  //MAKE SURE USER HAS ADMIN RIGHTS BEFORE INSTALLING
  if IsAdminLoggedOn then
    begin
      result := true
        exit;
    end
  else
    begin
      MsgBox('您必须拥有管理员权限来执行此次操作.' + NL +
             '请使用管理员账户登录,' + NL +
            '然后重新运行此程序.', mbInformation, MB_OK);
        result := false;
    end
  end;
end.

innosetup 制作.net 4.0 安装包的模板 代码如下:

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档!

#define MyAppName "应用程序"
#define MyAppVersion "1.0.0"
#define MyAppPublisher " "
#define MyAppURL "www.qq.com"
#define MyAppExeName "AppClient.exe"
#define IncludeFramework true
#define IsExternal ""
#define IsAdminLoggedOn true
;ClientApp是客户端程序所在的文件夹
#define SourceFileDir "D:\ClientApp\"


[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{D74B494C-8E8D-46BD-B166-142678A51AF2}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
;如果用户选择的文件夹已经存在,是否提示
DirExistsWarning=no
;卸载程序所在的文件夹,将会与我们的程序存在于同一文件夹中
UninstallFilesDir={app}
;卸载程序所使用的图标 在添加删除程序中
UninstallDisplayIcon={app}\{#MyAppName}
 
Compression=lzma
SolidCompression=yes

#if IncludeFramework
  OutputBaseFilename=setup_FW
#else
  OutputBaseFilename=Setup
#endif

;输出目录

OutputDir={#SourceFileDir}\setup
;是否在程序组中允许卸载
Uninstallable=yes

UninstallDisplayName=卸载{#MyAppName}

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

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone; 
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
 
Source: "D:\ClientV4\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

#if IncludeFramework
;把.net framework 4.0放在另一个文件件中
Source: "D:\NetFramework4\dotNetFx40_Full_x86_x64.exe"; DestDir: "{tmp}"; Flags: ignoreversion {#IsExternal}; Check: NeedsFramework
#endif
 

; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

[Icons]

Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"  ;WorkingDir:   "{app}" 
;桌面快捷方式
;ico2.ico是要在桌面显示的快捷方式的ico
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon ;WorkingDir:"{app}"; IconFilename: "{app}\ico2.ico"; 
;快速启动
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon   ;WorkingDir:   "{app}" 
;卸载
Name: "{group}\卸载{#MyAppName}"; Filename: "{uninstallexe}"

;注册开机启动 暂时不启用
;[Registry]
;注册表中添加自启动
;Root: HKLM; Subkey: "software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "MyStartKey"; ValueData: "{app}\{#MyAppExeName} /s"; Flags: uninsdeletevalue


[Run]
#if IncludeFramework
Filename: {tmp}\dotNetFx40_Full_x86_x64.exe; Parameters: "/q:a /c:""install /l /q"""; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: "正在安装程序运行所必须的.NET Framework4.0框架,大概需要2-5分钟,请稍后"
#endif
Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: "-q -machine -remgroup ""{#MyAppName}"""; WorkingDir: {tmp}; Flags: skipifdoesntexist runhidden; StatusMsg: "设置程序访问权限..."
Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: "-q -machine -addgroup 1.2 -url ""file://{app}/*"" FullTrust -name ""{#MyAppName}"""; WorkingDir: {tmp}; Flags: skipifdoesntexist runhidden; StatusMsg: "设置程序访问权限..."

[UninstallRun]
Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: "-q -machine -remgroup ""{#MyAppName}"""; Flags: skipifdoesntexist runhidden;

[code]
// Indicates whether .NET Framework 4.0 is installed.
function IsDotNET40Detected(): boolean;
var
    success: boolean;
    install: cardinal;
begin
    success := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Install', install);
   
    Result :=  success and (install = 1);
end;

//RETURNS OPPOSITE OF IsDotNet20Detected FUNCTION
//Remember this method from the Files section above
function NeedsFramework(): Boolean;
begin
  Result := (IsDotNET40Detected = false);
end;



function GetCustomSetupExitCode(): Integer;
begin
  if (IsDotNET40Detected = false) then
    begin
      MsgBox('.NET Framework 未能正确安装!',mbError, MB_OK);
      result := -1
    end
end;

//卸载程序
function InitializeUninstall(): Boolean;
begin
  Result := MsgBox('卸载程序:' #13#13 '你真的要卸载该程序?', mbConfirmation, MB_YESNO) = idYes;
  //if Result = False then
  //  MsgBox('InitializeUninstall:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
end;


procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  ErrorCode: Integer;
begin
  case CurUninstallStep of
    usUninstall:
      begin
        //MsgBox('卸载程序:' #13#13 '正在卸载...', mbInformation, MB_OK)
        // ...insert code to perform pre-uninstall tasks here...
      end;
    usPostUninstall:
      begin
        //MsgBox('卸载程序:' #13#13 '卸载完成.', mbInformation, MB_OK);
        // ...insert code to perform post-uninstall tasks here...
        ShellExec('open', 'http://www.qq.cn', '', '', SW_SHOW, ewNoWait, ErrorCode)

      end;
  end;
end;

 

你可能感兴趣的:(【模板下载】innosetup 制作.net安装包的模板)