Use the WTSGetActiveConsoleSessionId function to obtain the SessionId of the console session, then use WTSQuerySessionInformation with the WTSUserName parameter to obtain the username.
Or using the Terminal Server
unit of the Security Library (JwsclTerminalServer):
Delphi-Quellcode:
uses JwaWindows, JwsclTerminalServer;
var
TS: TJwTerminalServer;
Session: TJwWTSSession;
begin
TS := TJwTerminalServer.Create;
if TS.EnumerateSessions then
begin
Session := ts.FindBySessionId(WTSGetActiveConsoleSessionId);
if Session <> nil then
begin
Memo1.Lines.Add(Session.Username);
end;
end;
TS.Free;
end;