I have a need to find the current domain\username for a program. Running under XP, I find that using the JEDI functions:
sWinUser := GetDomainName + '\' + GetLocalUserName;
works just fine.
When running under terminal server though, the administrator privileged users seem to be running as the console user. So if "doug" is logged in at the terminal server console, even though I am logged in as "james" the function will return "doug"!
After reading some more information, I thought that using the wtsapi32.dll would be the answer, it has a function to return the session information, WTSQuerySessionInformation. It doesn't seem to work for me though. has anybody used this function successfully? If so, can some one shed some light on how to do it? Or even if there is a different way to find the info I am after?
Many thanks in advance,
James McGinty
获取WTS用户名
uses WTSAPI32;
function GetWTSUser: string;
var
Len: DWORD;
UserName: PWideChar;
begin
Len := 0;
if WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSUserName, Pointer(UserName), Len) then
begin
Result := Widestring(UserName);
WTSFreeMemory(UserName);
end;
end;