Reputation: 48958
I know the official way is the registry, but this is kinda timeconsuming.
I have to check installed versions on several PC's, none of them have VisualStudio , but all of them (probably) a version of .NET framework.
Since the hot water probably exists already, where can i find it?
Upvotes: 5
Views: 4655
Reputation: 33920
Take a look at the javascript from SmallestDotNet. There is also a good article over at the CodeProject.
Upvotes: 0
Reputation: 754575
I commonly run across this problem when writing PowerShell scripts. I find the best way to do this is to run the following check at each of the following base directories
Don't forget about the second directory or you risk your application breaking on 64 bit machines.
For each of those start points, I look for directories match v\d+\\.\d+\\.\d+
and contain the file mscorlib.dll. It is not sufficient to simply look for directory names because it's possible for the name to exist without actually having that version of the framework being installed. For instance if you have a vista machine you will also have v1.0.3705 and v1.1.4322 but neither of those frameworks are actually installed.
Upvotes: 1
Reputation: 2341
here is a code you can put in ASP.net site or winforms
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("mscoree.dll")]
private static extern int GetCORSystemDirectory(
[MarshalAs(UnmanagedType.LPWStr)]StringBuilder pbuffer,
int cchBuffer, ref int dwlength);
static void Main(string[] args)
{
GetClrInstallationDirectory();
}
private static void GetClrInstallationDirectory()
{
int MAX_PATH = 260;
StringBuilder sb = new StringBuilder(MAX_PATH);
GetCORSystemDirectory(sb, MAX_PATH, ref MAX_PATH);
Console.WriteLine(sb.ToString());
while(Console.Read() != 'q') ;
}
}
}
Upvotes: 0
Reputation: 25775
Here's a free lightweight tool that does it quickly - .NET Version detector 2007
If you want to do it manually, this page shows 4-5 good ways to do it. The MS Support page presents a method as simple as opening up the Framework folder and checking the versions installed (folder names)!
However, If you want to do it programmatically, the HttpBrowserCapabilities
class offers a GetClrVersions()
method that is accessible through the Request.Browser.GetClrVersions()
call. Of course, as others have mentioned, you can always query the Navigator.UserAgent property of the Browser too, via Javascript (I think this will show you the .NET versions only in IE):
javascript:alert(navigator.userAgent)
Upvotes: 3
Reputation: 31928
Upvotes: 3