杉宫竹苑工作室

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

Inno Setup 先决条件检测安装

[复制链接]
发表于 2017-1-9 21:34:56 | 显示全部楼层 |阅读模式

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

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

x
检测并安装 .NET 3.5
检测并安装SQL Server 2008 Express R2 both in x86 and x64
检测并安装 Windows Installer 4.5
检测并安装 Crystal Report 2008 Redist x86 and x64


  1. Files
  2. Source: "E:\Inno Setup\Prerequisites\WindowsInstaller4_5\WindowsXP-KB942288-v3-x86.exe"; DestDir: "{app}"; DestName:"wi.exe"; Flags: ignoreversion deleteafterinstall;Check: checkwixp86; AfterInstall: InstallWindowsInstaller
  3. Source: "E:\Inno Setup\Prerequisites\WindowsInstaller4_5\WindowsXP-KB942288-v3-x86.exe"; DestDir: "{app}"; DestName:"wi.exe"; Flags: ignoreversion deleteafterinstall;Check: checkwi86; AfterInstall: InstallWindowsInstaller
  4. Source: "E:\Inno Setup\Prerequisites\WindowsInstaller4_5\WindowsXP-KB942288-v3-x86.exe"; DestDir: "{app}"; DestName:"wi.exe"; Flags: ignoreversion deleteafterinstall;Check: checkwi64; AfterInstall: InstallWindowsInstaller

  5. Source: "E:\Inno Setup\Prerequisites\dotnetfx35\dotnetfx35.exe"; DestDir: "{app}"; DestName:"dotnetfx35.exe"; Flags: ignoreversion deleteafterinstall;Check: Checkdotnet; AfterInstall: InstallDotNet;

  6. Source: "E:\Inno Setup\Prerequisites\CrystalReports105\CRRedist2008x86.msi"; DestDir: "{app}"; DestName:"cr.exe"; Check: ShouldInstallCR86; Flags: ignoreversion deleteafterinstall; AfterInstall: InstallCrystalReports
  7. Source: "E:\Inno Setup\Prerequisites\CrystalReports105\CRRedist2008x64.msi"; DestDir: "{app}"; DestName:"cr.exe"; Check: ShouldInstallCR64; Flags: ignoreversion deleteafterinstall; AfterInstall: InstallCrystalReports

  8. Source: "E:\Inno Setup\Prerequisites\SQLServer2008R2SP2\SQLEXPRx86ENU.exe"; Components:sqlserver; DestDir: "{app}"; DestName:"sql.exe"; Flags: ignoreversion; Check: CheckSQLServer86; AfterInstall: InstallSQLServer
  9. Source: "E:\Inno Setup\Prerequisites\SQLServer2008R2SP2\SQLEXPRx64ENU.exe"; Components:sqlserver; DestDir: "{app}"; DestName:"sql.exe"; Flags: ignoreversion; Check: CheckSQLServer64; AfterInstall: InstallSQLServer

  10. Source: "E:\Project\Inno Setup\Project\BIS\Files\BIS.exe"; Check: InstallThisFile; DestDir: "{app}"; Flags: ignoreversion

  11. Icons
  12. Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
  13. Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
  14. Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
  15. Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
  16. Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

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

  19. Registry
  20. Root: HKLM; Subkey: "Software\MyApp"; Flags: uninsdeletekey
  21. Root: HKLM; Subkey: "Software\MyApp"; ValueType: string; ValueName: "Path"; ValueData: "{app}"

  22. UninstallDelete
  23. Type: files; Name: "{app}\sql.exe"; AfterInstall: RemoveSQLServer



  24. Code
  25. const
  26. RunOnceName = 'setup Restart';
  27. var
  28. //dotnetRedistPath: string;
  29. //downloadNeeded: boolean;
  30. //ProcessorArchitecture = paIA64
  31. //paX64
  32. lastcaption: string;
  33. dotNetNeeded: boolean;
  34. wineeded: boolean;
  35. sqlserverneeded: boolean;
  36. memoDependenciesNeeded: string;
  37. Version: TWindowsVersion;
  38. msipath: string;
  39. versionMS, versionLS: cardinal;
  40. HasRestarted: boolean;
  41. IsRestartNeeded: boolean;
  42. SkipOtherPage: boolean;
  43. SQLDependency: string;
  44. filename: string;

  45. Function WindowsInstallerVersionBelow31(): Boolean;
  46. begin
  47. //intToStr(word(VersionMS shr 16))
  48. Result:=false;
  49. if ((VersionMS shr 16) < 3) then
  50. result:=true;

  51. if ((((VersionMS shr 16)) = 3) and (((VersionLS shr 16)) < 1)) then
  52. result:=true;

  53. end;

  54. Function WindowsInstallerVersionBelow45(): Boolean;
  55. begin
  56. //intToStr(word(VersionMS shr 16))
  57. Result:=false;
  58. if ((VersionMS shr 16) < 4) then
  59. result:=true;

  60. if ((((VersionMS shr 16)) = 4) and (((VersionLS shr 16)) < 5)) then
  61. result:=true;

  62. end;

  63. Function WindowsInstallerVersionBelow50(): Boolean;
  64. begin
  65. //intToStr(word(VersionMS shr 16))
  66. Result:=false;
  67. if ((VersionMS shr 16) < 5) then
  68. result:=true;

  69. end;

  70. function Is64(): boolean;
  71. begin

  72. Result:=IsWin64;
  73. end;

  74. function Is86(): boolean;
  75. begin

  76. Result:= not IsWin64;
  77. end;

  78. function ShouldInstallCR64(): boolean;
  79. begin
  80. result:=false;

  81. if ((is64) and (not IsRestartNeeded)) then
  82. result:=true;
  83. end;

  84. function ShouldInstallCR86(): boolean;
  85. begin
  86. result:=false;

  87. if ((is86) and (not IsRestartNeeded)) then
  88. result:=true;
  89. end;

  90. function IsXP():boolean;
  91. begin

  92. Result:=false;


  93. // Windows 2003 version is 5.2 (server)
  94. if (Version.Major = 5) then begin
  95. Result:=true;

  96. end;
  97. end;

  98. function IsWindows7():boolean;
  99. begin

  100. Result:=false;

  101. // Windows 2003 version is 5.2 (server)
  102. if (Version.Major = 6) then begin
  103. Result:=true;

  104. end;
  105. end;

  106. function IsWindows7OrLater():boolean;
  107. begin

  108. Result:=false;

  109. // Windows 2003 version is 5.2 (server)
  110. if (Version.Major >= 6) then begin
  111. Result:=true;

  112. end;
  113. end;

  114. function InstallThisFile(): boolean;
  115. begin
  116. result:=not IsRestartNeeded;
  117. end;

  118. function CheckWI86(): boolean;
  119. begin
  120. Result:=false;

  121. if ((wineeded) and (ProcessorArchitecture = paX86) and IsWindows7OrLater()) then begin

  122. Result:=true;
  123. end;
  124. end;

  125. function CheckWI64(): boolean;
  126. begin
  127. Result:=false;
  128. if (( wineeded) and (ProcessorArchitecture = paX64) and IsWindows7OrLater()) then begin
  129. Result:=true;
  130. end;

  131. end;

  132. function CheckWIXP86(): boolean;
  133. begin
  134. Result:=false;
  135. if ((wineeded) and (ProcessorArchitecture = paX86) and IsXP()) then begin

  136. Result:=true;

  137. end;
  138. end;

  139. function Checkdotnet(): boolean;
  140. begin
  141. Result:=false;

  142. if (dotNetNeeded and not IsRestartNeeded ) then begin
  143. Result:=true;
  144. end;
  145. end;

  146. function CheckSQLServer86(): boolean;
  147. begin
  148. Result:=false;
  149. if (ProcessorArchitecture = paX86) and (not IsRestartNeeded) then begin

  150. Result:=true;

  151. end;

  152. end;

  153. function CheckSQLServer64(): boolean;
  154. begin
  155. Result:=false;
  156. if (ProcessorArchitecture = paX64) and (not IsRestartNeeded) then begin

  157. Result:=true;

  158. end;
  159. end;


  160. //if Exec(ExpandConstant('{win}\notepad.exe'), '', '', SW_SHOW,
  161. // ewWaitUntilTerminated, ResultCode) then


  162. Procedure InstallCrystalReports() ;
  163. var
  164. path: string;
  165. kode: integer;
  166. Begin
  167. path:= ExpandConstant('{app}\cr.exe');
  168. //msgbox (path, mbInformation, MB_OK);
  169. lastcaption:=WizardForm.StatusLabel.Caption;
  170. WizardForm.StatusLabel.Caption := 'Installing Crystal Report 2008 Runtime... (This may take a few minutes)'
  171. Exec(path,'', '', SW_Show, ewWaitUntilTerminated,kode);
  172. WizardForm.StatusLabel.Caption := lastcaption;
  173. End;

  174. Procedure InstallWindowsInstaller() ;
  175. var
  176. path: string;
  177. kode: integer;
  178. Begin
  179. path:= ExpandConstant('{app}\wi.exe');
  180. //msgbox (path, mbInformation, MB_OK);

  181. lastcaption:=WizardForm.StatusLabel.Caption;
  182. WizardForm.StatusLabel.Caption := 'Installing Windows Installer 4.5... (This may take a few minutes)'
  183. Exec(path,'/Q', '', SW_hide, ewWaitUntilTerminated,kode);
  184. WizardForm.StatusLabel.Caption := lastcaption;

  185. //msgbox('This install need to reboot the computer. Please close all the application', mbInformation, MB_OK);
  186. if IsComponentSelected('sqlserver') then begin
  187. IsRestartNeeded:=true;
  188. RegWriteStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce',RunOnceName, ExpandConstant('{src}\' + filename ));
  189. RegWriteStringValue(HKEYCURRENTUSER, 'Software\MyApp','MyApp', '1' );
  190. end;
  191. End;

  192. Procedure InstallDotNet() ;
  193. var
  194. path: string;
  195. kode: integer;
  196. Begin
  197. path:= ExpandConstant('{app}\dotnetfx35.exe');
  198. //msgbox (path, mbInformation, MB_OK);
  199. lastcaption:=WizardForm.StatusLabel.Caption;
  200. WizardForm.StatusLabel.Caption := 'Installing .NET Framework 3.5 SP1... (This may take a few minutes) '
  201. Exec(path,'/Q /Norestart', '', SW_hide, ewWaitUntilTerminated,kode);
  202. WizardForm.StatusLabel.Caption := lastcaption;
  203. End;

  204. Procedure InstallSQLServer();
  205. var
  206. path: string;
  207. kode: integer;
  208. Begin
  209. if sqlserverneeded then
  210. begin
  211. path:= ExpandConstant('{app}\sql.exe');
  212. lastcaption:=WizardForm.StatusLabel.Caption;
  213. WizardForm.StatusLabel.Caption := 'Installing SQL Server 2008 Express R2 SP2... (This may take a few minutes) '
  214. Exec(path,'/Q /Action=install /FEATURES=SQL /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE" /SQLSYSADMINACCOUNTS="BUILTIN\ADMINISTRATORS" /AGTSVCACCOUNT="NT AUTHORITY \Network Service" /SECURITYMODE=SQL /SAPWD=@pass /IACCEPTSQLSERVERLICENSETERMS /TCPENABLED=1', '', SW_hide, ewWaitUntilTerminated,kode);
  215. WizardForm.StatusLabel.Caption := lastcaption;
  216. end;
  217. End;

  218. Procedure RemoveSQLServer() ;
  219. var
  220. path: string;
  221. kode: integer;
  222. Begin

  223. if (RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\100\10.50')) then begin
  224. path:= ExpandConstant('{app}\sql.exe');
  225. lastcaption:=WizardForm.StatusLabel.Caption;
  226. WizardForm.StatusLabel.Caption := 'Removing SQL Server 2008 Express R2 SP2... (This may take a few minutes) '
  227. Exec(path,'/Q /Action=uninstall /FEATURES=SQL /INSTANCENAME=MSSQLSERVER ', '', SW_hide, ewWaitUntilTerminated,kode);
  228. WizardForm.StatusLabel.Caption := lastcaption;

  229. end;

  230. End;

  231. function IsNeedRestart(): boolean;
  232. begin
  233. result:= IsRestartNeeded;
  234. end;

  235. function InitializeSetup(): Boolean;

  236. begin
  237. msipath:=ExpandConstant('{sys}\msi.dll');
  238. IsRestartNeeded:=false;
  239. dotNetNeeded := false;
  240. filename:='BIS 1.0 Setup Full';
  241. GetWindowsVersionEx(Version);
  242. GetVersionNumbers(msipath, versionMS, versionLS)

  243. SkipOtherPage:=true;

  244. if ((RegValueExists(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce',RunOnceName)) and (RegValueExists(HKEYCURRENTUSER,'Software\MyApp', 'MyApp'))) then
  245. begin
  246. MsgBox('Setup needs to reboot your computer before continue installing', mbError, mb_Ok);
  247. result:=false;
  248. end else
  249. begin
  250. if RegValueExists(HKEYCURRENTUSER,'Software\MyApp', 'MyApp') then
  251. begin
  252. RegDeleteKeyIncludingSubkeys(HKEYCURRENTUSER,'Software\MyApp');
  253. HasRestarted:=true;
  254. end else
  255. begin


  256. if (WindowsInstallerVersionBelow45 and not HasRestarted) then begin
  257. wineeded := true;
  258. memoDependenciesNeeded := memoDependenciesNeeded + ' Windows Installer 4.5' #13;
  259. end;



  260. end;

  261. Result := true;

  262. // Check for required netfx installation
  263. if (not RegKeyExists(HKLM, 'Software\Microsoft\.NETFramework\AssemblyFolders\v3.5')) then begin
  264. dotNetNeeded := true;
  265. if (not IsAdminLoggedOn()) then begin
  266. MsgBox('This Appliacation needs the Microsoft .NET Framework 3.5 to be installed by an Administrator', mbInformation, MB_OK);
  267. Result := false;
  268. end else begin
  269. memoDependenciesNeeded := memoDependenciesNeeded + ' .NET Framework 3.5 SP 1' #13;

  270. end;
  271. end;




  272. end;
  273. end;

  274. function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
  275. var
  276. s: string;

  277. begin
  278. if memoDependenciesNeeded <> '' then s := s 'Dependencies to install:' NewLine + memoDependenciesNeeded;

  279. s:= s SQLDependency NewLine;

  280. s := s MemoDirInfo NewLine + NewLine;

  281. Result := s
  282. end;

  283. function PrepareToInstall(var NeedsRestart: Boolean): String;
  284. begin
  285. if IsComponentSelected('sqlserver') then begin
  286. if (not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\100\10.50')) then begin
  287. sqlserverneeded := true;

  288. end;
  289. end;
  290. end;


  291. function ShouldSkipPage(PageID: Integer): Boolean;
  292. begin
  293. if HasRestarted then begin
  294. //or (pageid=wpInfoAfter) or (pageid=wpFinished)
  295. if ((pageid=wpReady) and (SkipOtherPage=true)) then begin
  296. WizardForm.ComponentsList.ItemEnabled1;
  297. SkipOtherPage:=false;
  298. result:=true;
  299. end
  300. else
  301. begin
  302. result:=true;
  303. end;
  304. end;
  305. end;

  306. Function NeedRestart(): Boolean;
  307. begin
  308. result:= IsRestartNeeded;
  309. end;

  310. procedure CurPageChanged(CurPageID: Integer);
  311. begin
  312. if curpageid = wpSelectTasks then begin
  313. if IsComponentSelected('sqlserver') then begin
  314. SQLDependency := ' SQL Server 2008 Express R2 SP2' #13;

  315. end else
  316. begin
  317. SQLDependency:='' ;
  318. end;
  319. end;

  320. if HasRestarted then begin
  321. if curpageid = wpSelectTasks then begin
  322. SQLDependency := ' SQL Server 2008 Express R2 SP2' #13;
  323. end else begin
  324. SQLDependency:='';
  325. end;
  326. end;
  327. end;
  328. procedure DeinitializeSetup();
  329. begin

  330. if (IsRestartNeeded and sqlserverneeded) then begin

  331. end;

  332. end;
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-19 18:08 , Processed in 0.099886 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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