1

How I could detect at application runtime

what version numbers of .NET framework are installed on the client machine?

1

2 Answers 2

4
Environment.Version.ToString()
Sign up to request clarification or add additional context in comments.

3 Comments

This will write the current version of the common language runtime. If he build the application with 2.0 what will he get?
Correct your answer correct he want the application run-time and not which .net version are installed +1 from me
This is usefull to know the current application environment but ofcourse is unable to detectd which are installed on the machine. @User3805967 to clarifi: with 2.0 it should get fw2.0, with 3.0 and 3.5 it should get fw 3.0, and targetting the app to 4.0 and/or 4.5 It will get fw4.0, you answer was adapted to my requeriments and worked nice, I were just trying to accept your answer but you have deleted it, thank you two
3
private static void GetVersionFromRegistry()
{
    using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
        RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
    {
        foreach (string versionKeyName in ndpKey.GetSubKeyNames())
        {
            if (versionKeyName.StartsWith("v"))
            {

                RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
                string name = (string)versionKey.GetValue("Version", "");
                string sp = versionKey.GetValue("SP", "").ToString();
                string install = versionKey.GetValue("Install", "").ToString();
                if (install == "") //no install info, ust be later
                    Console.WriteLine(versionKeyName + "  " + name);
                else
                {
                    if (sp != "" && install == "1")
                    {
                        Console.WriteLine(versionKeyName + "  " + name + "  SP" + sp);
                    }

                }
                if (name != "")
                {
                    continue;
                }
                foreach (string subKeyName in versionKey.GetSubKeyNames())
                {
                    RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
                    name = (string)subKey.GetValue("Version", "");
                    if (name != "")
                        sp = subKey.GetValue("SP", "").ToString();
                    install = subKey.GetValue("Install", "").ToString();
                    if (install == "") //no install info, ust be later
                        Console.WriteLine(versionKeyName + "  " + name);
                    else
                    {
                        if (sp != "" && install == "1")
                        {
                            Console.WriteLine("  " + subKeyName + "  " + name + "  SP" + sp);
                        }
                        else if (install == "1")
                        {
                            Console.WriteLine("  " + subKeyName + "  " + name);
                        }

                    }

                }

            }
        }
    }
}

resources info : http://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.