Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Eric den Doop
  Where is Eric den Doop?
 Eric den Doop
 To: cerub
  Where is cerub?
Subject: RE: terminal services
Thread ID: 16165 Message ID: 16167 # Views: 3 # Ratings: 0
Version: Unknown Category: General VFP Topics
Date: Thursday, October 10, 2002 1:00:41 PM         

> Hello!
> I develop with VFP7.
> How can I to check, are the runned program on Terminal server client or simple windows platform
> Thanks,
> Cerub

See the code below. Most of it was taken from a MS KB article. I have modified it a little so that it works correctly on Windows XP boxes. XP has a feature called Remote Desktop and this feature is basically the same as a real TS.


FUNCTION IsTerminalServer

   * 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

   * 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.

   * 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)
   nMajorVersion = StrToLong(SUBSTR(OSVersion, 5, 4))
   cMajorVersion = ALLTRIM(STR(nMajorVersion))

  * win9x en winme zijn NOOIT een TS
   IF UPPER(LEFT(OS(), 10)) == "WINDOWS 4."
  		RETURN .F.
   * 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.
      RETURN .T.

   * 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.

   IF (nErrCode # 0) THEN
      RETURN .F.
      nTSEnabled = StrToLong(lpbValue)
   * Check to see if it is a Terminal Server	
   * EdD changed on 01-02-2002
   * AND toegevoegd voor XP bakken die zichzelf identificeren als Terminal Server (XP gebruikt dezelfde registry keys voor de remote desktop feature)
   * SYS(0) = "Windows 5.01" = WinXP http://fox.wikis.com/wc.dll?Wiki~VFPFunctionOS~VFP
   IF (nTSEnabled = 1) AND OS() # "Windows 5.01" THEN
       RETURN .T.
      RETURN .F.		


* This function converts a long to a string

   LOCAL nLoopVar, strReturn

   strReturn = ""
   FOR nLoopVar = 24 TO 0 STEP -8
      strReturn = CHR(INT(nLongVal/(2^nLoopVar))) + strReturn
      nLongVal = MOD(nLongVal, (2^nLoopVar))
RETURN strReturn

* This function converts a String to a Long

   LOCAL nLoopVar, nRetval

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

Excuse me for the ugly formatting. I do not have time to indent this code properly before posting it to the server.
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts


terminal services Posted by cerub @ 10/10/2002 11:06:53 AM
RE: terminal services Posted by Eric den Doop @ 10/10/2002 1:00:41 PM
RE: terminal services Posted by Luis Navas @ 10/10/2002 3:04:43 PM
RE: terminal services Posted by cerub @ 10/10/2002 4:50:32 PM