一个比较完整的Inno Setup 安装脚本 - 增加了对ini文件设置的功能

来源:互联网 发布:cad迷你看图mac破解版 编辑:程序博客网 时间:2024/04/25 16:04

一个比较完整的Inno Setup 安装脚本,增加了对ini文件设置的功能,一个安装包常用的功能都具备了。

[plain] view plaincopy
  1. [Setup]  
  2. ; 注: AppId的值为单独标识该应用程序。  
  3. ; 不要为其他安装程序使用相同的AppId值。  
  4. ; (生成新的GUID,点击 工具|在IDE中生成GUID。)  
  5. AppId={{A9861883-31C5-4324-BD9A-DC3271EEB675}  
  6. ;程序名  
  7. AppName=ISsample  
  8. ;版本号  
  9. AppVerName=ISsample 1.0.0.0  
  10. ;发布者名  
  11. AppPublisher=Hkiss  
  12. ;相关连接  
  13. AppPublisherURL=http://zwkufo.blog.163.com  
  14. AppSupportURL=http://zwkufo.blog.163.com  
  15. AppUpdatesURL=http://zwkufo.blog.163.com  
  16. ;默认安装目录  
  17. DefaultDirName={pf}\ISsample  
  18. ;默认开始菜单名  
  19. DefaultGroupName=ISsample  
  20. ;是否打开->可选安装开始菜单项  
  21. ;AllowNoIcons=yes  
  22. ;安装协议  
  23. ;LicenseFile=C:\Example\原始文件\agreement.txt  
  24. ;安装前查看的文本文件  
  25. ;InfoBeforeFile=C:\Example\原始文件\Setup_New.txt  
  26. ;安装后查看文本文件  
  27. ;InfoAfterFile=C:\Example\原始文件\Setup_Old.txt  
  28. ;输出文件夹  
  29. OutputDir=C:\Example\InnoSetup\out  
  30. ;输出文件名  
  31. OutputBaseFilename=setup  
  32. ;安装图标  
  33. SetupIconFile=C:\Example\原始文件\title.ico  
  34. ;安装需要输入密码  
  35. ;Password=123  
  36. ;Encryption=yes  
  37.   
  38. ;压缩相关  
  39. Compression=lzma  
  40. SolidCompression=yes  
  41.   
  42. ;可以让用户忽略选择语言相关  
  43. ShowLanguageDialog = yes  
  44. ;备注版本信息  
  45. VersionInfoCompany=HTTP://www.Hkiss.COM  
  46. VersionInfoDescription=ISsample 汉化增强版  
  47. VersionInfoVersion=1.0.0.0  
  48. VersionInfoCopyright=Copyright (C) 2007-2008 Hkiss  
  49.   
  50. ;制作选择语言  
  51. [Languages]  
  52. Name: "chs"; MessagesFile: "compiler:Default.isl" ;LicenSeFile :"C:\Example\原始文件\chs\agreement.txt"  
  53. Name: "en"; MessagesFile: "compiler:Languages\English.isl";LicenSeFile :"C:\Example\原始文件\en\agreement.txt"  
  54.   
  55. ;用户定制任务  
  56. [Tasks]  
  57. Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked  
  58. Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked  
  59. Name: "Tasks_1" ; Description:"用户自定义任务1"; Flags: unchecked  
  60. Name: "Tasks_2" ; Description:"用户自定义任务2"; Flags: unchecked  
  61. ;选择了组件才会出现的定制任务  
  62. Name: "Tasks_3" ; Description:"用户自定义任务3";Components: c1 ; Flags: unchecked  
  63.   
  64. ;文件安装  
  65. [Files]  
  66. ;多语言安装环境设置    公共参数Languages 来设置  
  67. Source: "C:\Example\原始文件\enfile.txt"; DestDir: "{app}"; Languages: en ; Flags: ignoreversion  
  68. Source: "C:\Example\原始文件\chsfile.txt"; DestDir: "{app}"; Languages: chs ; Flags: ignoreversion  
  69. ;用户自定义任务 Tasks  
  70. Source: "C:\Example\原始文件\Tasks\tasks_1.txt"; DestDir: "{app}\Tasks"; Flags: ignoreversion ;Tasks : Tasks_1  
  71. Source: "C:\Example\原始文件\Tasks\tasks_2.txt"; DestDir: "{app}\Tasks"; Flags: ignoreversion ;Tasks :Tasks_2  
  72. Source: "C:\Example\原始文件\Tasks\tasks_Components.txt"; DestDir: "{app}\Tasks"; Flags: ignoreversion ;Tasks :Tasks_2  
  73. ;用户定义组件安装  
  74. Source: "C:\Example\原始文件\Components\Components_1.txt"; DestDir: "{app}\Components"; Flags: ignoreversion ; Components: a1;  
  75. Source: "C:\Example\原始文件\Components\Components_2.txt"; DestDir: "{app}\Components"; Flags: ignoreversion ; Components: a2;  
  76. Source: "C:\Example\原始文件\Components\Components_3.txt"; DestDir: "{app}\Components"; Flags: ignoreversion ; Components: a3;  
  77. Source: "C:\Example \原始文件\Components\Components_4.txt"; DestDir: "{app} \Components"; Flags: ignoreversion ; Components: a1 a2 a3;  
  78.   
  79. ;用户注册自定义Dll文件      regserver 注册 noregerror 不显示错误信息  
  80. Source: "C:\Example\原始文件\jmail.dll"; DestDir: "{app}"; Flags: ignoreversion regserver  
  81. ;添加自述文件  
  82. Source: "C:\Example\原始文件\ISsample.txt"; DestDir: "{app}"; Flags: ignoreversion  
  83. ;添加一个文件到缓存文件夹{Tmp} deleteafterinstall 安装后删除  
  84. Source: "C:\Example\原始文件\test.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall  
  85.   
  86. Source: "C:\Example\原始文件\ISsample.chm"; DestDir: "{app}"; Flags: ignoreversion  
  87. Source: "C:\Example\原始文件\ISsample.exe"; DestDir: "{app}"; Flags: ignoreversion  
  88. Source: "C:\Example\原始文件\ISsample.dll"; DestDir: "{app}"; Flags: ignoreversion  
  89. Source: "C:\Example\原始文件\ISsample.ini"; DestDir: "{app}"; Flags: ignoreversion  
  90. Source: "C:\Example\原始文件\ISsample.rar"; DestDir: "{app}"; Flags: ignoreversion  
  91. Source: "C:\Example\原始文件\ISsample_sys.dll"; DestDir: "{win}\System32"; Flags: ignoreversion  
  92. Source: "C:\Example\原始文件\log\*"; DestDir: "{app}\log"; Flags: ignoreversion recursesubdirs createallsubdirs  
  93. ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”  
  94. ;安装类型设置  
  95. [Types]  
  96. Name: Full ;Description:"完全安装"; Flags: iscustom  
  97. Name: Compact ;Description:"简洁安装";  
  98. Name: Custom; Description:"自定义安装";  
  99. ;组件安装  
  100. [Components]  
  101. Name: c1; Description: "自定义任务3" ; Types: Full  
  102. Name: a1; Description: "安装Components_1"; Types: Full Compact Custom ;  
  103. Name: a2; Description: "安装Components_2"; Types : Full   Compact  
  104. Name: a3; Description: "安装Components_3"; Types : Full  
  105.   
  106. ;开始菜单,桌面快捷方式  
  107. [Icons]  
  108. Name: "{group}\ISsample"; Filename: "{app}\ISsample.exe"  
  109. Name: "{group}\{cm:ProgramOnTheWeb,ISsample}"; Filename: "http://zwkufo.blog.163.com"  
  110. Name: "{group}\{cm:UninstallProgram,ISsample}"; Filename: "{uninstallexe}"  
  111. Name: "{commondesktop}\ISsample"; Filename: "{app}\ISsample.exe"; Tasks: desktopicon  
  112. Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\ISsample"; Filename: "{app}\ISsample.exe"; Tasks: quicklaunchicon  
  113. ;添加一个帮助文挡  
  114. Name: {group}\ISsample 1.0.0.0 帮助文档;Filename: {app}\ISsample.chm  
  115.   
  116. ;用来在程序安装完成后 在安装程序显示最终对话框之前执行程序 常用与运行主程序 显示自述文件 删除临时文件  
  117. [Run]  
  118. Filename: "{app}\ISsample.exe"; Description: "{cm:LaunchProgram,ISsample}"; Flags: nowait postinstall skipifsilent  
  119. Filename: "{app}\ISsample.txt"; Description: "查看显示自述文件"; Flags: postinstall skipifsilent shellexec  
  120.   
  121. ;更改显示在程序中显示的消息文本  
  122. [Messages]  
  123. BeveledLabel=HKiss科技  
  124. ;卸载对话框说明  
  125. ConfirmUninstall=您真的想要从电脑中卸载ISsample吗?%n%n按 [是] 则完全删除 %1 以及它的所有组件;%n按 [否]则让软件继续留在您的电脑上.  
  126. ;定义解压说明  
  127. ;StatusExtractFiles=解压并复制主程序文件及相关库文件...  
  128.   
  129. ;用于在用户系统中创建,修改或删除ini文件健值  
  130. [INI]  
  131. Filename: "{app}\cfg.ini"; Section: "Startup Options"; Flags: uninsdeletesection  
  132. Filename: "{app}\cfg.ini"; Section: "Startup Options"; Key: "server ip"; String: "127.0.0.1"  
  133. Filename: "{app}\cfg.ini"; Section: "Startup Options"; Key: "server port"; String: "8080"  
  134.   
  135. ;用于在用户系统中创建,修改或删除注册表健值  
  136. [Registry]  
  137. Root: HKLM ;SubKey:"Software\ISsample";ValueType:dword;ValueName:config;ValueData:10 ;Flags:uninsdeletevalue  
  138. ;在执行脚本  
  139. [code]  
  140. //全局变量  
  141. var MyProgChecked: Boolean;  
  142.   
  143. //判断程序是否存在  
  144. //初始华程序事件  
  145. function InitializeSetup(): boolean;  
  146. var Isbl: boolean;         //声明变量  
  147. var Isstr: string;  
  148. begin       //开始  
  149. Isbl := true;             //变量赋值  
  150. Isstr := '欢迎';  
  151. if RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\ISsample', 'config') then  
  152. begin  
  153.     MsgBox('已安装过,请先卸载在安装',mbConfirmation, MB_OK);  
  154.     isbl := false;  
  155. end else  
  156. begin  
  157.    //MsgBox('无值',mbConfirmation, MB_OK);  
  158.      isbl := true;  
  159. end;  
  160.   
  161. //下面是个麻烦的 条件语句 end else 注意  
  162. //if MsgBox(Isstr, mbConfirmation, MB_OKCANCEL) = IDOK then  
  163. //begin  
  164. // isbl := true;  
  165. // MsgBox('执行了', mbConfirmation, MB_OK);  
  166. //end else  
  167. //begin  
  168. // isbl := false;  
  169. //MsgBox('执行了', mbConfirmation, MB_OK);  
  170. //end;  
  171.   
  172. Result := Isbl;  
  173. end;       //结束  
  174.   
  175. procedure CurStepChanged(CurStep: TSetupStep);  
  176. var Isstr :string;  
  177. begin  
  178. if CurStep=ssInstall then       //实际安装前调用  
  179. begin  
  180.     //MsgBox('CurStepChanged:实际安装前调用', mbConfirmation, MB_OKCANCEL);           //安装完成后调用  
  181. end;  
  182. if CurStep=ssPostInstall then  
  183. begin  
  184.     Isstr := ExpandConstant('{tmp}\tmp.rar');  
  185. //    if FileExists(Isstr) then  
  186. //    begin  
  187. //      MsgBox('文件存在',mbConfirmation, MB_OK);  
  188. //    end else  
  189. //    begin  
  190. //      MsgBox('文件不存在',mbConfirmation, MB_OK);  
  191. //    end;  
  192.    // MsgBox('CurStepChanged:实际安装后调用', mbConfirmation, MB_OKCANCEL);  
  193. end;  
  194. end;  
  195.   
  196. //下一步 按钮按钮 事件  
  197. function NextButtonClick(CurPageID: Integer): Boolean;  
  198. var ResultCode: Integer;  
  199. var IsSetup : Boolean;  
  200. begin  
  201. IsSetup := true ;  
  202. case CurPageID of  
  203.     wpSelectDir:  
  204.        MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);   //WizardDirValue 路径  
  205.     wpSelectProgramGroup:  
  206.        MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK); //开始菜单名  
  207.     wpReady:  
  208.       begin  
  209.        if not RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Test', 'config') then   begin  
  210.           if MsgBox('程序执行需要Test.ext,是否安装!', mbConfirmation, MB_YESNO) = idYes then begin  
  211.            ExtractTemporaryFile('test.exe');  
  212.             if not Exec(ExpandConstant('{tmp}\test.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then  
  213.               MsgBox('Test.exe出错:' #13#13 ' ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);  
  214.           end else begin  
  215.                 IsSetup := false ;  
  216.           end ;  
  217.           BringToFrontAndRestore();  
  218.         end;  
  219.       end;  
  220. end;  
  221. Result := IsSetup;  
  222. end;  
0 0
原创粉丝点击