For Each objProcess in colProcesses > strNameOfUser = REPLICATE(CHR(0),256) > * See if owner can be determined > Return = objProcess.GetOwner(strNameOfUser) > If Return <> 0 Then > ? "Could not get owner info for process " + objProcess.Name + CHR(13) + "Error = " + STR(Return) > Else > * Get Owner > Return = objProcess.GetOwner(@strNameOfUser) > > IF objProcess.name = "WINWORD" > SET STEP ON > ENDIF > ? "Process " + objProcess.Name + " is owned by " + "\" + strNameOfUser + "." > EndIf >Next >>
>>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 >>>>
>>strComputer = "." >>loCIMV2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2") >>colProcesses = loCIMV2.ExecQuery("Select * from Win32_Process") >> >>For Each objProcess in colProcesses >> strNameOfUser = SPACE(140) >> Return = objProcess.GetOwner(strNameOfUser) >> If Return <> 0 Then >> ? "Could not get owner info for process " + objProcess.Name + CHR(13) + "Error = " + STR(Return) >> Else >> IF objProcess.name = "WINWORD" >> SET STEP ON >> ENDIF >> ? "Process " + objProcess.Name + " is owned by " + "\" + strNameOfUser + "." >> EndIf >>Next >>>>