tags:

views:

242

answers:

2

From within my Java program I want to determine which .NET Framework is installed on the system. What is the best (and easiest) way to do this?

Answer Thanks scubabbl! It worked to check the directory System.getenv( "WINDIR" ) + "\\Microsoft.NET\\Framework" for its directories starting with the letter "v".

+5  A: 

From what I understand, the actual file structure in c:\windows\Microsoft.Net\Framework has folders with versions of .Net installed. On my computer, I have folders up to v3.5, or c:\windows\Microsoft.Net\Framework\v3.5.

There are lots of issues with this, including security issues though.

The second, and probably better answer would be to check the windows registry.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP

The Version key will have the value you are looking for.

Edit: stackoverflow question regarding reading the registry with java. http://stackoverflow.com/questions/62289/readwrite-to-windows-registry-using-java

This library http://www.trustice.com/java/jnireg/ will allow you to read the registry.

scubabbl
Thanks! Checking that directory should do the trick for me, since I know I have read access. one additional tweak is to use System.getenv("WINDIR") in case someone installed Windows in D: or somewhere exotic.
Epaga
Ah, yes. I didn't think of that. Good catch.
scubabbl
A: 

Checking the directory structure is not the best way to do this. Take a look at this thread for the full details on the registry keys you need to evaluate.

Scott Dorman