📄 wtsapi32.pas
字号:
unit WtsApi32;
interface
// Windows Terminal Server public APIs
//
// Copyright 1995-1999, Citrix Systems Inc.
// Copyright (c) 1997-1999 Microsoft Corporation
//==============================================================================
// Defines
//==============================================================================
//
// Specifies the current server
//
const
WTS_CURRENT_SERVER = THandle(0);
{$EXTERNALSYM WTS_CURRENT_SERVER}
WTS_CURRENT_SERVER_HANDLE = THandle(0);
{$EXTERNALSYM WTS_CURRENT_SERVER_HANDLE}
WTS_CURRENT_SERVER_NAME = '';
{$EXTERNALSYM WTS_CURRENT_SERVER_NAME}
//
// Specifies the current session (SessionId)
//
WTS_CURRENT_SESSION = DWORD(-1);
{$EXTERNALSYM WTS_CURRENT_SESSION}
//
// Possible pResponse values from WTSSendMessage()
//
IDTIMEOUT = 32000;
{$EXTERNALSYM IDTIMEOUT}
IDASYNC = 32001;
{$EXTERNALSYM IDASYNC}
//
// Shutdown flags
//
WTS_WSD_LOGOFF = $00000001; // log off all users except
{$EXTERNALSYM WTS_WSD_LOGOFF} // current user; deletes
// WinStations (a reboot is
// required to recreate the
// WinStations)
WTS_WSD_SHUTDOWN = $00000002; // shutdown system
{$EXTERNALSYM WTS_WSD_SHUTDOWN}
WTS_WSD_REBOOT = $00000004; // shutdown and reboot
{$EXTERNALSYM WTS_WSD_REBOOT}
WTS_WSD_POWEROFF = $00000008; // shutdown and power off (on
{$EXTERNALSYM WTS_WSD_POWEROFF}
// machines that support power
// off through software)
WTS_WSD_FASTREBOOT = $00000010; // reboot without logging users
{$EXTERNALSYM WTS_WSD_FASTREBOOT} // off or shutting down
//==============================================================================
// WTS_CONNECTSTATE_CLASS - Session connect state
//==============================================================================
type
_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;
//==============================================================================
// WTS_SERVER_INFO - returned by WTSEnumerateServers (version 1)
//==============================================================================
//
// WTSEnumerateServers() returns two variables: pServerInfo and Count.
// The latter is the number of WTS_SERVER_INFO structures contained in
// the former. In order to read each server, iterate i from 0 to
// Count-1 and reference the server name as
// pServerInfo[i].pServerName; for example:
//
// for ( i=0; i < Count; i++ ) {
// _tprintf( TEXT("%s "), pServerInfo[i].pServerName );
// }
//
// The memory returned looks like the following. P is a pServerInfo
// pointer, and D is the string data for that pServerInfo:
//
// P1 P2 P3 P4 ... Pn D1 D2 D3 D4 ... Dn
//
// This makes it easier to iterate the servers, using code similar to
// the above.
//
type
PWTS_SERVER_INFOW = ^WTS_SERVER_INFOW;
{$EXTERNALSYM PWTS_SERVER_INFOW}
_WTS_SERVER_INFOW = record
pServerName: LPWSTR; // server name
end;
{$EXTERNALSYM _WTS_SERVER_INFOW}
WTS_SERVER_INFOW = _WTS_SERVER_INFOW;
{$EXTERNALSYM WTS_SERVER_INFOW}
TWtsServerInfoW = WTS_SERVER_INFOW;
PWtsServerInfoW = PWTS_SERVER_INFOW;
PWTS_SERVER_INFOA = ^WTS_SERVER_INFOA;
{$EXTERNALSYM PWTS_SERVER_INFOA}
_WTS_SERVER_INFOA = record
pServerName: LPSTR; // server name
end;
{$EXTERNALSYM _WTS_SERVER_INFOA}
WTS_SERVER_INFOA = _WTS_SERVER_INFOA;
{$EXTERNALSYM WTS_SERVER_INFOA}
TWtsServerInfoA = WTS_SERVER_INFOA;
PWtsServerInfoA = PWTS_SERVER_INFOA;
{$IFDEF UNICODE}
WTS_SERVER_INFO = WTS_SERVER_INFOW;
{$EXTERNALSYM WTS_SERVER_INFO}
PWTS_SERVER_INFO = PWTS_SERVER_INFOW;
{$EXTERNALSYM PWTS_SERVER_INFO}
TWtsServerInfo = TWtsServerInfoW;
PWtsServerInfo = PWtsServerInfoW;
{$ELSE}
WTS_SERVER_INFO = WTS_SERVER_INFOA;
{$EXTERNALSYM WTS_SERVER_INFO}
PWTS_SERVER_INFO = PWTS_SERVER_INFOA;
{$EXTERNALSYM PWTS_SERVER_INFO}
TWtsServerInfo = TWtsServerInfoA;
PWtsServerInfo = PWtsServerInfoA;
{$ENDIF}
//==============================================================================
// WTS_SESSION_INFO - returned by WTSEnumerateSessions (version 1)
//==============================================================================
//
// WTSEnumerateSessions() returns data in a similar format to the above
// WTSEnumerateServers(). It returns two variables: pSessionInfo and
// Count. The latter is the number of WTS_SESSION_INFO structures
// contained in the former. Iteration is similar, except that there
// are three parts to each entry, so it would look like this:
//
// for ( i=0; i < Count; i++ ) {
// _tprintf( TEXT("%-5u %-20s %u\n"),
// pSessionInfo[i].SessionId,
// pSessionInfo[i].pWinStationName,
// pSessionInfo[i].State );
// }
//
// The memory returned is also segmented as the above, with all the
// structures allocated at the start and the string data at the end.
// We'll use S for the SessionId, P for the pWinStationName pointer
// and D for the string data, and C for the connect State:
//
// S1 P1 C1 S2 P2 C2 S3 P3 C3 S4 P4 C4 ... Sn Pn Cn D1 D2 D3 D4 ... Dn
//
// As above, this makes it easier to iterate the sessions.
//
type
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;
PWTS_SESSION_INFOA = ^WTS_SESSION_INFOA;
{$EXTERNALSYM PWTS_SESSION_INFOA}
_WTS_SESSION_INFOA = record
SessionId: DWORD; // session id
pWinStationName: LPSTR; // name of WinStation this session is connected to
State: WTS_CONNECTSTATE_CLASS; // connection state (see enum)
end;
{$EXTERNALSYM _WTS_SESSION_INFOA}
WTS_SESSION_INFOA = _WTS_SESSION_INFOA;
{$EXTERNALSYM WTS_SESSION_INFOA}
TWtsSessionInfoA = WTS_SESSION_INFOA;
PWtsSessionInfoA = PWTS_SESSION_INFOA;
{$IFDEF UNICODE}
WTS_SESSION_INFO = WTS_SESSION_INFOW;
PWTS_SESSION_INFO = PWTS_SESSION_INFOW;
TWtsSessionInfo = TWtsSessionInfoW;
PWtsSessionInfo = PWtsSessionInfoW;
{$ELSE}
WTS_SESSION_INFO = WTS_SESSION_INFOA;
PWTS_SESSION_INFO = PWTS_SESSION_INFOA;
TWtsSessionInfo = TWtsSessionInfoA;
PWtsSessionInfo = PWtsSessionInfoA;
{$ENDIF}
//==============================================================================
// WTS_PROCESS_INFO - returned by WTSEnumerateProcesses (version 1)
//==============================================================================
//
// WTSEnumerateProcesses() also returns data similar to
// WTSEnumerateServers(). It returns two variables: pProcessInfo and
// Count. The latter is the number of WTS_PROCESS_INFO structures
// contained in the former. Iteration is similar, except that there
// are four parts to each entry, so it would look like this:
//
// for ( i=0; i < Count; i++ ) {
// GetUserNameFromSid( pProcessInfo[i].pUserSid, UserName,
// sizeof(UserName) );
// _tprintf( TEXT("%-5u %-20s %-5u %s\n"),
// pProcessInfo[i].SessionId,
// UserName,
// pProcessInfo[i].ProcessId,
// pProcessInfo[i].pProcessName );
// }
//
// The memory returned is also segmented as the above, with all the
// structures allocated at the start and the string data at the end.
// We'll use S for the SessionId, R for the ProcessId, P for the
// pProcessName pointer and D for the string data, and U for pUserSid:
//
// S1 R1 P1 U1 S2 R2 P2 U2 S3 R3 P3 U3 ... Sn Rn Pn Un D1 D2 D3 ... Dn
//
// As above, this makes it easier to iterate the processes.
//
type
PWTS_PROCESS_INFOW = ^WTS_PROCESS_INFOW;
{$EXTERNALSYM PWTS_PROCESS_INFOW}
_WTS_PROCESS_INFOW = record
SessionId: DWORD; // session id
ProcessId: DWORD; // process id
pProcessName: LPWSTR; // name of process
pUserSid: PSID; // user's SID
end;
{$EXTERNALSYM _WTS_PROCESS_INFOW}
WTS_PROCESS_INFOW = _WTS_PROCESS_INFOW;
{$EXTERNALSYM WTS_PROCESS_INFOW}
TWtsProcessInfoW = WTS_PROCESS_INFOW;
PWtsProcessInfoW = PWTS_PROCESS_INFOW;
PWTS_PROCESS_INFOA = ^WTS_PROCESS_INFOA;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -