Created
August 7, 2012 22:02
-
-
Save tlehman/3289778 to your computer and use it in GitHub Desktop.
Get DotNet Versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using Microsoft.Win32; | |
| namespace GetDotNetVersions | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| // Create a RegistryKey, which will access the HKEY_USERS | |
| // key in the registry of this machine | |
| // | |
| // The registry key where all the installed .NET Framework versions is | |
| // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP | |
| // | |
| RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE") | |
| .OpenSubKey("Microsoft") | |
| .OpenSubKey("NET Framework Setup") | |
| .OpenSubKey("NDP"); | |
| PrintKeys(rk); | |
| Pause(); | |
| } | |
| static void PrintKeys(RegistryKey rkey) | |
| { | |
| // Retrieve all subkeys for the specified key | |
| String[] names = rkey.GetSubKeyNames(); | |
| int icount = 0; | |
| Console.WriteLine("Versions of .NET on your system:"); | |
| foreach (String s in names) | |
| { | |
| if (s != "CDF") | |
| Console.WriteLine(s.Replace("v", "")); | |
| // the following code puts a limit on the number | |
| // of keys displayed. Comment it out to print | |
| // the complete list | |
| icount++; | |
| if (icount >= 10) | |
| break; | |
| } | |
| } | |
| static void Pause() | |
| { | |
| Console.Read(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment