tags:

views:

1462

answers:

5

The problem is that I need to know if it's version 3.5 SP 1, Environment.Version() only returns 2.0.50727.3053.

I found this solution but I think it will take much more time than it's worth, so I'm looking for a simpler one. Any suggestions?

Thanks in advance

+1  A: 

AFAIK there's no built in method in the framework that will allow you to do this. You could check this post for a suggestion on determining framework version by reading windows registry values.

Darin Dimitrov
A: 

Without further investigation, Environment.Version() probably just returns the version of the CLR.

Cecil Has a Name
+7  A: 

Something like this should do it. Just grab the value from the registry

Edit: Updated a bit; Framework is the highest installed version, SP is the service pack for that version.

RegistryKey installed_versions = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
string[] version_names = installed_versions.GetSubKeyNames();
//version names start with 'v', eg, 'v3.5' which needs to be trimmed off before conversion
double Framework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1), CultureInfo.InvariantCulture);
int SP = Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1]).GetValue("SP", 0));
Factor Mystic
Thanks! This works, but I still need the service pack. Any idea?
Carlo
The long version string as well as SP subkey for each SOFTWARE\Microsoft\NET Framework Setup\NDP\<.net version> should provide this, which you can grab with the GetValue method.
Factor Mystic
at the v3.5 level there is a key called SP. The value is the service pack level
SomeMiscGuy
Sorry I'm too noob with this registry fetching. Think you could put up the code?
Carlo
Worked as a charm! Thank you.
Carlo
A: 

Here are some additional possibilities including the useragent, but it eventually links back to the blog post you mentioned.

JP Alioto
+2  A: 

Environment.Version() is giving the correct answer for a different question. The CLR hasn't changed since 2.0 - 3, 3.5, and 4 just have new libraries. I suppose you could check the GAC for libraries that were added in each of those subsequent releases.

quillbreaker