views:

34

answers:

2

I've been trying to detect whether or no the Terminal Services are running. I tried to use MSDN Way:

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 );

It works well, but on:

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

without Terminal Services role, call to VerifyVersionInfo returns non-zero value which means "the currently running operating system satisfies the specified requirements" or the function fails.

GetLastError returns:
0x000000cb "The system could not find the environment option that was entered."

On Windows XP SP3 call to VerifyVersionInfo returns zero value, so there are no typing errors, I suppose.

The question is: how to handle this behavior? Is it good to treat this as there are no Terminal Services? Are there any better techniques?

Is it a bug in OS?

Update: On Windows Server 2008 R1 behavior is similar (fails). May be on many other systems too.

A: 

Terminal Services is an NT-service like any other, internally named TermServices, and if you have the permission.privilege to access the service manager, you could poll there to see if it's running:

OpenSCManager OpenService QueryServiceStatus

Stijn Sanders
A: 

Well, I found almost working solution (fails only on Win2k server).

OSVERSIONINFOEX osVersionInfo;
DWORDLONG dwlConditionMask = 0;

memset( &osVersionInfo, 0, sizeof( osVersionInfo ) );
osVersionInfo.dwOSVersionInfoSize = sizeof( osVersionInfo );
osVersionInfo.wSuiteMask = VER_SUITE_SINGLEUSERTS;

VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );

return !VerifyVersionInfo( &osVersionInfo, VER_SUITENAME, dwlConditionMask );

Interesting fact - call to VerifyVersionInfo do not modify last error code. Error code 0x000000cb that GetLastError returns to me is just a garbage.

Victor Zhuravlev

related questions