杉宫竹苑工作室

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

setup Factory 发布.net2.0 的软件

[复制链接]
发表于 2016-8-28 15:00:21 | 显示全部楼层 |阅读模式

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

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

x
Setup Factory。在7.0版本中,Setup Factory的默认从属资源中仅支持VB5.0及VB6.0,想要在生成的安装程序中自动完成.NET FRAMEWORK的安装,从网上查了一下,须要按以下步骤做几件事:
首先找到Setup Factory安装目录下的Dependencies目录,在目录中新建一个dotnet2_0.xml的文件。
然后,在Dependencies目录下新建子目录,取名dotnet2_0,将.NET FRAMEWORK安装程序dotnetfx.exe拷至该子目录下,dotnetfx.exe可在VS 2005的安装目录下的SDK\\v2.0\\BootStrapper\\Packages\\dotnetfx目录下找到。
完成之后打开Setup Factory,选择:资源---从属---添加,可以看到.NET FRAMEWORK 2.0了。
文件dotnet2_0.xml内容如下:
  1. <DependencyTemplate>
  2. <Dependency>
  3. <Name> .NET Framework 2.0</Name>
  4. <RuntimeTempFolder>dotnet20</RuntimeTempFolder>
  5. <RevisionDate>Friday, April 1, 2011</RevisionDate>
  6. <Description>Installs the Microsoft .NET 2.0 Framework SP2 onto the user's system. Includes the .NET installer in the setup executable.

  7. Applications and controls written for the .NET Framework version 2.0 require the .NET Framework Redistributable Package version 2.0 to be installed on the computer where the application or control runs. The .NET Framework redistributable package is available as a stand-alone executable file, dotnetfx3.exe. When this dependency module is included in your setup, it detects and installs the .NET Framework redistributable.

  8. This dependency module requires that you supply a copy of both Microsoft .NET Framework redistributable files (NetFx20SP2_x86.exe and NetFx20SP2_x64.exe). The .NET installation files can be downloaded from the following URL:

  9. http://www.microsoft.com/downloads/en/details.aspx?FamilyID=5B2C0358-915B-4EB5-9B1D-10E506DA9D0F

  10. </Description>
  11. <DetectScript>function isDotNet_Installed()
  12. --Check to see if the registry key exists
  13. local DotNet_Registry = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727");
  14. if (DotNet_Registry == false) then
  15. -- The registry key does not exist
  16. -- Run the .NET Installation script
  17. -- Output to the log file that .NET could not be found, so it will be installed.
  18. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: No version of .NET 2.0 was found. .NET 2.0 will be installed.\r\n", true);
  19. return false;
  20. else
  21. -- The key does exist
  22. -- Get the .NET install success value from the registry
  23. local DotNet_Install_Success = Registry.GetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727", "Install", true);

  24. if (DotNet_Install_Success == "1") then
  25. -- Check the version key.
  26. local DotNet_Install_Version = Registry.GetValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727", "Version", true);

  27. -- Compare the returned value against the needed value
  28. Compare = String.CompareFileVersions(DotNet_Install_Version, "2.2.30729");

  29. if (Compare == 0 or Compare == 1) then
  30. -- .NET version 2.0 SP2 is installed already
  31. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: .NET version 2.0 SP2 is installed already\r\n", true);
  32. return true;
  33. end
  34. else
  35. -- The success value wasn't found
  36. -- Run the .NET Installation script
  37. -- Output to the log file that .NET could not be found, so it will be installed.
  38. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: No version of .NET 2.0 was found. .NET 2.0 will be installed.\r\n", true);
  39. return false;
  40. end
  41. end
  42. return true;
  43. end</DetectScript>
  44. <DetectFunction>isDotNet_Installed</DetectFunction>
  45. <InstallScript>
  46. -- Check to see if this is a valid operating system for .NET 3.0
  47. function isValidDotNet2OS()
  48. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: Entering compatible OS detection.\r\n",true);

  49. local tblOSInfo = System.GetOSVersionInfo();
  50. local strOSName = System.GetOSName();

  51. -- Check Windows XP
  52. if (tblOSInfo.MajorVersion == "5") and (tblOSInfo.MinorVersion == "1") then
  53. return true;
  54. end

  55. -- Check Windows Server 2003
  56. if (tblOSInfo.MajorVersion == "5") and (tblOSInfo.MinorVersion == "2") then
  57. return true;
  58. end

  59. -- this installer is not supported on other platforms
  60. return false;
  61. end


  62. if (not isDotNet_Installed()) then
  63. -- Variables used in the installation actions:
  64. local strMessage = [[Setup has detected that your Microsoft .NET run-time files are out of date.
  65.                                                             
  66. local strDialogTitle = "Technology Required";
  67. local bShowUserPrompt = true; -- Whether to prompt the user for confirmation before running the .NET installer.
  68. local bRunInstallFile = true; -- The default of whether or not to run the setup
  69. local bRequirementFail = false;
  70. local tbRequirementFailStrings = {};

  71. local strAbortQuestion = [[

  72. Due to this requirement failure, it is recommended that you abort the install.

  73. Click OK to abort the setup, or Cancel to continue with the application install.]];
  74. local strRequirementString = [[.NET 2.0 cannot be installed due to the following requirements:

  75. ]];
  76. local strRuntimeSupportFolder = SessionVar.Expand("%TempLaunchFolder%\\dotnet20");
  77. local b64BitOs = System.Is64BitOS();
  78. local strExtractInstallerToPath = "";
  79. if (b64BitOs) then
  80. --strExtractInstallerToPath = strRuntimeSupportFolder.."\\NetFx20SP2_x64.exe";
  81. strExtractInstallerToPath = strRuntimeSupportFolder.."\\dotnetfx2.0.exe";
  82. else
  83. strExtractInstallerToPath = strRuntimeSupportFolder.."\\dotnetfx2.0.exe";
  84. --strExtractInstallerToPath = strRuntimeSupportFolder.."\\NetFx20SP2_x86.exe";
  85. end
  86. local strMessageFail = "";
  87. local _NeedsReboot = false;
  88. local strCmdArgs = "";
  89. local bSilentMode = true; -- Whether to send the /q switch to the .NET 2.0 installer.
  90. local bVital = true; -- Whether the .NET 2.0 installation is vital.

  91. -- Output to the log that the .NET installation script has started.
  92. SetupData.WriteToLogFile("Success\t.NET 2.0 Module: Installation script started.\r\n", true);

  93. ------------------------------------------------------------------------------------------------------------
  94. ---- Requires Internet Explorer 6.0 greater
  95. ------------------------------------------------------------------------------------------------------------

  96. -- Read the version of Internet Explorer (if installed).
  97. strIEVersion = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer", "Version", false);

  98. -- If Internet Explorer Version is less than 6.00.2800.1106 , or cannot be found,
  99. -- set the failure variable and failure string table.
  100. if ((String.CompareFileVersions(strIEVersion, "6.00")== -1) or (strIEVersion == "")) then
  101. bRequirementFail = true;
  102. strTemp = "- .NET 2.0 requires Internet Explorer version 6.0 or greater.";
  103. Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
  104. end

  105. ------------------------------------------------------------------------------------------------------------
  106. ---- Requires Admin permissions ----
  107. ------------------------------------------------------------------------------------------------------------

  108. -- Check if the user is logged in with administrative permissions.
  109. -- If the user doesn't have admin permissions, set the failure variable
  110. -- and failure string table.
  111. tbUserInfo = System.GetUserInfo();
  112. if (tbUserInfo ~= nil) then
  113. if (not tbUserInfo.IsAdmin) then
  114. bRequirementFail = true;
  115. strTemp = "- You do not have the required administrative permissions to install .NET 2.0.";
  116. Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
  117. end
  118. end

  119. ------------------------------------------------------------------------------------------------------------
  120. ---- Requires MSI 3.1 ----
  121. ------------------------------------------------------------------------------------------------------------
  122. -- Get the operating system name.
  123. local strOSName = System.GetOSName();

  124. local strMSIVersion = MSI.GetMSIVersion();


  125. -- need MSI 3.1
  126. if (String.CompareFileVersions(strMSIVersion,"3.1.4000") == -1) or (not strMSIVersion) then
  127. -- MSI 3.1 is not installed
  128. bRequirementFail = true;
  129. strTemp = "- The .NET 2.0 runtime module requires Windows Installer 3.1. Please install this technology then run the setup again.";
  130. Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
  131. end


  132. ------------------------------------------------------------------------------------------------------------
  133. ---- Operating System Check
  134. -- Windows Server 2003
  135. -- Windows XP
  136. ------------------------------------------------------------------------------------------------------------


  137. -- Check if OS is Windows XP or Windows Server 2003
  138. if (not isValidDotNet2OS()) then
  139. bRequirementFail = true;
  140. --.NET 2.0 isn't supported on the OS that was detected.
  141. strTemp = "- .NET 2.0 cannot be installed on this operating system. Requires Windows XP, or Windows Server 2003.";
  142. Table.Insert(tbRequirementFailStrings, Table.Count(tbRequirementFailStrings) + 1, strTemp);
  143. end


  144. -- Check if the dialog should be displayed asking whether or not they want to install the module.
  145. if(bShowUserPrompt)then
  146. local nDialogResult = Dialog.Message(strDialogTitle,strMessage,MB_OKCANCEL,MB_ICONEXCLAMATION);
  147. if(nDialogResult == IDOK)then
  148. -- The user chose to install the module.
  149. bRunInstallFile = true;
  150. else
  151. -- The user chose not to install the module.
  152. bRunInstallFile = false;
  153. end
  154. end

  155. if (not bRequirementFail) then
  156. -- Check if the user wants to install the runtime.
  157. if(bRunInstallFile)then
  158. -- The following are command line options that can be used when launching the install file Dotnetfx3.exe.
  159. -- /q - Suppresses all UI. An .INI file cannot be specified with this option.
  160. -- /quiet - Same as /q.
  161. -- /qb - Displays minimal UI, showing only progress.
  162. -- /passive - Same as /qb.
  163. -- /uninstall - Uninstalls product.
  164. -- /remove - Same as /uninstall.
  165. -- /f - Repairs all .NET Framework 3.0 components that are installed.
  166. -- /nopatch - Specifies that patches are not applied and bypasses patch checking.
  167. -- /norollback - Specifies that setup is not rolled back if a setup component fails.
  168. -- /norestart - Specifies that the installer does not restart the computer after installation completes. The
  169. --redistributable installer returns ERROR_SUCCESS_REBOOT_REQUIRED (3010) if a reboot is required.
  170. --/? - Displays this list of options.


  171. if (bSilentMode) then
  172. -- Passing quite mode, and no restart.
  173. strCmdArgs = strCmdArgs.."/qb /norestart ";
  174. else
  175. -- Passing no restart.
  176. strCmdArgs = strCmdArgs.."/norestart ";
  177. end
  178. strCmdArgs = "/R:N";
  179. -- Output to the log that the .NET installation is being launched.
  180. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: .NET 2.0 installation file "..strExtractInstallerToPath.." is being launched.\r\n");
  181. local nResult = File.Run(strExtractInstallerToPath, strCmdArgs, "", SW_SHOWNORMAL, true);
  182. if (nResult == 3010) then
  183. -- .NET install indicated that it needs reboot to be complete
  184. -- Set MSI Factory's reboot variable so that the reboot is just
  185. -- performed at the end of the install.
  186. _NeedsReboot = true;
  187. elseif (nResult == 1602) then
  188. -- The user canceled the setup program.
  189. strMessageFail = [[You have cancelled the installation for .NET 2.0. It is not recommended that you continue with the setup.

  190. Click OK to abort the setup, or Cancel to continue with the application install.]];
  191. elseif (nResult == 1603) then
  192. -- A fatal error occurred during installation.
  193. strMessageFail = [[A fatal error occurred during installation of the .NET 2.0 runtime. It is not recommended that you continue with the setup.

  194. Click OK to abort the setup, or Cancel to continue with the application install.]];
  195. elseif (nResult == 1605) then
  196. -- This action is only valid for products that are currently installed.
  197. strMessageFail = [[Error during installation of the .NET 2.0 runtime. This action is valid only for products that are currently installed. It is not recommended that you continue with the setup.

  198. Click OK to abort the setup, or Cancel to continue with the application install.]];
  199. elseif (nResult == 1636) then
  200. -- The patch package could not be opened or the patch was not applicable to the .NET Framework 3.0.
  201. strMessageFail = [[The patch package could not be opened or the patch was not applicable to the .NET Framework 2.0. It is not recommended that you continue with the setup.

  202. Click OK to abort the setup, or Cancel to continue with the application install.]];
  203. elseif (nResult == 1639) then
  204. -- Invalid command line argument.
  205. strMessageFail = [[An invalid command line argument was passed to the .NET 2.0 installation. It is not recommended that you continue with the setup.

  206. Click OK to abort the setup, or Cancel to continue with the application install.]];
  207. elseif (nResult == 1643) then
  208. -- The patch package is not permitted by system policy.
  209. strMessageFail = [[The .NET 2.0 patch package is not permitted by system policy. It is not recommended that you continue with the setup.

  210. Click OK to abort the setup, or Cancel to continue with the application install.]];
  211. elseif (nResult == 0) then
  212. -- The .NET setup was successful, so do nothing.
  213. else
  214. -- The .NET setup program was not completed successfully.
  215. strMessageFail = [[An unknown error occurred during the installation of the .NET 2.0 runtime. It is not recommended that you continue with the setup.

  216. Click OK to abort the setup, or Cancel to continue with the application install.]];
  217. end

  218. -- Check to see if an error message was generated.
  219. if (strMessageFail ~= "") then
  220. -- Display the error notification dialog.

  221. -- Output to the log .NET error message.
  222. SetupData.WriteToLogFile("Error\t.NET 2.0 Module: Dialog error shown- "..strMessageFail..".\r\n");

  223. if (bShowUserPrompt) then
  224. nDialogResult = Dialog.Message(".NET 2.0 Installation" ,strMessageFail,MB_OKCANCEL,MB_ICONEXCLAMATION);
  225. if (nDialogResult == IDOK) then
  226. bAbortInstall = true;
  227. end
  228. end
  229. end

  230. -- Delete the run time installer file and remove the temp folder
  231. File.Delete(strExtractInstallerToPath);
  232. --Folder.Delete(strRuntimeSupportFolder);

  233. -- If the user chose to abort the install after the failure of .NET install, exit the setup.
  234. if (bAbortInstall) then
  235. -- Output to the log that the user chose to abort the setup after .NET failure.
  236. SetupData.WriteToLogFile("Error\t.NET 2.0 Module: User chose to abort setup after .NET failure. Exiting setup.\r\n");
  237. Application.Exit(EXIT_REASON_USER_ABORTED);
  238. end



  239. else
  240. -- The user chose not to install the runtime so delete the run time installer file,
  241. -- remove the temp folder and then exit the setup.

  242. -- Output to the log that the user chose to abort the setup.
  243. SetupData.WriteToLogFile("Error\t.NET 2.0 Module: User chose to abort setup. Exiting setup.\r\n");

  244. File.Delete(strExtractInstallerToPath);
  245. --Folder.Delete(strRuntimeSupportFolder);
  246. if bVital then
  247. Application.Exit(EXIT_REASON_USER_ABORTED);
  248. else
  249. Application.ExitScript();
  250. end
  251. end
  252. else
  253. -- A requirement failed

  254. -- If the user didn't cancel...
  255. if (bRunInstallFile) then
  256. -- One or more of the requirements failed. Notify the user and ask if they wish
  257. -- to abort the installation.
  258. strFullErrorString = Table.Concat(tbRequirementFailStrings, "\r\n", 1, TABLE_ALL);
  259. nDialogResult = Dialog.Message("Notice" , strRequirementString..strFullErrorString..strAbortQuestion, MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1);

  260. -- Output the requirement failure string to the log.
  261. SetupData.WriteToLogFile("Error\t.NET 2.0 Module: Requirement failure dialog: "..strFullErrorString.."\r\n");

  262. -- Delete the runtime installer file and remove the temp folder
  263. File.Delete(strExtractInstallerToPath);

  264. -- The user chose to abort the install due to the requirement failure of .NET.
  265. if (nDialogResult == IDOK) then

  266. -- Output to the log that the user chose to abort the install due to requirement failure.
  267. SetupData.WriteToLogFile("Error\t.NET 2.0 Module: User aborted setup due to requirement failure. Exiting setup.\r\n");

  268. -- Abort the install.
  269. Application.Exit(EXIT_REASON_USER_ABORTED);
  270. end
  271. else
  272. -- The user chose not to install the runtime so delete the run time installer file,
  273. -- remove the temp folder and then exit the setup.

  274. -- Output to the log that the user chose to abort the setup.
  275. SetupData.WriteToLogFile("Error\t.NET 2.0 Module: User chose to abort setup. Exiting setup.\r\n");

  276. File.Delete(strExtractInstallerToPath);

  277. if bVital then
  278. Application.Exit(EXIT_REASON_USER_ABORTED);
  279. else
  280. Application.ExitScript();
  281. end

  282. end
  283. end

  284. -- If a reboot was needed by .NET, notify the user that they must reboot
  285. -- before continuing with the install

  286. -- NOTE: If you would always like to force the user to reboot, comment out the "if (_NeedsReboot) then" condition below.

  287. local strRebootMessage = [[A reboot is required to continue with the installation. After rebooting, re-run the installation.

  288. Click OK to reboot now, or Cancel to reboot later.]];
  289. if (_NeedsReboot) then
  290. nDialogResult = Dialog.Message("Notice", strRebootMessage, MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1);

  291. -- Output to the log that a reboot is required by the .NET setup.
  292. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: .NET 2.0 detected that a reboot is required.\r\n");
  293. -- Check if the uer wanted to reboot now.
  294. if (nDialogResult == IDOK) then

  295. -- NOTE: If you would like the install to relaunch itself after the reboot,
  296. -- uncomment the following block of code.
  297. -- Re-run the installation after the reboot.

  298. File.RunOnReboot(_SourceFilename, "");

  299. -- Output to the log that a reboot will be performed.
  300. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: A reboot will be performed.\r\n");
  301. -- Reboot the user's system.
  302. System.Reboot();
  303. Application.Exit(0);
  304. else
  305. -- Output to the log that the user chose to reboot later and abort the setup.
  306. SetupData.WriteToLogFile("Info\t.NET 2.0 Module: User chose to reboot later. Exiting setup.\r\n");
  307. -- Abort the install.
  308. Application.Exit(EXIT_REASON_USER_ABORTED);
  309. end
  310. end
  311. -- Output to the log that the installation script has finished.
  312. SetupData.WriteToLogFile("Success\t.NET 2.0 Module: Installation script finished.\r\n");
  313. end
  314. </InstallScript>
  315. <SupportFiles>
  316. <File>#SUFDIR#\Dependencies\dotnet20\dotnetfx2.0.exe</File>
  317. </SupportFiles>
  318. </Dependency>
  319. </DependencyTemplate>
复制代码
然后在 资源(resource)-从属(Dependencies)中添加.NET Framework 2.0就行了。
在Actions—> on startup下面添加 下面代码
  1. result = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\.NETFramework\\policy\\v2.0");
  2. if (result == false) then
  3. result = File.Run(SessionVar.Expand("%TempLaunchFolder%\\dotnetfx2.0.exe"), "", "", SW_SHOWNORMAL, true);
  4. end
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-15 14:54 , Processed in 0.124447 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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