How to List Process Owners using VBScript + WMI Object?


With WMI Object, we can list the process names and their owners easily. The WMI Query is:

Select * from Win32_Process

The following VBScript (under Windows Scripting Host environment) queries the Win32_Process and prints the name and the owners.

1
2
3
4
5
6
7
8
9
10
11
12
' List Process Owners
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
 
For Each objProcess in colProcessList
    colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
    Wscript.Echo "Process " & objProcess.Name & " is owned by " _ 
        & strUserDomain & "\" & strNameOfUser & "."
Next
' List Process Owners
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcessList
    colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
    Wscript.Echo "Process " & objProcess.Name & " is owned by " _ 
        & strUserDomain & "\" & strNameOfUser & "."
Next

On my HPZ800 server Win 10 64-bit, it lists the following (truncated).

Process System Idle Process is owned by \.
Process System is owned by \.
Process smss.exe is owned by \.
Process csrss.exe is owned by \.
Process wininit.exe is owned by \.
Process csrss.exe is owned by \.
Process services.exe is owned by \.
Process lsass.exe is owned by \.
Process winlogon.exe is owned by \.
Process svchost.exe is owned by \.
Process svchost.exe is owned by \.
Process dwm.exe is owned by \.
Process svchost.exe is owned by \.
Process svchost.exe is owned by \.
Process svchost.exe is owned by \.
Process nvvsvc.exe is owned by \.
Process svchost.exe is owned by \.
Process svchost.exe is owned by \.
Process nvxdsync.exe is owned by \.
Process nvvsvc.exe is owned by \.
Process svchost.exe is owned by \.
Process RtkAudioService64.exe is owned by \.
Process svchost.exe is owned by \.
Process ZhuDongFangYu.exe is owned by \.
Process RAVBg64.exe is owned by \.
Process spoolsv.exe is owned by \.
Process svchost.exe is owned by \.
Process QQProtect.exe is owned by \.
Process ibguard.exe is owned by \.
Process svchost.exe is owned by \.
Process ReflectService.exe is owned by \.
Process svchost.exe is owned by \.
Process svchost.exe is owned by \.
Process mqsvc.exe is owned by \.
Process MsMpEng.exe is owned by \.
Process pcas.exe is owned by \.
Process dasHost.exe is owned by \.
Process secbizsrv.exe is owned by \.
Process IpOverUsbSvc.exe is owned by \.
Process TBSecSvc.exe is owned by \.
Process ibserver.exe is owned by \.
Process NisSrv.exe is owned by \.
Process svchost.exe is owned by \.
Process sihost.exe is owned by HP-PC\HP.
Process taskhostw.exe is owned by HP-PC\HP.
Process RuntimeBroker.exe is owned by HP-PC\HP.
Process SkypeHost.exe is owned by HP-PC\HP.
Process explorer.exe is owned by HP-PC\HP.
Process aliwssv.exe is owned by HP-PC\HP.
Process conhost.exe is owned by HP-PC\HP.
...
...

The CreateObject allows VBScript to be flexible and extensible. Of course, you can use other programming languages to query the WMI object as well.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
532 words
Last Post: How to List Keyboard Properties using VBScript and WMI Object?
Next Post: How to Get Maximum Square Area in a Rectangle using Dynamic Programming?

The Permanent URL is: How to List Process Owners using VBScript + WMI Object?

Leave a Reply