是否有命令行命令来验证安装了什么版本的。net

时间:2022-08-09 00:10:00

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?

我有一组脚本用于执行脚本安装。您可以在任何服务器2008机器上使用这些脚本。但是,我需要使用dos批处理文件检查. net 3.5是否已经安装(在脚本运行之前)。这有可能吗?

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.

我知道我可以检查一个文件是否在C:\WINDOWS\ Microsoft.NET \ Framework \ v3.5的存在,但它将会很高兴有更可靠。

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

我想检查它是否已经安装,而不仅仅是目录/文件是否存在。

Thanks

谢谢

9 个解决方案

#1


14  

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.

不幸的是,最好的方法是检查那个目录。我不确定你的意思是什么,但是。net 3.5“实际上已经安装”了。net 3.0和。net 2.0的CLR,所以所有的新功能都打包在这个目录下的新程序集中。基本上,如果目录在那里,那么就安装了3.5。

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

我想补充的是,要找到这样的目录,最大限度的灵活性:

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

#2


71  

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:

既然您说您想知道它是否实际安装了,我认为最好的方法(除了运行版本特定的代码)是检查命名为“Install”的注册表键。0 x1意味着是的:

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:

WMI是另一种可能性,但似乎不切实际(缓慢?在我的C2D, SSD上花费2分钟。也许它在您的服务器上工作得更好:

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.

除了这些之外,我认为100%确定的唯一方法是运行一个简单的控制台应用程序,它是针对你的框架版本编译的。就我个人而言,我认为这是不必要的,并且相信注册表方法很好。

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.

最后,您可以设置一个从服务器可以访问的内部网测试站点,并嗅探用户代理以确定. net版本。但这当然不是批处理文件解决方案。也看到医生。

#3


16  

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

您的意思是,如下所示的DOS命令将完成显示已安装的。net框架的工作:

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.

当您掌握使用WMIC时,WMIC非常有用,比在脚本中编码WMI更容易,这取决于您想要实现什么。

#4


5  

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.

你可以给自己写一个控制台应用,使用System.Environment。版本查找版本。Scott Hanselman在博客上发表了这篇文章。

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

或者在注册表中查看已安装的版本。微软HKLM \ Software \ \ \*党NETFramework设置

#5


4  

If you're going to run a little console app, you may as well install clrver.exe from the .NET SDK. I don't think you can get cleaner than that. This isn't my answer (but I happen to agree), I found it here.

如果您打算运行一个小型控制台应用程序,您可以安装clrver。来自。net SDK的exe。我不认为你能弄得这么干净。这不是我的答案(但我碰巧同意),我在这里找到的。

#6


0  

REM Search for the CONFIG file, if this doesn't exit then the user doesn't have the .Net framework 2.0 `

快速眼动搜索配置文件,如果没有退出,用户就没有。net框架2.0 '

SET FileName=%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG
IF EXIST %FileName% GOTO INSTALL_DIALER
ECHO.You currently do not have the Microsoft(c) .NET Framework 2.0 installed.

#7


0  

This is working for me:

这对我很有效:

@echo off
SETLOCAL ENABLEEXTENSIONS

echo Verify .Net Framework Version

for /f "delims=" %%I in ('dir /B /A:D %windir%\Microsoft.NET\Framework') do (
    for /f "usebackq tokens=1,3 delims= " %%A in (`reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\%%I" 2^>nul ^| findstr Install`) do (
        if %%A==Install (
            if %%B==0x1 (
                echo %%I
            )
        )
    )
)

echo Do you see version v4.5.2 or greater in the list?

pause

ENDLOCAL 

The 2^>nul redirects errors to vapor.

2 ^ > nul重定向错误蒸汽。

#8


0  

you can check installed c# compilers and the printed version of the .net:

您可以查看已安装的c#编译器和.net的打印版本:

@echo off

for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do (
    set "l="
    for /f "skip=1 tokens=2 delims=k" %%$ in ('"%%# #"') do (
        if not defined l (
            echo Installed: %%$
            set l=%%$
        )
    )
)

echo latest installed .NET %l%

the csc.exe does not have a -version switch but it prints the .net version in its logo. You can also try with msbuild.exe but .net framework 1.* does not have msbuild.

csc。exe没有-version交换机,但它在其徽标中打印。net版本。您也可以尝试msbuild。但是。net框架1。*没有msbuild。

#9


-2  

you can have a look to this page for .NET 4 : http://www.itninja.com/question/batch-script-to-check-and-install-dotnet4-0

你可以浏览一下。net4: http://www.itninja.com/question/batch-脚本-check- install-dotnet4-0

#1


14  

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.

不幸的是,最好的方法是检查那个目录。我不确定你的意思是什么,但是。net 3.5“实际上已经安装”了。net 3.0和。net 2.0的CLR,所以所有的新功能都打包在这个目录下的新程序集中。基本上,如果目录在那里,那么就安装了3.5。

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

我想补充的是,要找到这样的目录,最大限度的灵活性:

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

#2


71  

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:

既然您说您想知道它是否实际安装了,我认为最好的方法(除了运行版本特定的代码)是检查命名为“Install”的注册表键。0 x1意味着是的:

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:

WMI是另一种可能性,但似乎不切实际(缓慢?在我的C2D, SSD上花费2分钟。也许它在您的服务器上工作得更好:

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.

除了这些之外,我认为100%确定的唯一方法是运行一个简单的控制台应用程序,它是针对你的框架版本编译的。就我个人而言,我认为这是不必要的,并且相信注册表方法很好。

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.

最后,您可以设置一个从服务器可以访问的内部网测试站点,并嗅探用户代理以确定. net版本。但这当然不是批处理文件解决方案。也看到医生。

#3


16  

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

您的意思是,如下所示的DOS命令将完成显示已安装的。net框架的工作:

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.

当您掌握使用WMIC时,WMIC非常有用,比在脚本中编码WMI更容易,这取决于您想要实现什么。

#4


5  

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.

你可以给自己写一个控制台应用,使用System.Environment。版本查找版本。Scott Hanselman在博客上发表了这篇文章。

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

或者在注册表中查看已安装的版本。微软HKLM \ Software \ \ \*党NETFramework设置

#5


4  

If you're going to run a little console app, you may as well install clrver.exe from the .NET SDK. I don't think you can get cleaner than that. This isn't my answer (but I happen to agree), I found it here.

如果您打算运行一个小型控制台应用程序,您可以安装clrver。来自。net SDK的exe。我不认为你能弄得这么干净。这不是我的答案(但我碰巧同意),我在这里找到的。

#6


0  

REM Search for the CONFIG file, if this doesn't exit then the user doesn't have the .Net framework 2.0 `

快速眼动搜索配置文件,如果没有退出,用户就没有。net框架2.0 '

SET FileName=%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG
IF EXIST %FileName% GOTO INSTALL_DIALER
ECHO.You currently do not have the Microsoft(c) .NET Framework 2.0 installed.

#7


0  

This is working for me:

这对我很有效:

@echo off
SETLOCAL ENABLEEXTENSIONS

echo Verify .Net Framework Version

for /f "delims=" %%I in ('dir /B /A:D %windir%\Microsoft.NET\Framework') do (
    for /f "usebackq tokens=1,3 delims= " %%A in (`reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\%%I" 2^>nul ^| findstr Install`) do (
        if %%A==Install (
            if %%B==0x1 (
                echo %%I
            )
        )
    )
)

echo Do you see version v4.5.2 or greater in the list?

pause

ENDLOCAL 

The 2^>nul redirects errors to vapor.

2 ^ > nul重定向错误蒸汽。

#8


0  

you can check installed c# compilers and the printed version of the .net:

您可以查看已安装的c#编译器和.net的打印版本:

@echo off

for /r "%SystemRoot%\Microsoft.NET\Framework\" %%# in ("*csc.exe") do (
    set "l="
    for /f "skip=1 tokens=2 delims=k" %%$ in ('"%%# #"') do (
        if not defined l (
            echo Installed: %%$
            set l=%%$
        )
    )
)

echo latest installed .NET %l%

the csc.exe does not have a -version switch but it prints the .net version in its logo. You can also try with msbuild.exe but .net framework 1.* does not have msbuild.

csc。exe没有-version交换机,但它在其徽标中打印。net版本。您也可以尝试msbuild。但是。net框架1。*没有msbuild。

#9


-2  

you can have a look to this page for .NET 4 : http://www.itninja.com/question/batch-script-to-check-and-install-dotnet4-0

你可以浏览一下。net4: http://www.itninja.com/question/batch-脚本-check- install-dotnet4-0