C#读取本机安装的.net framework 版本


转自:http://geekswithblogs.net/lorint/archive/2006/01/30/67654.aspx

// (Note that lbInstVersions is a listbox placed on a WinForm or Web Form.)
string componentsKeyName="SOFTWARE\\Microsoft\\Active Setup\\Installed Components",
   friendlyName,
   version;
// Find out in the registry anything under:
//    HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components
// that has ".NET Framework" in the name
RegistryKey componentsKey=Registry.LocalMachine.OpenSubKey(componentsKeyName);
string[] instComps=componentsKey.GetSubKeyNames();
foreach(string instComp in instComps)
{
   RegistryKey key=componentsKey.OpenSubKey(instComp);
   friendlyName=(string)key.GetValue(null); // Gets the (Default) value from this key
   if(friendlyName != null && friendlyName.IndexOf(".NET Framework")>=0)
   {
      // Let's try to get any version information that's available
      version=(string)key.GetValue("Version");
      // If you want only the framework info with its SP level and not the
      // other hotfix and service pack detail, uncomment this if:
      //    if(version!=null && version.Split(',').Length>=4)
      lbInstVersions.Items.Add(friendlyName+(version!=null?(" ("+version+")"):""));
   }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值