Actually I get this login SID, which is definitly a Session Logon ID :
(S-1-5-5-0-946199)
I translated your source
- I hope it correct.
Delphi-Quellcode:
constructor TSecurityToken.CreateWTSQueryUserToken(SessionID : Cardinal {= INVALID_HANDLE_VALUE});
begin
Self.Create;
fShared := FALSE;
if SessionID = INVALID_HANDLE_VALUE then
SessionID := WtsGetActiveConsoleSessionID;
fAccessMask := TOKEN_ALL_ACCESS;
if not WTSQueryUserToken(SessionID, fTokenHandle) then
raise ESMWinCallFailedException.CreateFmtEx('A call to WTSQueryUserToken failed. ',
'WTSQueryUserToken',ClassName,'USM_Token.pas', 0,true,[]);
end;
function GetLogonSID(aToken: TSecurityToken) : TSecurityID;
var i : integer;
ptg : TSecurityIDList;
begin
result := nil;
ptg := aToken.GetTokenGroups;
// Loop through the groups to find the logon SID.
for i := 0 to ptg.Count-1 do
begin
if (ptg[i].Attributes and SE_GROUP_LOGON_ID) = SE_GROUP_LOGON_ID then
begin
// Found the logon SID; make a copy of it.
result := TSecurityID.Create(ptg[i].CreateCopyOfSID);
Break;
end;
end;
end;
And the code that replaces the old one :
Delphi-Quellcode:
var WTSToken := TSecurityToken;
aLocalGroups : TSecurityID;
...
WTSToken := TSecurityToken.CreateWTSQueryUserToken();
aLocalGroups := TSecurityIDList.Create(true);
aLogonSid := GetLogonSID(WTSToken);
ShowMessage('aLogonSid: '+ aLogonSid.GetText(true));
aLocalGroups.Add(aLogonSid);
aLocalGroups.Add(TSecurityID.Create('','DebuggerUser'));
aLocalGroups.Add(AdministratorsSID);