1 /// 2 /// 检测计算机已经安装的NetFramework版本 3 /// 4 internal void GetVersionFromRegistry() 5 { 6 using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, 7 RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\")) 8 { 9 foreach (string versionKeyName in ndpKey.GetSubKeyNames()) 10 { 11 if (versionKeyName.StartsWith("v")) 12 { 13 RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName); 14 string name = (string)versionKey.GetValue("Version", ""); 15 string sp = versionKey.GetValue("SP", "").ToString(); 16 string install = versionKey.GetValue("Install", "").ToString(); 17 if (install == "") //no install info, ust be later 18 Console.WriteLine(versionKeyName + " " + name); 19 else 20 { 21 if (sp != "" && install == "1") 22 { 23 Console.WriteLine(versionKeyName + " " + name + " SP" + sp); 24 } 25 } 26 if (name != "") 27 { 28 continue; 29 } 30 foreach (string subKeyName in versionKey.GetSubKeyNames()) 31 { 32 RegistryKey subKey = versionKey.OpenSubKey(subKeyName); 33 name = (string)subKey.GetValue("Version", ""); 34 if (name != "") 35 sp = subKey.GetValue("SP", "").ToString(); 36 install = subKey.GetValue("Install", "").ToString(); 37 if (install == "") //no install info, ust be later 38 Console.WriteLine(versionKeyName + " " + name); 39 else 40 { 41 if (sp != "" && install == "1") 42 { 43 Console.WriteLine(" " + subKeyName + " " + name + " SP" + sp); 44 } 45 else if (install == "1") 46 { 47 Console.WriteLine(" " + subKeyName + " " + name); 48 } 49 } 50 } 51 } 52 } 53 } 54 }
时间: 2024-11-11 18:25:10