PC Review


Reply
Thread Tools Rate Thread

How to detect whether terminal services is installed in Windows XP Pro

 
 
=?Utf-8?B?aWN5d2luZA==?=
Guest
Posts: n/a
 
      3rd Feb 2004
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
dwlConditionMas
)


Secode
#include <windows.h
#include <winbase.h

/* ------------------------------------------------------------
Note that the ValidateProductSuite and IsTerminalService
functions use ANSI versions of the functions to maintai
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 functio
/
// Terminal Services detection code for systems runnin
// 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"
&hKe
)
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;
}
 
Reply With Quote
 
 
 
 
Dario
Guest
Posts: n/a
 
      16th Feb 2004
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;
>}
>.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can my application detect if it is running in a Terminal Services client session? Alek Luchnikov Microsoft Access 1 13th Feb 2008 04:15 PM
How can my application detect if it is running in a Terminal Services client session? Alek Luchnikov Microsoft Access Getting Started 0 13th Feb 2008 12:36 PM
terminal services installed.... what next? =?Utf-8?B?ZHVrZQ==?= Microsoft Windows 2000 4 23rd Apr 2007 03:14 PM
Re: Can patches and SP's be remotely installed using Windows 2K Terminal Services ? Ray at Microsoft Windows 2000 0 1st Aug 2003 07:59 PM
Installed Office 2K before I installed terminal services. Now what? Microsoft Windows 2000 Terminal Server Applications 3 24th Jul 2003 11:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:40 AM.