简体   繁体   English

从WinForms应用程序检查.Net框架版本

[英]Check on .Net framework version from WinForms app

How to check the .net framework version on start of WinForms application that wrote on .NET 3.5? 如何在.NET 3.5上编写的WinForms应用程序启动时检查.net框架版本? If .net 3.5 is not installed, the application should show the message about it (may be with link on .net installer or some else). 如果未安装.net 3.5,则应用程序应显示有关它的消息(可能与.net安装程序或其他方面的链接有关)。 Now it show some error that is not clear for user. 现在它显示了一些用户不清楚的错误。

You have to create a starter app written either in .Net 2.0 or as an unmanaged app (to cover if there's no version of .Net installed at all) and start that first and then if .Net 3.5 is installed it'll start the real app, otherwise it'll show a nice error message. 您必须创建一个以.Net 2.0或非托管应用程序编写的入门应用程序(如果没有安装任何版本的.Net,则覆盖它)并首先启动,然后如果安装了.Net 3.5,它将启动真实的应用程序,否则它将显示一个很好的错误消息。

However, the even better solution would be to have your installer install .Net 3.5, that way you won't have to worry about it (but this obviously won't work for XCopy deployment etc). 但是,更好的解决方案是让您的安装程序安装.Net 3.5,这样您就不必担心它(但这显然不适用于XCopy部署等)。

Doing that in a .NET 3.5 application is going to be kinda hard, since you never get to the point where your application is started. 在.NET 3.5应用程序中执行此操作会有点困难,因为您从未达到应用程序启动的程度。

Generally this is done in the installer for the application, by adding a launch condition. 通常,这是通过添加启动条件在应用程序的安装程序中完成的。 See http://support.microsoft.com/kb/315291 请参见http://support.microsoft.com/kb/315291

EDIT: I found an article that explains how to write an unmanaged application to run before your .NET application starts (as suggested in ho1's answer) http://blogs.msdn.com/b/astebner/archive/2009/01/31/9387659.aspx 编辑:我发现了一篇文章,解释了如何在.NET应用程序启动之前编写一个非托管应用程序(如ho1的回答中所述) http://blogs.msdn.com/b/astebner/archive/2009/01/31 /9387659.aspx

Check out this C++ project that should do what you're asking for. 看看这个C ++项目应该做你想要的。

http://www.codeproject.com/KB/mcpp/DotNetTester.aspx http://www.codeproject.com/KB/mcpp/DotNetTester.aspx

You'd just set up your shortcuts to launch that app, which would in turn launch your .net app. 您只需设置快捷方式即可启动该应用,然后启动您的.net应用。

From the project description: 从项目描述:

For example (test for a minimum of FW 1.1 and launch an application): 例如(测试最低FW 1.1并启动应用程序):

dotNetTester.exe 1.1 C:\\Temp\\Myapp.exeC:\\Temp\\Myapp.exe dotNetTester.exe 1.1 C:\\ Temp \\ Myapp.exeC:\\ Temp \\ Myapp.exe

I re-read your question - you cannot run .NET x ver app when .NET x is not installed! 我重新阅读了您的问题 - 在未安装.NET x时无法运行.NET x ver应用程序! The end. 结束。

If you have it installed, then for other purpose- 如果你安装了它,那么出于其他目的 -

Use System.Environment.Version to find which version you are using currently. 使用System.Environment.Version查找当前使用的版本。

To know about all the versions installed, check this . 要了解所有已安装的版本, 请检查此项

Enumerate the subkeys of HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP. 枚举HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ NET Framework Setup \\ NDP的子项。 Each subkey is a .Net version. 每个子键都是.Net版本。 It should have Install=1 value if it's present on the machine, an SP value that shows the service pack and an MSI=1 value if it was installed using an MSI. 如果它存在于计算机上,则应具有Install = 1值,如果使用MSI安装,则应显示Service Pack的SP值和MSI = 1值。 (.Net 2.0 on Vista doesn't have the last one for example, as it is part of the OS) (例如Vista上的.Net 2.0没有最后一个,因为它是操作系统的一部分)

You can access this registry key "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP" and iterate over the values. 您可以访问此注册表项“HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ NET Framework Setup \\ NDP”并迭代值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将.NET Framework与Winforms应用程序捆绑在一起 - Bundling .NET Framework with Winforms app 如何从 .NET 框架应用程序以编程方式检查安装在我的机器上的 .NET Core Runtime 版本? - How to programmatically check the .NET Core Runtime version installed on my machine from a .NET Framework app? 以编程方式检查.NET Framework版本-我应该吗? - Programatically check for version .NET Framework - Should I? 有没有一种简单的方法来检查 .NET Framework 版本? - Is there an easy way to check the .NET Framework version? WinForms 中的app.config 文件是由.Net 框架缓存的吗? - is app.config file in WinForms cached by .Net framework? 如果app是winforms或asp.net,请使用预处理器进行检查 - Check using preprocessor if app is a winforms or asp.net .NET Winforms应用程序中的报告 - Reports in a .NET Winforms App 无法将自定义 ActiveX 控件添加到 .NET Core WinForms 应用程序,但 .NET Framework 应用程序工作正常 - Can't add custom ActiveX control to .NET Core WinForms app., but .NET Framework app works fine 如何使用可能不存在的.NET Framework版本安全地检查.NET Framework版本? - How to safely check .NET Framework version using a .NET Framework version that may not exist? 为什么具有相同目标框架版本的两个应用程序的.NET版本不同 - Why .NET version is different for two app with same target framework version
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM