...determine if my program/Service is running under the System account?

Author: Michael Fritzsche

Category: System

function OnSystemAccount(): Boolean;
const
  
cnMaxNameLen = 254;
var
  
sName: string;
  dwNameLen: DWORD;
begin
  
dwNameLen := cnMaxNameLen - 1;
  SetLength(sName, cnMaxNameLen);
  GetUserName(PChar(sName), dwNameLen);
  SetLength(sName, dwNameLen);
  if UpperCase(Trim(sName)) = 'SYSTEM' then Result := True 
  else 
    
Result := False;
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base