title: How to check if a process belongs to the current user?
body: <p>I'm trying to get PIDs of processes which belongs to the current user but I don't know how to check the process owner.</p>
  
  <p>This is my code (the user's checking condition is missing):</p>
  
  <pre><code>uses
    TlHelp32, ...;
  
  type
    TCardinalArray = array of Cardinal;
  
  function GetCurrentUserPIDs(const AProcessName : string) : TCardinalArray;
  var
    ContinueLoop: boolean;
    FSnapshotHandle: THandle;
    FProcessEntry32: TProcessEntry32;
  begin
    SetLength(Result, 0);
    FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
    ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
    while(ContinueLoop) do
    begin
      if(SameText(FProcessEntry32.szExeFile, AProcessName)) then
      begin
        if((* is this my process? *)) then
        begin
          SetLength(Result, Length(Result) + 1);
          Result[Length(Result) - 1] := FProcessEntry32.th32ProcessID;
        end;
      end;
      ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
    end;
    CloseHandle(FSnapshotHandle);
  end;
  </code></pre>