简体   繁体   English

在Windows 2008 R2 SP1上使用GetVersionEx时的错误行为

[英]Incorrect behavior while using GetVersionEx on Windows 2008 R2 SP1

I want to check if Windows operating system's version is Windows 2008 or Above. 我想检查Windows操作系统的版本是否为Windows 2008或更高版本。 I am using following piece of code, it works just fine in my environment but someone(customer) has reported that it's not working on their production OS environment but works on other systems having Windows 2008 R2 SP1. 我正在使用以下代码,它在我的环境中可以正常工作,但是有人(客户)报告说,它不能在其生产OS环境中工作,但可以在具有Windows 2008 R2 SP1的其他系统上工作。 It's not working means it returns false even in case OS is Windows 2008 R2 SP1. 它无法正常工作,即使操作系统为Windows 2008 R2 SP1,它也会返回false。 What's wrong with the code? 代码有什么问题?

bool CheckIfOperatingISWindowsServer2K8orAbove()
{
  OSVERSIONINFOEX winOSInfo;
  winOSInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFOEX);
  GetVersionEx(&winOSInfo);

  //Check if windows version is 6 (i.e longhorn) and its windows server 
  if( winOSInfo.dwPlatformId==VER_PLATFORM_WIN32_NT && winOSInfo.dwMajorVersion == 6 && winOSInfo.wProductType == VER_NT_SERVER)
  {
     if ( winOSInfo.dwMinorVersion == 0 || winOSInfo.dwMinorVersion == 1 ) 
      return true;  
  }

  return false;
}

I think of only missing part is not initializing winOSInfo to value 0 using ZeroMemory(&winfo, sizeof(OSVERSIONINFOEX)); 我认为唯一缺少的部分不是使用ZeroMemory(&winfo,sizeof(OSVERSIONINFOEX))将winOSInfo初始化为0。

What's your opinion? 你怎么看? Do you think not initializing OSVERSIONINFOEX structure causes this kind of issues? 您是否认为不初始化OSVERSIONINFOEX结构会导致此类问题?

Thanks in advance. 提前致谢。

Could you check with your customer if their server 2008 R2 is configured as domain controller? 您能否与客户确认他们的服务器2008 R2是否配置为域控制器?

Because in the documentation of the structure OSVERSIONINFOEX it is indicated, in wProductType/VER_NT_SERVER: 因为在结构OSVERSIONINFOEX的文档中指出了它,所以在wProductType / VER_NT_SERVER中:

Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER. 请注意,也是域控制器的服务器报告为VER_NT_DOMAIN_CONTROLLER,而不是VER_NT_SERVER。

And in this case, your code will not give the expected result. 在这种情况下,您的代码将无法获得预期的结果。

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

相关问题 CopyFile / CopyFileEx在Windows Server 2008 R2 SP1 x64中不起作用 - CopyFile/CopyFileEx not working in Windows Server 2008 R2 SP1 x64 如何在Windows 2008 R2中使用CreateVirtualDisk创建差异VHD - How to create a differencing VHD using CreateVirtualDisk in Windows 2008 R2 Windows Server 2008 r2上BluetoothGetRadioInfo的替代方法 - Alternative to BluetoothGetRadioInfo on Windows Server 2008 r2 Windows 2008 R2中缺少多播消息 - Missing multicast messages in Windows 2008 R2 在Windows 7 x64上使用Visual Studio 2008 SP1(msvc9)进行stlport编译不起作用 - stlport compilation with Visual Studio 2008 SP1 (msvc9) on Windows 7 x64 doesn't work 在 Windows Server 2012 R2 上构建的应用程序在 Windows Server 2008 R2 上失败 - Application built on Windows Server 2012 R2 fails on windows server 2008 R2 Windows Server 2008 R2上的常见对话框:GetOpenFileName中崩溃 - Common Dialogs on Windows Server 2008 R2: crash in GetOpenFileName NetUserAdd在工作组Windows Server 2008 R2上运行时失败 - NetUserAdd failing when running on workgroup Windows Server 2008 R2 Windows 8下的GetVersionEx - GetVersionEx under Windows 8 VS2008 SP1中对Lambda表达式的支持 - Lambda expressions support in VS2008 SP1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM