杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2023|回复: 0

Inno Setup 制作安装程序[支持静默安装.NET环境]

[复制链接]
发表于 2017-1-2 17:57:39 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

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

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

  8. [Setup]
  9. ; 注: AppId的值为单独标识该应用程序。
  10. ; 不要为其他安装程序使用相同的AppId值。
  11. ; (生成新的GUID,点击 工具|在IDE中生成GUID。)
  12. AppId={{A7293410-B577-4984-939A-4969DC799A5C}
  13. AppName={#MyAppName}
  14. AppVersion={#MyAppVersion}
  15. AppPublisher={#MyAppPublisher}
  16. AppPublisherURL={#MyAppURL}
  17. AppSupportURL={#MyAppURL}
  18. AppUpdatesURL={#MyAppURL}
  19. DefaultDirName={pf}/{#MyAppName}/测试程序/
  20. UsePreviousAppDir=yes
  21. DefaultGroupName=TestApp
  22. AllowNoIcons=yes
  23. OutputBaseFilename=setup
  24. SetupIconFile=D:/安装程序/TestApp/book.ico
  25. Compression=lzma
  26. SolidCompression=yes

  27. :管理员权限
  28. PrivilegesRequired=admin

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

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

  34. [Files]
  35. Source: "D:/安装程序/TestApp/TestApp.exe"; DestDir: "{app}"; Flags: ignoreversion
  36. Source: "D:/安装程序/TestApp/TestApp.exe.config"; DestDir: "{app}"; Flags: ignoreversion
  37. Source: "D:/安装程序/TestApp/readme.txt"; DestDir: "{app}"; Flags: ignoreversion
  38. Source: "D:/安装程序/TestApp/include/dotnetfx.exe"; DestDir: "{tmp}"; Check:IsNeedInstall ; CopyMode:onlyifdoesntexist;Flags: ignoreversion deleteafterinstall
  39. ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”

  40. [Icons]
  41. Name: "{group}/{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"
  42. Name: "{group}/查看述文件"; Filename: "{app}/readme.txt"
  43. Name: "{group}/{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
  44. Name: "{commondesktop}/{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"; Tasks: desktopicon;
  45. Name: "{userappdata}/Microsoft/Internet Explorer/Quick Launch/{#MyAppName}"; Filename: "{app}/{#MyAppExeName}"; Tasks: quicklaunchicon

  46. [code]
  47. var
  48. isNeedDF : Boolean;
  49. function IsNeedInstall():Boolean;
  50. begin
  51.   isNeedDF := true;
  52.   if (RegKeyExists(HKLM, 'Software/Microsoft/.NETFramework/policy/v2.0')) then
  53.   begin
  54.   isNeedDF := false;
  55.   Result := false;
  56.   end
  57.   else
  58.   Result := true;
  59. end;

  60. procedure CurStepChanged(CurStep: TSetupStep);
  61. var
  62. pt:string;
  63. ResultCode:Integer;
  64. begin
  65.   if(CurStep=ssPostInstall) then
  66.   begin
  67.     if isNeedDF then
  68.     begin
  69.       pt:=  ExpandConstant('{tmp}/dotnetfx.exe');
  70.       if(FileExists(pt)) then
  71.       begin
  72.         if(not Exec(pt,'/q:a /c:"install.exe /qb"','',SW_HIDE,ewWaitUntilTerminated,ResultCode)) then
  73.         begin
  74.           MsgBox('.NET运行环境安装失败,请手动安装!', mbInformation, MB_OK);
  75.         end;
  76.       end
  77.       else
  78.       begin
  79.         MsgBox('未找到文件'+pt, mbInformation, MB_OK);
  80.       end;
  81.     end
  82.     else
  83.       MsgBox('You Neednt Install .NET Framework 2.0', mbInformation, MB_OK);
  84.   end;
  85. end;

  86. [Messages]
  87. BeveledLabel= CoSail Software Co,Ltd.

  88. [Run]
  89. Filename: "{app}/{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: unchecked nowait postinstall skipifsilent
复制代码


关键位置解释

[Tasks]代码段Flags: unchecked 去掉默认就是选择的
[Files]代码段中加上Check:IsNeedInstall ;就是一个检查是否处理的判断,其中IsNeedInstall是在[Code]代码段中自定义的一个函数。

[Run]代码段Flags加一个unchecked就是安装完毕,"运行本程序"不勾选,默认没有这一项。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 18:51 , Processed in 0.115390 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表