我一直在尝试检测终端服务是否正在运行。我尝试使用MSDN 方式:
OSVERSIONINFOEX osVersionInfo;
DWORDLONG dwlConditionMask = 0;
memset( &osVersionInfo, 0, sizeof( osVersionInfo ) );
osVersionInfo.dwOSVersionInfoSize = sizeof( osVersionInfo );
osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;
VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );
return VerifyVersionInfo( &osVersionInfo, VER_SUITENAME, dwlConditionMask );
它运作良好,但在:
OS Name: Microsoft(R) Windows(R) Server 2003, Enterprise Edition
OS Version: 5.2.3790 Service Pack 2 Build 3790
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Server
OS Build Type: Multiprocessor Free
如果没有终端服务角色,则调用VerifyVersionInfo
返回一个非零值,这意味着“当前运行的操作系统满足指定的要求”或函数失败。
GetLastError
返回:
0x000000cb "The system could not find the environment option that was entered."
在 Windows XP SP3 上,调用VerifyVersionInfo
返回一个零值,所以我想没有输入错误。
我该如何处理这种行为?将其视为没有终端服务是否很好?有没有更好的技术?
它是操作系统中的错误吗?
更新:
在 Windows Server 2008 R1 上,行为类似(失败)。也可能在许多其他系统上。