
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
	<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head><card id="MainCard" title="&#x6B22;&#x8FCE;&#x5149;&#x4E34;"><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a><br/>&nbsp;</p><p><b>&#x6807;&#x9898;&#x3A;</b> &#x43;&#x68;&#x65;&#x63;&#x6B;&#x20;&#x2E;&#x4E;&#x45;&#x54;&#x20;&#x56;&#x65;&#x72;&#x73;&#x69;&#x6F;&#x6E;&#x20;&#x77;&#x69;&#x74;&#x68;&#x20;&#x49;&#x6E;&#x6E;&#x6F;&#x20;&#x53;&#x65;&#x74;&#x75;&#x70;&#x5B;&#x8F6C;&#x5D;</p><p><b>&#x4F5C;&#x8005;&#x3A;</b> &#x64;&#x6E;&#x61;&#x77;&#x6F;</p><p><b>&#x65E5;&#x671F;&#x3A;</b> &#x32;&#x30;&#x31;&#x36;&#x2D;&#x31;&#x30;&#x2D;&#x33;&#x31;&#x20;&#x31;&#x30;&#x3A;&#x35;&#x32;&#x20;&#x50;&#x4D;</p><p><b>&#x5206;&#x7C7B;&#x3A;</b> <a href="wap.asp?do=showLog&amp;cateID=16">&#x57;&#x69;&#x6E;&#x7F16;&#x7A0B;</a></p><p><b>&#x5185;&#x5BB9;&#x3A;</b> Inno Setup by Jordan Russell is a great installation scripting program, but lacks a built-in function to determine the .NET Framework version installed on the target machine. Fortunately, it&#x2019;s easy to write such a function using Inno Setup&#x2019;s Pascal scripting language.<br/>The Versions<br/>Microsoft maintains a set of registry keys that indicate the installed .NET Framework versions and service packs. C# MVP Scott Dorman has posted a list comprising versions 1.0 through 4.0 (at the time of this writing) in this Stack Overflow thread. The required registry keys are quite similar for most .NET Framework versions except 1.0. We&#x2019;ll ignore that version which has been obsoleted by 1.1 anyway.<br/>Versions 4.5 and newer are somewhat tricky since they install as in-place up&#100;ates for version 4.0 and reuse the exact same registry keys. The official MSDN page How to: Determine Which .NET Framework Versions Are Installed suggests checking for the presence of DWORD value Release, so that&#x2019;s what I&#x2019;m doing below. An alt&#101;rnative would be to examine the REG_SZ value Version which equals 4.0.30319 for .NET 4.0, 4.5.50709 for .NET 4.5, and 4.6.00079 for .NET 4.6. (Sadly, I didn&#x2019;t think to record the version strings for 4.5.1 &amp; 4.5.2 while I had them installed.)<br/>Versions 4.5.1 and 4.6.x introduce an additional complication: there are two possible Release values, depending on the Windows version! The script handles this by treating all queries for versions 4.5 o&#114; newer as minimum requirements, i.e. they will succeed if the Release value is equal to o&#114; greater than the specified version&#x2019;s minimum value on any system. Queries for .NET 4.0 are also fulfilled by .NET 4.5 o&#114; newer, due to the latter installing as in-place up&#100;ates. Queries for older versions require exact matches, i.e. they are not fulfilled by .NET 4.0 o&#114; newer even if the application would be compatible.<br/>The Script<br/>In the following Inno Setup scripting code block, function IsDotNetDetected checks whether the specified .NET Framework version and at least the specified service pack level are installed. All listed version strings are for final release versions; betas and release candidates typically have different version numbers. Function InitializeSetup demonstrates how to use IsDotNetDetected to check for .NET Framework 4.6 without service packs.<br/>I&#x2019;m placing this small bit of code in the public domain, so you may embed it in your own projects, modify and redistribute it as you see fit.<br/>&#x590D;&#x5236;&#x5185;&#x5BB9;&#x5230;&#x526A;&#x8D34;&#x677F; &#x7A0B;&#x5E8F;&#x4EE3;&#x7801;[Code]<br/>function IsDotNetDetected(version: string; service: cardinal): boolean;<br/>// Indicates whether the specified version and service pack of the .NET Framework is installed.<br/>//<br/>// version -- Specify one of these strings for the required .NET Framework version:<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v1.1&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 1.1<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v2.0&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 2.0<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v3.0&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 3.0<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v3.5&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 3.5<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4\Client&#39;&nbsp;&nbsp;&nbsp;&nbsp; .NET Framework 4.0 Client Profile<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4\Full&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .NET Framework 4.0 Full Installation<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.5&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 4.5<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.5.1&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 4.5.1<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.5.2&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 4.5.2<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.6&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 4.6<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.6.1&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 4.6.1<br/>//&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.6.2&#39;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.NET Framework 4.6.2<br/>//<br/>// service -- Specify any non-negative integer for the required service pack level:<br/>//&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; No service packs required<br/>//&nbsp;&nbsp;&nbsp;&nbsp;1, 2, etc.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Service pack 1, 2, etc. required<br/>var<br/>&nbsp;&nbsp;&nbsp;&nbsp;key, versionKey: string;<br/>&nbsp;&nbsp;&nbsp;&nbsp;install, release, serviceCount, versionRelease: cardinal;<br/>&nbsp;&nbsp;&nbsp;&nbsp;success: boolean;<br/>begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;versionKey := version;<br/>&nbsp;&nbsp;&nbsp;&nbsp;versionRelease := 0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// .NET 1.1 and 2.0 embed release number in version key<br/>&nbsp;&nbsp;&nbsp;&nbsp;if version = &#39;v1.1&#39; then begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versionKey := &#39;v1.1.4322&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;end else if version = &#39;v2.0&#39; then begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versionKey := &#39;v2.0.50727&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;end<br/>&nbsp;&nbsp;&nbsp;&nbsp;// .NET 4.5 and newer install as up&#100;ate to .NET 4.0 Full<br/>&nbsp;&nbsp;&nbsp;&nbsp;else if Pos(&#39;v4.&#39;, version) = 1 then begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;versionKey := &#39;v4\Full&#39;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case version of<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.5&#39;:&nbsp;&nbsp; versionRelease := 378389;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.5.1&#39;: versionRelease := 378675; // 378758 on Windows 8 and older<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.5.2&#39;: versionRelease := 379893;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.6&#39;:&nbsp;&nbsp; versionRelease := 393295; // 393297 on Windows 8.1 and older<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.6.1&#39;: versionRelease := 394254; // 394271 on Windows 8.1 and older<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;v4.6.2&#39;: versionRelease := 394802; // 394806 on Windows 8.1 and older<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br/>&nbsp;&nbsp;&nbsp;&nbsp;end;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// installation key group for all .NET versions<br/>&nbsp;&nbsp;&nbsp;&nbsp;key := &#39;SOFTWARE\Microsoft\NET Framework Setup\NDP\&#39; + versionKey;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// .NET 3.0 uses value InstallSuccess in subkey Setup<br/>&nbsp;&nbsp;&nbsp;&nbsp;if Pos(&#39;v3.0&#39;, version) = 1 then begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success := RegQueryDWordValue(HKLM, key + &#39;\Setup&#39;, &#39;InstallSuccess&#39;, install);<br/>&nbsp;&nbsp;&nbsp;&nbsp;end else begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success := RegQueryDWordValue(HKLM, key, &#39;Install&#39;, install);<br/>&nbsp;&nbsp;&nbsp;&nbsp;end;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// .NET 4.0 and newer use value Servicing instead of SP<br/>&nbsp;&nbsp;&nbsp;&nbsp;if Pos(&#39;v4&#39;, version) = 1 then begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success := success and RegQueryDWordValue(HKLM, key, &#39;Servicing&#39;, serviceCount);<br/>&nbsp;&nbsp;&nbsp;&nbsp;end else begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success := success and RegQueryDWordValue(HKLM, key, &#39;SP&#39;, serviceCount);<br/>&nbsp;&nbsp;&nbsp;&nbsp;end;<br/>&nbsp;&nbsp;&nbsp;&nbsp;// .NET 4.5 and newer use additional value Release<br/>&nbsp;&nbsp;&nbsp;&nbsp;if versionRelease &gt; 0 then begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success := success and RegQueryDWordValue(HKLM, key, &#39;Release&#39;, release);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success := success and (release &gt;= versionRelease);<br/>&nbsp;&nbsp;&nbsp;&nbsp;end;<br/>&nbsp;&nbsp;&nbsp;&nbsp;result := success and (install = 1) and (serviceCount &gt;= service);<br/>end;<br/>function InitializeSetup(): Boolean;<br/>begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;if not IsDotNetDetected(&#39;v2.0&#39;, 0) then begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox(&#39;MyApp requires Microsoft .NET Framework 2.0.&#39;#13#13<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;Please use Windows Up&#100;ate to install this version,&#39;#13<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39;and then re-run the MyApp setup program.&#39;, mbInformation, MB_OK);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result := false;<br/>&nbsp;&nbsp;&nbsp;&nbsp;end else begin<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result := true;<br/>&nbsp;&nbsp;&nbsp;&nbsp;end<br/>end;<br/>&#x76F8;&#x5173;&#x94FE;&#x63A5;<br/>[1].Check .NET Version with Inno Setup&#xFF1A;http://kynosarges.org/DotNetVersion.html<br/>[2].Inno Setup &#x68C0;&#x6D4B;&#x5DF2;&#x5B89;&#x88C5;&#x7684;.NET Framework &#x7248;&#x672C;&#xFF1A;http://www.cnblogs.com/oldfarmer/p/5797130.html<br/>[3].&#x5982;&#x4F55;&#xFF1A;&#x786E;&#x5B9A;&#x8BA1;&#x7B97;&#x673A;&#x5B89;&#x88C5;&#x4E86;&#x54EA;&#x4E9B; .NET Framework &#x7248;&#x672C;&#xFF1A;http://www.mzwu.com/article.asp?id=4252</p><p> + <a href="#CommentCard">&#x67E5;&#x770B;&#x5F53;&#x524D;&#x65E5;&#x5FD7;&#x8BC4;&#x8BBA;</a> (0)</p><p>&nbsp;<br/><br/><a href="wap.asp?do=Login">&#x767B;&#x5F55;</a></p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.609&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card><card id="postCommentCard"><p><b>&#x6807;&#x9898;&#x3A;</b> <a href="#MainCard">&#x43;&#x68;&#x65;&#x63;&#x6B;&#x20;&#x2E;&#x4E;&#x45;&#x54;&#x20;&#x56;&#x65;&#x72;&#x73;&#x69;&#x6F;&#x6E;&#x20;&#x77;&#x69;&#x74;&#x68;&#x20;&#x49;&#x6E;&#x6E;&#x6F;&#x20;&#x53;&#x65;&#x74;&#x75;&#x70;&#x5B;&#x8F6C;&#x5D;</a></p><p><br/>你没有权限发表评论</p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.609&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card><card id="CommentCard"><p>&#x6682;&#x65E0;&#x8BC4;&#x8BBA;</p><p><a href="#MainCard">&#x8FD4;&#x56DE;</a></p><p><br/>&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;&#x2500;</p><p><a href="wap.asp">&#x6728;&#x5B50;&#x5C4B;</a></p><p><a href="http://www.pjhome.net/wap.asp">PJBlog3&nbsp;v3.2.9.518</a>&nbsp;Inside.</p><p>Processed&nbsp;In&nbsp;0.609&nbsp;ms</p><do type="prev" label="&#x8FD4;&#x56DE;"><prev/></do></card>
</wml>
