whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

27 Visitors Online


 
...Detect terminal services?
Autor: P. Below
[ Print tip ]  

Tip Rating (7):  
     


{
 Question:

 Do you happen to have a sample piece of code for detecting if Terminal
 Services is loaded?  I found this piece of C code, but I'm having a hard
 time translating things...
}

function IsRemoteSession: Boolean;
const
  
sm_RemoteSession = $1000; { from WinUser.h }
begin
  
Result := (GetSystemMetrics(sm_RemoteSession) <> 0);
end;

{
  That tells you if your program is running in a terminal client session,
  which is usually all you ever need to worry about.
}

{
>
> #include <windows.h>
> #include <stdio.h>
>
> // This code will only work on the Windows 2000 platform
>
> BOOL IsTerminalServicesEnabled(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
>          );
>
}

type
  
OSVERSIONINFOEX = packed record
    
dwOSVersionInfoSize: DWORD;
    dwMajorVersion: DWORD;
    dwMinorVersion: DWORD;
    dwBuildNumber: DWORD;
    dwPlatformId: DWORD;
    szCSDVersion: array[0..127] of Char;
    wServicePackMajor: WORD;
    wServicePackMinor: WORD;
    wSuiteMask: WORD;
    wProductType: BYTE;
    wReserved: BYTE;
  end;
  TOSVersionInfoEx = OSVERSIONINFOEX;
  POSVersionInfoEx = ^TOSVersionInfoEx;

const
  
VER_SUITE_TERMINAL = $00000010;
  VER_SUITENAME = $00000040;
  VER_AND = 6;

function VerSetConditionMask(
  ConditionMask: int64;
  TypeMask: DWORD;
  Condition: Byte
  ): int64; stdcallexternal kernel32;

function VerifyVersionInfo(
  var VersionInformation: OSVERSIONINFOEX;
  dwTypeMask: DWORD;
  dwlConditionMask: int64
  ): BOOL; stdcallexternal kernel32 name 'VerifyVersionInfoA';


function IsTerminalServicesEnabled: Boolean;
var
  
osVersionInfo: OSVERSIONINFOEX;
  dwlConditionMask: int64;
begin
  
FillChar(osVersionInfo, SizeOf(osVersionInfo), 0);
  osVersionInfo.dwOSVersionInfoSize := sizeof(osVersionInfo);
  osVersionInfo.wSuiteMask := VER_SUITE_TERMINAL;
  dwlConditionMask := 0;
  dwlConditionMask :=
    VerSetConditionMask(dwlConditionMask,
    VER_SUITENAME,
    VER_AND);
  Result := VerifyVersionInfo(
    osVersionInfo,
    VER_SUITENAME,
    dwlConditionMask);
end;

{
  But heed the warning in the C sample: the functions used here are not
  available on Win 9x and NT 4! If you use external declarations as above
  your program would not even load on such a platform.
}


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners