Get lastest version .Net Framework Directory

What is the easiest way to get the directory of the most current .Net Framework installation in C# code and also in a batch file.  

I need to set some code access security settings using the caspol.exe which is in the framework directory but it is different on different machines.  For example on a windows 2000 machine it is in c:\winnt\microsoft.net\framework\<framework version>.. and on an XP machine it is in c:\windows\microsoft.net\framework\<framework version>..

I can get around the windows vs winnt by using the %SystemRoot% environment variable but I don't know of any easy way to determine the most current version of the framework in a batch file at least.  

Any assistance would be helpful.
Thanks,


Answer this question

Get lastest version .Net Framework Directory

  • ThisObject

    For anyone interested I posted a function that will get the Framework directory on my <A href="http://dotnetweblogs.com/whaggard/posts/7464.aspx">weblog</A>.


  • EmilF

    There is a real easy way to find the directory:

    System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();

    Thanks to Jamie Cansdale, for pointing this out to me.


  • Get lastest version .Net Framework Directory