Export (0) Print
Expand All

GetOwner method of the Win32_Process class

The GetOwnerWMI class method retrieves the user name and domain name under which the process is running.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax


uint32 GetOwner(
  [out]  string User,
  [out]  string Domain
);

Parameters

User [out]

Returns the user name of the owner of this process.

Domain [out]

Returns the domain name under which this process is running.

Return value

Return codeDescription
0

Successful Completion

2

Access Denied

3

Insufficient Privilege

8

Unknown Failure

9

Path Not Found

21

Invalid Parameter

 

Examples

The Monitor Process CPU Pct by Name with Owner VBScript sample collects the CPU or Processor utilization percent and looks up the process owner.

The Get all servers that a list of users is logged onto PowerShell sample querys WMI for the owner of all explorer.exe processes.

The following VBScript code example obtains the owner for each running process.

strComputer = "."
Set colProcesses = GetObject("winmgmts:" & _
   "{impersonationLevel=impersonate}!\\" & strComputer & _
   "\root\cimv2").ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcesses

    Return = objProcess.GetOwner(strNameOfUser)
    If Return <> 0 Then
        Wscript.Echo "Could not get owner info for process " & _  
            objProcess.Name & VBNewLine _
            & "Error = " & Return
    Else 
        Wscript.Echo "Process " _
            & objProcess.Name & " is owned by " _ 
            & "\" & strNameOfUser & "."
    End If
Next

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

Namespace

\root\CIMV2

MOF

CIMWin32.mof

DLL

CIMWin32.dll

See also

Operating System Classes
Win32_Process

 

 

Show:
© 2014 Microsoft