3 out of 6 rated this helpful - Rate this topic

GetOwner method of the Win32_Process Class

Applies to: desktop apps only

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

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 client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Namespace

\root\CIMV2

MOF

Cimwin32.mof

DLL

Cimwin32.dll

See also

Operating System Classes
Win32_Process

 

 

Send comments about this topic to Microsoft

Build date: 3/9/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ