Sample Script for Detecting the .NET Framework 3.0 Using Internet Explorer

The user-agent string that is sent in browser headers is stored in the registry of the server computer, as listed in the following table.

Version Registry Key
3.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform\.NET CLR.3.0.04131.06
Note   The build number ( 04131.06 in the example) will change for the final release of .NET Framework 3.0.
2.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform\.NET CLR 2.0.50727
1.1 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform\.NET CLR 1.1.4322

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
  
< head >
    
< title > Test for NET Framework 3.0 </ title >
    
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8" />
    
< script  type ="text/javascript"  language ="JavaScript" >
    
<!--
    
var RequiredFXVersion = "3.0.04131.06";
    
    
function window::onload()
    
{
      
var foundVer = CheckRequiredFXVersion(RequiredFXVersion);
      
if (foundVer != null)
      
{
        result.innerHTML 
= "This computer has the correct version of the .NET Framework: " + foundVer + "." + "<br/>"
          
+ "This computer's userAgent string is: " + navigator.userAgent + ".";
      }
 
      
else
      
{
        result.innerHTML 
= "This computer does not have the correct 
version of the .NET Framework.<br/>
"
          
+ "<a href='http://msdn.microsoft.com/windowsvista/default.aspx'>Click here</a> "
          
+ "to get .NET Framework 3.0 now.<br>"
          
+ "This computer's userAgent string is: " + navigator.userAgent + ".";
      }

    }

    
    
//
    // Retrieve available versions from the user agent string
    // and check if any of them match the required version.
    //
    function CheckRequiredFXVersion(requiredVersion)
    
{
      
var userAgentString = navigator.userAgent.match(/\.NET CLR[ .][0-9.]+/g);
      
if (userAgentString != null)
      
{
        
var i;
        
for (i = 0; i < userAgentString.length; ++i)
        
{
          
var ver = userAgentString[i].slice(9);
          
if (CheckVersion(requiredVersion, ver))
            
return ver;
        }

      }

      
return null;
    }


    
//
    // Check if a specific version satisfies the version requirement.
    //
    function CheckVersion(requiredVersion, ver)
    
{
      requiredVersion 
= requiredVersion.split(".");
      ver 
= ver.split(".");
      
      
// Major versions must match exactly.
      if (requiredVersion[0!= ver[0])
        
return false;
      
      
// Minor/build numbers must be at least the required version.
      var i;
      
for (i = 1; i < requiredVersion.length && i < ver.length; i++)
      
{
        
if (new Number(ver[i]) < new Number(requiredVersion[i]))
          
return false;
      }

      
return true;
    }

    
    
-->
    
</ script >
  
</ head >
  
< body >
    
< div  id ="result"   />
  
</ body >
</ html >

你可能感兴趣的:(framework)