您的位置:首页 > 编程语言 > C#

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

2012-01-19 13:53 435 查看
转自: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 nameRegistryKey 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 keyif(friendlyName != null && friendlyName.IndexOf(".NET Framework")>=0){// Let's try to get any version information that's availableversion=(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+")"):""));}}
[/code]

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐