1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| const
wtsapi = 'wtsapi32.dll';
type
handle = longword;
_WTS_CONNECTSTATE_CLASS = (
WTSActive, // User logged on to WinStation
WTSConnected, // WinStation connected to client
WTSConnectQuery, // In the process of connecting to client
WTSShadow, // Shadowing another WinStation
WTSDisconnected, // WinStation logged on without client
WTSIdle, // Waiting for client to connect
WTSListen, // WinStation is listening for connection
WTSReset, // WinStation is being reset
WTSDown, // WinStation is down due to error
WTSInit); // WinStation in initialization
{$EXTERNALSYM _WTS_CONNECTSTATE_CLASS}
WTS_CONNECTSTATE_CLASS = _WTS_CONNECTSTATE_CLASS;
{$EXTERNALSYM WTS_CONNECTSTATE_CLASS}
TWtsConnectStateClass = WTS_CONNECTSTATE_CLASS;
PWTS_SESSION_INFOW = ^WTS_SESSION_INFOW;
{$EXTERNALSYM PWTS_SESSION_INFOW}
_WTS_SESSION_INFOW = record
SessionId: DWORD; // session id
pWinStationName: LPWSTR; // name of WinStation this session is connected to
State: WTS_CONNECTSTATE_CLASS; // connection state (see enum)
end;
{$EXTERNALSYM _WTS_SESSION_INFOW}
WTS_SESSION_INFOW = _WTS_SESSION_INFOW;
{$EXTERNALSYM WTS_SESSION_INFOW}
TWtsSessionInfoW = WTS_SESSION_INFOW;
PWtsSessionInfoW = PWTS_SESSION_INFOW;
WTS_SESSION_INFO = WTS_SESSION_INFOW;
PWTS_SESSION_INFO = PWTS_SESSION_INFOW;
TWtsSessionInfo = TWtsSessionInfoW;
PWtsSessionInfo = PWtsSessionInfoW;
//function WTSOpenServer(pServerName: LPWSTR): HANDLE; stdcall;
function WTSOpenServer(pServerName: LPWSTR): HANDLE;stdcall; external wtsapi name 'WTSOpenServerW';
function WTSEnumerateSessions(hServer: HANDLE; Reserved: DWORD; Version: DWORD;var ppSessionInfo: PWTS_SESSION_INFOW; var pCount: DWORD): BOOL;stdcall; external wtsapi name 'WTSEnumerateSessionsW';
procedure WTSFreeMemory(pMemory: PVOID);stdcall; external wtsapi name 'WTSFreeMemory';
procedure TForm1.Button1Click(Sender: TObject);
var
fhserveur : longword;
booOk : boolean;
ppsession : PWTS_SESSION_INFO;
nbSession : dword ;
begin
fhserveur := WTSOpenServer ( pchar ( 'localhost' ));
if fhserveur = 0 then exit;
try
booOk := WTSEnumerateSessions ( fhserveur, 0, 1, ppsession, nbSession ); // çà plante ici
caption := inttostr(nbSession);
WTSFreeMemory (ppsession );
except
on e:exception do
memo1.Lines.Add( e.Message );
end;
end; |
Partager