//..
type
TWtsConnectStateClass = (WTSActive, WTSConnected, WTSConnectQuery,
WTSShadow, WTSDisconnected, WTSIdle, WTSListen,
WTSReset, WTSDown, WTSInit);
type
PWtsSessionInfo = ^TWtsSessionInfo;
_WTS_SESSION_INFOA =
packed record
SessionId : DWORD;
pWinStationName : LPTSTR;
State : TWtsConnectStateClass;
end;
TWtsSessionInfo = _WTS_SESSION_INFOA;
const
WTS_CURRENT_SERVER_HANDLE = 0;
type
TFNWtsEnumerateSessions =
function (hServer: THandle; Reserved: DWORD;
Version: DWORD;
out ppSessionInfo: PWtsSessionInfo;
out pCount: PDWORD): BOOL;
stdcall;
TFNWtsFreeMemory =
procedure(pMemory: Pointer);
stdcall;
//..
function ConStateToStr(
const conState: TWTSConnectStateClass):
String;
begin
case conState
of
WTSActive : Result := '
WTSActive';
WTSConnected : Result := '
WTSConnected';
WTSConnectQuery : Result := '
WTSConnectQuery';
WTSShadow : Result := '
WTSShadow';
WTSDisconnected : Result := '
WTSDisconnected';
WTSIdle : Result := '
WTSIdle';
WTSListen : Result := '
WTSListen';
WTSReset : Result := '
WTSReset';
WTSDown : Result := '
WTSDown';
WTSInit : Result := '
WTSInit';
else
Result := '
Unknown';
end;
end;
//..
var count : PDWord;
SessionInfo : PWtsSessionInfo;
begin
try
Win32Check(WtsEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, SessionInfo, count));
ShowMessage('
State=' + ConStateToStr(SessionInfo.State) + #13#10 +
'
SessionID=' + IntToStr(SessionInfo.SessionId) + #13#10 +
'
pWinStationName=' + SessionInfo.pWinStationName);
WtsFreeMemory(SessionInfo);
except
On E:
Exception do
//..
end;
end;