Is there a command line command for verifying what version of .NET is installed

161,093

Solution 1

Unfortunately the best way would be to check for that directory. I am not sure what you mean but "actually installed" as .NET 3.5 uses the same CLR as .NET 3.0 and .NET 2.0 so all new functionality is wrapped up in new assemblies that live in that directory. Basically, if the directory is there then 3.5 is installed.

Only thing I would add is to find the dir this way for maximum flexibility:

%windir%\Microsoft.NET\Framework\v3.5

Solution 2

Since you said you want to know if its actually installed, I think the best way (short of running version specific code), is to check the reassuringly named "Install" registry key. 0x1 means yes:

C:\>reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5"| findstr Install

   Install     REG_DWORD       0x1
   InstallPath REG_SZ  c:\WINNT\Microsoft.NET\Framework\v3.5\

This also happens to be the "Microsoft Recommended" official method.

WMI is another possibility, but seems impractical (Slow? Takes 2 min on my C2D, SSD). Maybe it works better on your server:

C:\>wmic product where "Name like 'Microsoft .Net%'" get Name, Version

Name                                                Version
Microsoft .NET Compact Framework 1.0 SP3 Developer  1.0.4292
Microsoft .NET Framework 3.0 Service Pack 2         3.2.30729
Microsoft .NET Framework 3.5 SP1                    3.5.30729
Microsoft .NET Compact Framework 2.0                2.0.5238
Microsoft .NET Framework 4 Client Profile           4.0.30319
Microsoft .NET Framework 4 Multi-Targeting Pack     4.0.30319
Microsoft .NET Framework 2.0 Service Pack 2         2.2.30729
Microsoft .NET Framework 1.1                        1.1.4322
Microsoft .NET Framework 4 Extended                 4.0.30319

C:\>wmic product where "name like 'Microsoft .N%' and version='3.5.30729'" get name

Name  
Microsoft .NET Framework 3.5 SP1

Other than these I think the only way to be 100% sure is to actually run a simple console app compiled targeting your framework version. Personally, I consider this unnecessary and trust the registry method just fine.

Finally, you could set up an intranet test site which is reachable from your server and sniffs the User Agent to determine .NET versions. But that's not a batch file solution of course. Also see doc here.

Solution 3

You mean a DOS command such as below will do the job displaying installed .NET frameworks:

wmic /namespace:\\root\cimv2 path win32_product where "name like '%%.NET%%'" get version

The following may then be displayed:

Version
4.0.30319

WMIC is quite useful once you master using it, much easier than coding WMI in scripts depending on what you want to achieve.

Solution 4

You can write yourself a little console app and use System.Environment.Version to find out the version. Scott Hanselman gives a blog post about it.

Or look in the registry for the installed versions. HKLM\Software\Microsoft\NETFramework Setup\NDP

Share:
161,093
Admin
Author by

Admin

Updated on July 08, 2022

Comments

  • Admin
    Admin almost 2 years

    I have set of scripts for doing scripted installs. You can use the scripts on any server 2008 machine. However, I need to check if .NET 3.5 has been installed (before the scripts run) using a dos batch file. Is that possible?

    I know I can check if a file in the C:\WINDOWS\Microsoft.NET\Framework\v3.5 exists, but it would be nice to have something a little more reliable.

    I would like to check if it's actually installed, not just if the dir/file exists.

    Thanks

  • dkretz
    dkretz over 15 years
    Gotta love it - Hanselman's blog has a widget that displays "Now playing: Alicia Keys - If I Was Your Woman/Walk On By" linked to the iTunes store. :D
  • Admin
    Admin over 15 years
    Thanks for the help. I think checking for the dir will work just fine. Also, thanks for the reminder about using %windir%
  • Admin
    Admin over 15 years
    Only problem is my scripts might be run on a freshly installed vm with nothing but the base OS. I think checking for the dir exist will work for what I need.
  • ajma
    ajma over 15 years
    If you care about SP1 versus non SP1, you're going to have use something else, like checking the registry.
  • Aviad Rozenhek
    Aviad Rozenhek almost 13 years
    I tried this command, verbatim, but it just hung there and froze and gave no response
  • Amit Naidu
    Amit Naidu almost 13 years
    Aviad, yes same here. You just have to wait. It took 3 minutes !
  • thefoyer
    thefoyer over 11 years
    Wow 3 minutes? That long? My virtual machine did it in about 10 seconds. Is there a way to limit it to the latest version install and show path to the location on the drive?
  • mvark
    mvark over 11 years
    This simple directory check no longer holds good to detect version. There is no v4.5 directory for .NET Framework 4.5 -stackoverflow.com/questions/12070518/…
  • Mosc
    Mosc about 11 years
    This method doesn't show all .NET Framework versions from GAC. Only 4.0 in my case: Microsoft .NET Framework 4 Multi-Targeting Pack 4.0.30319, Microsoft .NET Framework 4 Extended 4.0.30320, Microsoft .NET Framework 4 Client Profile 4.0.30320. Although 2.0.50727, 3.0.30729.5420, 3.5.30729.5420 versions are also installed.
  • Mosc
    Mosc about 11 years
    This method doesn't properly show all .NET Framework versions from GAC. In my case it only shows properly 2.0 & 4.0: Microsoft ASP.NET MVC 2 2.0.50217.0, Microsoft Windows SDK for Visual Studio .NET 4.0 Framework Tools 7.1.30514, Microsoft ASP.NET MVC 2 - Visual Studio 2010 Tools 2.0.50217.0, Microsoft .NET Framework 4 Multi-Targeting Pack 4.0.30319, Microsoft Windows SDK .NET Framework Tools (30514) 7.1.30514, Microsoft .NET Framework 4 Extended 4.0.30320, Microsoft .NET Framework 4 Client Profile 4.0.30320. Although 3.0.30729.5420, 3.5.30729.5420 versions are also installed.
  • max
    max about 10 years
    It does not hang. It takes a few minutes which is crazy, but I suggest that you use wmic because using registry keys does not always work on all windows. Also, I've noticed that depending on the tool that you are using, on some windows versions, you may not have the registry read permissions on them...
  • Guido Leenders
    Guido Leenders about 10 years
    I use this one for 4.5: reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"| findstr Version
  • John
    John over 8 years
    @GuidoLeenders Even better reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" /v Version
  • Scott Chamberlain
    Scott Chamberlain over 8 years
    Link only answers are discouraged. Please provide at least a summary of the information provided in the link.
  • Aaron
    Aaron over 8 years
    MS has deprecated the 'v4.0' registry folder in favour of a 'v4' folder with an release number in it, like 393297 = 4.6. msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx#net‌​_b
  • Matt
    Matt about 8 years
    Check out this MSDN article: How to: Determine Which .NET Framework Versions Are Installed. It explains that you can no longer rely on the directory only. For versions >=4.0 you need to analyze the registry.
  • Arash
    Arash about 8 years
    is there any powershell command like python --version or node--version for net ?
  • vitaly-t
    vitaly-t almost 8 years
    For .NET 4.6.2 I'm getting: Version\n1.0.0\n4.6.01590. Not sure what that 1.0.0 means... Running on Windows Server 2008 R2
  • Jon P
    Jon P over 7 years
    What makes it too long to finish?
  • Andy Gauge
    Andy Gauge about 7 years
    reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"| findstr 4.6 I have to filter only version 4.6. This is how I did it.
  • Mr. Blonde
    Mr. Blonde over 6 years
    Although slow, this method has the advantage that it shows all installed versions of .NET.
  • Gary Woodfine
    Gary Woodfine over 6 years
    Not the most catchy and easily remembered commands, but it worked for me! Thanks!