VBScript, how to I find an owner of a given proces

2019-03-02 10:39发布

问题:

I am trying to write vbs to find owner of process. Can you please help me?

回答1:

My google-fu is strong

Microsoft Windows 2000 Scripting Guide - Determining 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