Hi,
The code in the listing is meant to detect whether the
server part of terminal services is installed.
It's not meant to detect if the RDP client, which is the
only component you may have in a WinXP box, is installed.
You are probably trying to detect the client as WinXP
cannot be configured as a TS Server (Only NT TSE, Win2K
Server or W2k3 server may)
In order to determine if TS client is installed you may
search the registry for
the "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Server
Client\Installed Components" key. You may look at
the "IsInstalled" value, which will be 1 if the client is
installed. The "Version" value will tell you which version
is installed.
Hope this helps
>-----Original Message-----
>I find some source code in MSDN. These code is used to
detect whether terminal services is installed in windows.
>
>I known terminal services is install in WindowsXP Pro.
However, when I run these code in windowsXP Pro, the
result is the terminal services isn't install. Why?
>
>The following is the source code in MSDN.
>First:
>BOOL AreWeRunningTerminalServices(void)
>{
> OSVERSIONINFOEX osVersionInfo;
> DWORDLONG dwlConditionMask = 0;
>
> ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFOEX));
> osVersionInfo.dwOSVersionInfoSize = sizeof
(OSVERSIONINFOEX);
> osVersionInfo.wSuiteMask = VER_SUITE_TERMINAL;
>
> VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME,
VER_AND );
>
> return VerifyVersionInfo(
> &osVersionInfo,
> VER_SUITENAME,
> dwlConditionMask
> );
>}
>
>Secode:
>#include <windows.h>
>#include <winbase.h>
>
>/* -------------------------------------------------------
------
> Note that the ValidateProductSuite and
IsTerminalServices
> functions use ANSI versions of the functions to
maintain
> compatibility with Windows 95/98/Me.
> -------------------------------------------------------
------ */
>
>BOOL ValidateProductSuite (LPSTR lpszSuiteToValidate);
>
>BOOL IsTerminalServicesEnabled( VOID )
>{
> BOOL bResult = FALSE;
> DWORD dwVersion;
> OSVERSIONINFOEXA osVersion;
> DWORDLONG dwlCondition = 0;
> HMODULE hmodK32 = NULL;
> HMODULE hmodNtDll = NULL;
> typedef ULONGLONG (WINAPI *PFnVerSetCondition)
(ULONGLONG, ULONG, UCHAR);
> typedef BOOL (WINAPI *PFnVerifyVersionA)
(POSVERSIONINFOEXA, DWORD, DWORDLONG);
> PFnVerSetCondition pfnVerSetCondition;
> PFnVerifyVersionA pfnVerifyVersionA;
>
> dwVersion = GetVersion();
>
> // Are we running Windows NT?
>
> if (!(dwVersion & 0x80000000))
> {
> // Is it Windows 2000 or greater?
>
> if (LOBYTE(LOWORD(dwVersion)) > 4)
> {
> // On Windows 2000 and later, use the
VerifyVersionInfo and
> // VerSetConditionMask functions. Don't static link
because
> // it won't load on earlier systems.
>
> hmodNtDll = GetModuleHandleA( "ntdll.dll" );
> if (hmodNtDll)
> {
> pfnVerSetCondition = (PFnVerSetCondition)
GetProcAddress(
> hmodNtDll, "VerSetConditionMask");
> if (pfnVerSetCondition != NULL)
> {
> dwlCondition = (*pfnVerSetCondition)
(dwlCondition,
> VER_SUITENAME, VER_AND);
>
> // Get a VerifyVersionInfo pointer.
>
> hmodK32 = GetModuleHandleA( "KERNEL32.DLL" );
> if (hmodK32 != NULL)
> {
> pfnVerifyVersionA = (PFnVerifyVersionA)
GetProcAddress(
> hmodK32, "VerifyVersionInfoA") ;
> if (pfnVerifyVersionA != NULL)
> {
> ZeroMemory(&osVersion, sizeof(osVersion));
> osVersion.dwOSVersionInfoSize = sizeof
(osVersion);
> osVersion.wSuiteMask = VER_SUITE_TERMINAL;
> bResult = (*pfnVerifyVersionA) (&osVersion,
> VER_SUITENAME, dwlCondition);
> }
> }
> }
> }
> }
> else // This is Windows NT 4.0 or earlier.
>
> bResult = ValidateProductSuite( "Terminal Server" );
> }
>
> return bResult;
>}
>
>//////////////////////////////////////////////////////////
//
>// ValidateProductSuite function
>//
>// Terminal Services detection code for systems running
>// Windows NT 4.0 and earlier.
>//
>//////////////////////////////////////////////////////////
//
>
>BOOL ValidateProductSuite (LPSTR lpszSuiteToValidate)
>{
> BOOL fValidated = FALSE;
> LONG lResult;
> HKEY hKey = NULL;
> DWORD dwType = 0;
> DWORD dwSize = 0;
> LPSTR lpszProductSuites = NULL;
> LPSTR lpszSuite;
>
> // Open the ProductOptions key.
>
> lResult = RegOpenKeyA(
> HKEY_LOCAL_MACHINE,
> "System\\CurrentControlSet\\Control\\ProductOptions"
,
> &hKey
> );
> if (lResult != ERROR_SUCCESS)
> goto exit;
>
> // Determine required size of ProductSuite buffer.
>
> lResult = RegQueryValueExA( hKey, "ProductSuite", NULL,
&dwType,
> NULL, &dwSize );
> if (lResult != ERROR_SUCCESS || !dwSize)
> goto exit;
>
> // Allocate buffer.
>
> lpszProductSuites = (LPSTR) LocalAlloc( LPTR, dwSize );
> if (!lpszProductSuites)
> goto exit;
>
> // Retrieve array of product suite strings.
>
> lResult = RegQueryValueExA( hKey, "ProductSuite", NULL,
&dwType,
> (LPBYTE) lpszProductSuites, &dwSize );
> if (lResult != ERROR_SUCCESS || dwType != REG_MULTI_SZ)
> goto exit;
>
> // Search for suite name in array of strings.
>
> lpszSuite = lpszProductSuites;
> while (*lpszSuite)
> {
> if (lstrcmpA( lpszSuite, lpszSuiteToValidate ) ==
0)
> {
> fValidated = TRUE;
> break;
> }
> lpszSuite += (lstrlenA( lpszSuite ) + 1);
> }
>
>exit:
> if (lpszProductSuites)
> LocalFree( lpszProductSuites );
>
> if (hKey)
> RegCloseKey( hKey );
>
> return fValidated;
>}
>.
>
|