使用Inno Setup 打包.NET程序,并自动安装.Net Framework

http://www.cnblogs.com/xiaogangqq123/archive/2012/03/19/2405730.html

Inno Setup是什么

Inno Setup 是一个windows系统下的安装包制作程序。它是免费的(而且允许免费用于商业用途)。官网网站:http://www.jrsoftware.org/

虽然说.NET 可以使用VS来打包安装包,但可定制化绝对不如Inno Setup,基本的使用这里不做过多介绍。大家Google一下吧。

我 们在开发.net客户端时候.Net Framework是个比较让人头疼的问题,比如一个WPF程序大小几百K,却要安装一个几十M的.Net Framework。但是也没办法.这里提供两种方式,一个是将.Net Framework打包进安装包中,一个是在线下载.Net Framework然后安装。

各有各的缺点和优点。大家自己择优选择吧。

Inno Setup打包.Net Framework到安装包方式脚本:

; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "MyApp" #define MyAppVersion "1.0" #define IncludeFramework true #define IsExternal "" #define MyAppPublisher "App" #define MyAppURL "http://www.MyApp.cn" #define MyAppExeName "MyApp.exe" [Setup] ; 注: AppId的值为单独标识该应用程序。 ; 不要为其他安装程序使用相同的AppId值。 ; (生成新的GUID,点击 工具|在IDE中生成GUID。) AppId={{B0C52F2E-939F-4CE2-89F3-2F0677584526} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={pf}\{#MyAppName} DefaultGroupName={#MyAppName} OutputDir=E:\step Compression=lzma SolidCompression=yes #if IncludeFramework OutputBaseFilename=setup_FW #else OutputBaseFilename=Setup #endif [Languages] Name: "chinesesimp"; MessagesFile: "compiler:Default.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1 [Files] Source: "E:\MyApp\MyApp.exe"; DestDir: "{app}"; Flags: ignoreversion {#IsExternal} #if IncludeFramework Source: "D:\开发\dotNetFx40_Full_x86_x64.exe"; DestDir: "{tmp}"; Flags: ignoreversion {#IsExternal}; Check: NeedsFramework #endif ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion” [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon [Run] #if IncludeFramework Filename: {tmp}\dotNetFx40_Full_x86_x64.exe; Parameters: "/q:a /c:""install /l /q"""; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: "Installing .NET Framework if needed" #endif Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: "-q -machine -remgroup ""{#MyAppName}"""; WorkingDir: {tmp}; Flags: skipifdoesntexist runhidden; StatusMsg: "Setting Program Access Permissions..." 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: "Setting Program Access Permissions..." [UninstallRun] Filename: {win}\Microsoft.NET\Framework\v4.0.30319\CasPol.exe; Parameters: "-q -machine -remgroup ""{#MyAppName}"""; Flags: skipifdoesntexist runhidden; [code] // Indicates whether .NET Framework 2.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); //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 := (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.asiafinance.cn', '', '', SW_SHOW, ewNoWait, ErrorCode) end; end; end;

脚本说明:

卸载完成之后会自动打开网页,其中的逻辑可以在里面自由扩展。

检测哪个Framwork可以在注册表中找到这个节点。

Inno Setup在线下载并安装.NetFramwork

; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "MyApp" #define MyAppVersion "1.0" #define MyAppPublisher "MyApp" #define MyAppURL "http://www.MyApp.cn/" #define MyAppExeName "MyApp.exe" [Setup] ; 注: AppId的值为单独标识该应用程序。 ; 不要为其他安装程序使用相同的AppId值。 ; (生成新的GUID,点击 工具|在IDE中生成GUID。) AppId={{769CC8AC-50C3-4776-95F5-A1ABF15A38F4} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} AppPublisher={#MyAppPublisher} AppPublisherURL={#MyAppURL} AppSupportURL={#MyAppURL} AppUpdatesURL={#MyAppURL} DefaultDirName={pf}\{#MyAppName} DefaultGroupName={#MyAppName} OutputDir=E:\step OutputBaseFilename=MyApp Compression=lzma SolidCompression=yes [Languages] Name: "chinesesimp"; MessagesFile: "compiler:Default.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1 [Files] Source: C:\Program Files\ISTool\isxdl.dll; Flags: dontcopy ; Source: "E:\MyApp\MyApp.exe"; DestDir: "{app}"; Flags: ignoreversion ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion” [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon [Run] Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: nowait postinstall skipifsilent [Code] var dotnetRedistPath: string; downloadNeeded: boolean; dotNetNeeded: boolean; memoDependenciesNeeded: string; procedure isxdl_AddFile(URL, Filename: PChar); external 'isxdl_AddFile@files:isxdl.dll stdcall'; function isxdl_DownloadFiles(hWnd: Integer): Integer; external 'isxdl_DownloadFiles@files:isxdl.dll stdcall'; function isxdl_SetOption(Option, Value: PChar): Integer; external 'isxdl_SetOption@files:isxdl.dll stdcall'; const dotnetRedistURL = 'http://www.microsoft.com/downloads/info.aspx?na=41&srcfamilyid=e5ad0459-cbcc-4b4f-97b6-fb17111cf544&srcdisplaylang=en&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f6%2f2%2f562A10F9-C9F4-4313-A044-9C94E0A8FAC8%2fdotNetFx40_Client_x86_x64.exe'; //this url was correct at time of publication for .net 3.5 you may need to change this in future. // local system for testing… // dotnetRedistURL = ‘http://192.168.1.1/dotnetfx35.exe’; function InitializeSetup(): Boolean; begin Result := true; dotNetNeeded := false; // Check for required netfx installation if (not RegKeyExists(HKLM, 'Software\Microsoft\.NETFramework\policy\v4.0')) then begin dotNetNeeded := true; if (not IsAdminLoggedOn()) then begin MsgBox('GasSoft needs the Microsoft .NET Framework to be installed by an Administrator', mbInformation, MB_OK); Result := false; end else begin memoDependenciesNeeded := memoDependenciesNeeded + '.NET Framework' #13; dotnetRedistPath := ExpandConstant('{src}\dotnetfx35.exe'); if not FileExists(dotnetRedistPath) then begin dotnetRedistPath := ExpandConstant('{tmp}\dotnetfx35.exe'); if not FileExists(dotnetRedistPath) then begin isxdl_AddFile(dotnetRedistURL, dotnetRedistPath); downloadNeeded := true; end; end; SetIniString('install', 'dotnetRedist', dotnetRedistPath, ExpandConstant('{tmp}\dep.ini')); end; end; end; function NextButtonClick(CurPage: Integer): Boolean; var hWnd: Integer; ResultCode: Integer; begin Result := true; if CurPage = wpReady then begin if (not RegKeyExists(HKLM, 'Software\Microsoft\.NETFramework\policy\v4.0')) then begin hWnd := StrToInt(ExpandConstant('{wizardhwnd}')); // don’t try to init isxdl if it’s not needed because it will error on < ie 3 if downloadNeeded then begin isxdl_SetOption('label', '正在下载 Microsoft .NET Framework'); isxdl_SetOption('des-c-r-i-p-tion', '您还未安装Microsoft .NET Framework. 请您耐心等待,下载完成后会安装到您的的计算机中。'); if isxdl_DownloadFiles(hWnd) = 0 then Result := false; end; if (Result = true) and (dotNetNeeded = true) then begin if Exec(ExpandConstant(dotnetRedistPath), '/qb', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin // handle success if necessary; ResultCode contains the exit code if not (ResultCode = 0) then begin Result := false; end; end else begin // handle failure if necessary; ResultCode contains the error code Result := false; end; end; end; end; end;

我检测是.Net Framework4.0,安装包大小大概48M,相比3.0还是小了不少.

在线安装的话安装包是小了,但是下载缺是比较耗时的。

参考资料:http://zerosandtheone.com/blogs/vb/archive/2008/06/23/vb-net-install-your-app-and-the-net-framework-using-inno-setup.aspx

http://my.hoopchina.com/114266/blog/24775.html

使用Inno Setup 打包.NET程序,并自动安装.Net Framework的更多相关文章

  1. Inno Setup打包的程序提升为管理员权限

    Inno Setup打包的程序在Win7 64位系统上安装,安装步骤最后一步若选中运行程序,会跳出一个错误提示框. 这是因为64位win7系统运行程序时需要管理员权限,而打包的文件并没有这个权限就试图 ...

  2. 【程序打包工具 Inno Setup】CreateProcess 失败:代码 740(Inno Setup打包的程序提升为管理员权限)

    原文参考 https://www.cnblogs.com/SnailProgramer/p/4243666.html http://blog.csdn.net/x356982611/article/d ...

  3. Inno Setup CreateProcess 失败:代码 740(Inno Setup打包的程序提升为管理员权限)

    原文参考 https://www.cnblogs.com/SnailProgramer/p/4243666.html http://blog.csdn.net/x356982611/article/d ...

  4. inno setup 打包exe程序

    inno setup 用于打包生成安装程序, 是通过的一个脚本 可以将 exe 执行文件以安装的形式,解压,添加依赖,创建快捷方式. 例如,我们写了个winform,我们怎么通过安装的形式,给客户的机 ...

  5. Inno Setup打包之先卸载再安装

    使用Inno Setup打包程序之后,如果想要在安装前先卸载,那么需要加下面代码,需要注意的是红色标注的改为你们自己的.网上看到有些说_is1前面用AppName,但是我这边验证不行. [Setup] ...

  6. Inno Setup 打包的文件以管理员权限执行

    最近发现一个问题,就是Inno Setup打包的程序安装完毕后执行需求管理员权限的程序的时候会失败( inno createprocess   须要提升),解决问题的最简单办法就是打包的后的程序也以管 ...

  7. (Inno setup打包)检测系统是否已安装程序,若已安装则弹出卸载提示的代码

    原文 http://bbs.itiankong.com/thread-30983-1-5.html 有6天没研究pascal代码了,昨天晚上突然来了灵感,终于解决了苦思冥想好几天没能解决的问题, 因此 ...

  8. Inno Setup制作应用程序安装包

    我最近写了一个MFC应用程序,想发给其他的小伙伴玩一玩,直接发了个exe文件过去,结果发现小伙伴那边打不开.原来这个exe文件虽然是MFC静态编译的,但是还依赖了其他几个.dll文件,需要把这几个dl ...

  9. Inno Setup 打包工具总结

    Inno Setup 打包工具总结 分类: Install Setup 2013-02-02 15:44 2386人阅读 评论(0) 收藏 举报 最近打包用到了Inno setup,在这个过程中容易犯 ...

随机推荐

  1. Anysys Fluent安装教程

    按顺序按照在一个文件夹内D:\Anysys Fluent 1:安装Exceed      调整电脑时间至2005年(前辈经验)      点击解压好的Exceed.13.[x86+x64]文件夹中的M ...

  2. idea tomcat +eclipse式的部署

    使用习惯了eclipse, 还没开始使用maven, 使用idea 有些不太习惯,现在记录下来,以备忘. /*这一步在tomcat使用external source时,其实是不起作用的**/   a. ...

  3. sql2008 附加数据库出错解决方法

    当遇到 无法为此请求检索数据,(Microsoft.SqlServer.SmoEnum)其他信息执行Transact-Sql语句或批处理时发生了异常, Microsoft.SqlServer.Conn ...

  4. 一些qml资料

    qml开发ios应用 http://www.seanyxie.com/qt-qml%E7%A7%BB%E5%8A%A8%E5%BC%80%E5%8F%91%E4%B9%8B%E5%9C%A8ios%E ...

  5. java 面向对象编程--第17章 I/O系统

    1.I/O操作指的是输入和输出流的操作.相对内存而言,当我们从数据源中将数据读取到内存中,就是输入流,也叫读取流.当我们将内存中处理好的数据写入数据源,就是输出流,也叫写入流. 2.流按照内容分类:字 ...

  6. Android为ViewPager增加切换动画——使用属性动画.

    ViewPager作为Android最常用的的组件之一,相信大家在项目中会频繁的使用到的,例如利用ViewPager制作引导页.轮播图,甚至做整个app的表现层的框架等等. Android3.0以下不 ...

  7. FF与IE对JavaScript和CSS的区别

    一.FF与IE对JavaScript的区别 1. document.formName.item("itemName") 问题 说明:IE下,可以使用document.formNam ...

  8. 部分SIM卡被曝存安全漏洞:7.5亿部手机受牵连

    7月22日消息,据国外媒体报道,一安全研究人员发现部分移动SIM卡所使用的加密方式存在一个安全漏洞,可能会导致手机被黑客远程控制. DES数据加密标准的SIM卡——DES是一种较旧的标准,目前正被部分 ...

  9. HDU 4050 wolf5x 概率dp 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4050 题意: 现在主角站在0处,需要到达大于n的位置 主角要进入的格子有三种状态: 0. 不能进入 1. 能进入 ...

  10. IT公司100题-3-求数组的最大子序列的和

    问题描述: 输入一个整形数组,数组里有正数也有负数. 数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和. 求所有子数组的和的最大值.要求时间复杂度为O(n). 例如输入的数组为1, -2 ...