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

MOF
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

Returns a value of 0 (zero) if successful, and any other number to indicate an error.

Return codeDescription
0

Successful Completion

2

Access Denied

3

Insufficient Privilege

8

Unknown Failure

9

Path Not Found

21

Invalid Parameter

 

Examples

For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.

For C++ code examples, see WMI C++ Application Examples.

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 clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
MOFCimwin32.mof
DLLCimwin32.dll
Namespace\root\cimv2

See Also

Operating System Classes
Win32_Process

Send comments about this topic to Microsoft

Build date: 11/3/2009

Tags :


Page view tracker