Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Terminal Server?
Message
From
10/10/2005 16:51:29
 
 
To
10/10/2005 16:34:00
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgia, United States
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 7 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01057779
Message ID:
01057785
Views:
9
1st example is from Richard Bean posted on the UT previously. I don't have a history of where the 2nd example came from.
&& Don't currently use all these DEFINEs, but could if we want to explore all 
&&  the Server Versions

#DEFINE VER_PLATFORM_WIN32S 0
#DEFINE VER_PLATFORM_WIN32_WINDOWS 1
#DEFINE VER_PLATFORM_WIN32_NT 2

#DEFINE VER_SERVER_NT                       0x80000000
#DEFINE VER_WORKSTATION_NT                  0x40000000

#DEFINE VER_NT_WORKSTATION		    0x00000001
#DEFINE VER_NT_DOMAIN_CONTROLLER	    0x00000002
#DEFINE VER_NT_SERVER               	    0x00000003

#DEFINE VER_SUITE_SMALLBUSINESS             0x00000001
#DEFINE VER_SUITE_ENTERPRISE                0x00000002
#DEFINE VER_SUITE_BACKOFFICE                0x00000004
#DEFINE VER_SUITE_COMMUNICATIONS            0x00000008
#DEFINE VER_SUITE_TERMINAL                  0x00000010
#DEFINE VER_SUITE_SMALLBUSINESS_RESTRICTED  0x00000020
#DEFINE VER_SUITE_EMBEDDEDNT                0x00000040
#DEFINE VER_SUITE_DATACENTER                0x00000080
#DEFINE VER_SUITE_SINGLEUSERTS              0x00000100
#DEFINE VER_SUITE_PERSONAL                  0x00000200
#DEFINE VER_SUITE_BLADE                     0x00000400

#DEFINE FFFF    			  0x0000FFFF && 65535

Declare LONG GetVersionEx in WIN32API STRING

STORE 0 to;
	 dwOSVersionInfoSize,;
    dwMajorVersion,;
    dwMinorVersion,;
    dwBuildNumber,;
    dwPlatformId,;
 	 wServicePackMajor,;
	 wServicePackMinor,;
	 wSuiteMask,;
	 wProductType,;
	 wReserved

szCSDVersion = ""
PId = "(Unknown)"

lczStructure = chr(5*4+127+1+3*2+2*1)+replicate(chr(0), 5*4-1)+;
               space(127)+chr(0)+replicate(chr(0), 3*2+2*1)

lcReturn = ""
lnResult = GetVersionEx( @lczStructure )
IF lnResult <> 0	&& No Error
	dwOSVersionInfoSize = asc2BEint(lczStructure, 1, 4)
	dwMajorVersion = asc2BEint(lczStructure, 5, 4)
	dwMinorVersion = asc2BEint(lczStructure, 9, 4)
	dwBuildNumber = BITAND(asc2BEint(lczStructure, 13, 4), FFFF)
	dwPlatformId = asc2BEint(lczStructure, 17, 4)
	szCSDVersion = ALLTRIM(CHRTRAN(SUBSTR(lczStructure, 21, 128),;
                       CHR(0)+CHR(1),""))
	IF dwOSVersionInfoSize > 148
		wServicePackMajor = asc2BEint(lczStructure, 149, 2)
		wServicePackMinor = asc2BEint(lczStructure, 151, 2)
		wSuiteMask = asc2BEint(lczStructure, 153, 2)
		wProductType = ASC(SUBSTR(lczStructure, 155, 1))
		wReserved = ASC(SUBSTR(lczStructure, 156, 1))
	ENDIF

	DO Case
	Case dwPlatformId = VER_PLATFORM_WIN32S
	    PId = "32s " 	&& "Windows 32s "

	Case dwPlatformId = VER_PLATFORM_WIN32_WINDOWS
	    PId = "95/98 " && "Windows 95/98 "
		DO CASE
		CASE dwMajorVersion = 4  and dwMinorVersion = 0
		   PId = "95 " && "Windows 95 "
		   lcSubVer = SUBSTR(szCSDVersion, 1, 1)
		   IF INLIST(lcSubVer, "B", "C")
		   	PId = PId + "OSR2 "
		   ENDIF
		CASE dwMajorVersion = 4  and dwMinorVersion = 10
		   PId = "98 " && "Windows 98 "
		   lcSubVer = SUBSTR(szCSDVersion, 1, 1)
		   IF lcSubVer = "A"
		   	PId = PId + "SE "
		   ENDIF
		CASE dwMajorVersion = 4  and dwMinorVersion = 90
		   PId = "ME " && "Windows ME "
		ENDCASE

	Case dwPlatformId = VER_PLATFORM_WIN32_NT
	    PId = "NT "			&& "Windows NT "
		DO CASE
		CASE dwMajorVersion <=  4
		   PId = "NT "			&& "Windows NT "

		CASE dwMajorVersion = 5 and dwMinorVersion = 0
		   PId = "2000 "		&& "Windows 2000 "

		CASE dwMajorVersion = 5 and dwMinorVersion = 1
		   PId = "XP "		&& "Windows XP "
		   IF BITAND(wSuiteMask, VER_SUITE_PERSONAL) <> 0
		   	PId = PId + "Home "
		   ELSE
		   	PId = PId + "Pro "
		   ENDIF
		ENDCASE
	ENDCASE

	lcReturn = PId ;
		+ ALLTRIM(transform(dwMajorVersion,"99999"));
		+ "." + ALLTRIM(transform(dwMinorVersion,"99999"));
		+ " (Build "+ ALLTRIM(transform(dwBuildNumber,"99999"));
		+ ":"+ IIF(EMPTY(szCSDVersion),"No SP", szCSDVersion);
		+ ")"
ENDIF
wait WINDOW lcReturn
RETURN lcReturn

FUNCTION asc2BEint

LPARAMETERS p_cString, p_nStart, p_nLength
IF PCOUNT() < 1 OR VARTYPE(p_cString) <> "C"
	RETURN -1
ENDIF

IF PCOUNT() < 2 OR VARTYPE(p_nStart) <> "N"
	p_nStart = 1
ENDIF
IF PCOUNT() < 3 OR VARTYPE(p_nLength) <> "N"
	p_nLength = LEN(p_cString)
ENDIF

LOCAL lnRet_val

DO CASE
CASE p_nLength = 1
   lnRet_val = asc(SUBSTR(p_cString, p_nStart, 1))

CASE p_nLength = 2
   lnRet_val = asc(SUBSTR(p_cString, p_nStart, 1));
   			+ asc(SUBSTR(p_cString, p_nStart+1, 1))*256

CASE p_nLength = 3
   lnRet_val = asc(SUBSTR(p_cString, p_nStart, 1));
   			+ asc(SUBSTR(p_cString, p_nStart+1, 1))*256;
   			+ asc(SUBSTR(p_cString, p_nStart+2, 1))*256^2

CASE p_nLength = 4
   lnRet_val = asc(SUBSTR(p_cString, p_nStart, 1));
   			+ asc(SUBSTR(p_cString, p_nStart+1, 1))*256;
   			+ asc(SUBSTR(p_cString, p_nStart+2, 1))*256^2;
   			+ asc(SUBSTR(p_cString, p_nStart+3, 1))*256^3

OTHERWISE
	lnRet_val = -1
ENDCASE

RETURN INT(lnRet_val)
*Start of Code
LOCAL lTerminalServer

lTerminalServer = IsTerminalServer()

IF (lTerminalServer) THEN
   =MESSAGEBOX ("This Computer is a Terminal Server")
ELSE
   =MESSAGEBOX("This Computer is not a Terminal Server")
ENDIF


FUNCTION IsTerminalServer
   * This function will determine if the machine is a Terminal Server.
   * It will return .T. if it is and .F. if not.

   * Constants that are needed for Registry functions
   #DEFINE HKEY_LOCAL_MACHINE -2147483646  && BITSET(0,31)+2
   #DEFINE REG_DWORD 4	                   && A 32-bit number.

   * WIN 32 API functions that are used
   DECLARE Integer RegOpenKey IN Win32API ;
      Integer nHKey, String @cSubKey, Integer @nResult
   DECLARE Integer RegQueryValueEx IN Win32API ;
      Integer nHKey, String lpszValueName, Integer dwReserved,;
      Integer @lpdwType, String @lpbData, Integer @lpcbData
   DECLARE Integer RegCloseKey IN Win32API ;
      Integer nHKey
   DECLARE GetVersionEx IN win32api STRING @OSVERSIONINFO

   * Local variables used
   LOCAL nErrCode	   && Error Code returned from Registry functions
   LOCAL nKeyHandle	   && Handle to Key that is opened in the Registry
   LOCAL lpdwValueType	   && Type of Value that we are looking for
   LOCAL lpbValue	   && The data stored in the value
   LOCAL lpcbValueSize	   && Size of the variable
   LOCAL lpdwReserved	   && Reserved Must be 0
   LOCAL cKey		   && Key we need to open
   LOCAL cValueToGet	   && Value to get
   LOCAL lTerminalServer   && True if it is a Terminal Server
   LOCAL nTSEnabled	   && Numeric value of TSEnabled
   LOCAL OSVersion	   && OS Version
   LOCAL cMajorVersion	   && Just the Version number i.e. 4 or 5
	
   * Initialize the variables
   cKey = "System\CurrentControlSet\Control\Terminal Server"
   cValueToGet = "TSEnabled"
   nKeyHandle = 0				
   lpdwReserved = 0	       && Must be 0
   lpdwValueType = REG_DWORD
   lpcbValueSize = 4	      && DWORD is 4 bytes
   lTerminalServer = .F.      && Assume it isn't a Terminal Server
   lpbValue = SPACE(4)

   nErrCode = RegOpenKey(HKEY_LOCAL_MACHINE, cKey, @nKeyHandle)
   * If the error code isn't 0, then the key doesn't exist or can't be opened.
   IF (nErrCode # 0) THEN
      RETURN .F.
   ENDIF

   * We need to check and see what version we are running NT 4 and Windows 2000 are different
   OSVersion = LongToStr(148) + REPLICATE(CHR(0), 144)
   =GetVersionEx(@OSVersion)
   nMajorVersion = StrToLong(SUBSTR(OSVersion, 5, 4))
   cMajorVersion = ALLTRIM(STR(nMajorVersion))

   * If it is NT 4 and we made it this far the machine is a Terminal Server
   IF (cMajorVersion = "4") THEN
      * Close the key when done.
      =RegCloseKey(nKeyHandle)
      RETURN .T.
   ENDIF

   * Get the value of TSEnabled. 1 is a Terminal  Server 0 isn't 
   nErrCode=RegQueryValueEx(nKeyHandle, cValueToGet, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize)

   * Close the key when done.
   =RegCloseKey(nKeyHandle)

   IF (nErrCode # 0) THEN
      RETURN .F.
   ELSE
      nTSEnabled = StrToLong(lpbValue)
   ENDIF
	
   * Check to see if it is a Terminal Server	
   IF (nTSEnabled = 1) THEN
       RETURN .T.
   ELSE
      RETURN .F.		
   ENDIF
ENDFUNC	

FUNCTION StrToLong
* This function converts a String to a Long
   PARAMETERS cLongStr

   LOCAL nLoopVar, nRetval

   nRetval = 0
   FOR nLoopVar = 0 TO 24 STEP 8
      nRetval = nRetval + (ASC(cLongStr) * (2^nLoopVar))
      cLongStr = RIGHT(cLongStr, LEN(cLongStr) - 1)
   NEXT
RETURN nRetval


FUNCTION LongToStr
* This function converts a long to a string
   PARAMETERS nLongVal

   LOCAL nLoopVar, strReturn

   strReturn = ""
   FOR nLoopVar = 24 TO 0 STEP -8
      strReturn = CHR(INT(nLongVal/(2^nLoopVar))) + strReturn
      nLongVal = MOD(nLongVal, (2^nLoopVar))
   NEXT
RETURN strReturn
*End of Code
>Is there an API call that will determine if Terminal Server is being used? Thanks!
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform