How to find process owner?  Download
This page presents a Delphi 7 function that retrieves the name of the user that owns (started) a process. Normally the logged user or SYSTEM owns the processes on a workstation. On a server the processes may be owned by many different users. This example is using TWmiProcessControl component from WmiSet component collection. The source code below creates and destroys the components on the fly, so it may be used UI- and in console-type applications.

// this function returns the owner of a running process 
// It may be used for local or remote host. When used for local host 
// TargetHost, UserName, Password parameters must be empty. 
// For remote computer the parameters must be: 
// TargetHost: name or IP address of the remote host, like '10.8.36.54' 
// UserName: name of the user, may include domain, like 'MOON\Administrator'; 
// Password: the user's password. 
// AProcess: either a name (as returned by process_enumerate_query.exe example) 
//           or a handle of a process (integer value); 
// It returns a name of the user in the form DOMAIN\USERNAME 
function ProcessGetOwner(TargetHost, UserName, Password, AProcess: string): string; 
var
  ProcessControl: TWmiProcessControl;
  i: integer;
  vProcessHandle: cardinal;
  vProcess: TWmiProcess;
  vUserName, vDomain: widestring;
begin
  ProcessControl := TWmiProcessControl.Create(nil);
  try
    ProcessControl.MachineName := TargetHost;
    ProcessControl.Credentials.UserName := UserName;
    ProcessControl.Credentials.Password := Password;

    // exception may happen on Win9x, WinNT if WMI core is not installed; 
    // The provided credentials may also be invalid. 
    ProcessControl.Active := true;
    vProcessHandle := StrToIntDef(AProcess, -1);
    for i := 0 to ProcessControl.Processes.Count - 1 do
    begin
      vProcess := ProcessControl.Processes[i];
      if (vProcessHandle = vProcess.Handle) or
         (AProcess = vProcess.Name) then
        begin
           // this method may return empty values, or throw exception 
           // if current user does not have enough permissions. 
          vProcess.GetProcessOwner(vUserName, vDomain);
          if (vDomain <> '') and (vUserName <> '') then
            Result := vDomain + '\' + vUserName
          else if (vUserName <> '') then
            Result := vUserName
          else
            raise Exception.Create('Not enough permissions');  
          Exit;
        end;
    end;

    raise Exception.Create('Specified process not found.');
  finally
    ProcessControl.Free;
  end;
end;