简体   繁体   English

如何识别Windows操作系统版本?

[英]How to recognize Windows OS version?

I am developing .NET 4 WPF application and this application should be able to export data to Excel xls worksheet. 我正在开发.NET 4 WPF应用程序,该应用程序应该能够将数据导出到Excel xls工作表。 However I need to resolve at runtime which version it is running on since there are still computers with Windows XP and Office 97/2000 on them. 但是我需要在运行时确定它正在运行哪个版本,因为仍然有配备Windows XP和Office 97/2000的计算机。

I wasn't able to export xls trough my application on Windows XP, Office 97/2000 because we don't own Office Interop libraries, versions 7, 8, or 9. 我无法通过Windows XP,Office 97/2000上的应用程序导出xls,因为我们不拥有版本7、8或9的Office Interop库。

Therefore I will export to CSV on Windows XP and xls on Windows 7 and Windows 10. 因此,我将在Windows XP上导出为CSV,在Windows 7和Windows 10上导出为xls。

I tried this code snippet but I am unsure if it is enough info to recognize if it is Win XP, 7 or 10. 我尝试了此代码段,但不确定是否足以识别它是Win XP,7还是10。

 public static string getOSVersion()
 {
      return Environment.OSVersion.ToString() + ", " + Environment.Version;
 }

I am getting this on Windows 10: 我在Windows 10上得到这个:

 Microsoft Windows NT 6.2.9200.0, 4.0.30319.42000

Is this enough information or is there a better way to recognize Windows OS Name? 这是足够的信息,还是有更好的方法来识别Windows OS名称?

System.Environment.Version will retrieve the Version of the .NET Framework used to execute your code, so this will not help you. System.Environment.Version将检索用于执行代码的.NET Framework的版本,因此这对您没有帮助。

The System.Environment.OSVersion object (OperatingSystem class) is indeed the correct way to get the Windows version. 实际上, System.Environment.OSVersion对象(OperatingSystem类)是获取Windows版本的正确方法。 You should however do something like this: 但是,您应该执行以下操作:

public static bool IsWindowsCurrentGen()
{
  if (Environment.OSVersion.Version.Major >= 6)
    return true;
  else
    return false;
}

This will return true for everything above (including) Windows Vista. 对于Windows Vista以上的所有版本(包括Windows Vista),都将返回true

For a "full" reference table see this StackOverflow question . 有关“完整”参考表,请参见此StackOverflow问题 Note, that it would be better from my point of view, to detect the installed Excel version rather than the OS version. 请注意,从我的角度来看,最好检测安装的Excel版本而不是OS版本。

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

相关问题 如何根据操作系统版本本地化Windows Phone - How to localize for Windows Phone based on OS version 如何以编程方式检测 Windows Phone 8.1 操作系统版本? - How to detect Windows Phone 8.1 OS version programmatically? 以编程方式获取 Windows 操作系统版本 - Getting Windows OS version programmatically 检测操作系统版本 - Windows Phone 7或Windows Phone 8? - Detect OS version - Windows Phone 7 or Windows Phone 8? Windows 8.1操作系统版本和其他设备信息 - Windows 8.1 Os version and other device info 启动条件:具有OS位的Windows OS Service Pack版本 - Launch Condition : Windows OS service pack version with OS bit visual studio无法识别版本10.0.14393.0中的Windows 10 sdk - visual studio does not recognize windows 10 sdk in version 10.0.14393.0 如何在Windows Mobile 7上的C#中获取操作系统名称和版本详细信息? - How can I get OS Name and Version details in C# on windows mobile 7? 如何在运行时检查操作系统版本,例如在 Windows 或 Linux 上,而不使用条件编译语句 - How to check the OS version at runtime, e.g. on Windows or Linux, without using a conditional compilation statement 如何检查UWP应用程序中的Windows 10操作系统版本以消除WACK测试失败? - How to check the Windows 10 OS version in an UWP app so as to eliminate WACK test fail?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM