Jump to content
Sign in to follow this  
Guest Sproffitt

ProcessList - how to show owner/user

Recommended Posts

Guest Sproffitt

I am running AutoIT on a W2k Citrix server and I want to list all of the iExplore processes running for the current user. Unfortunately I am seeing all iExplore processes for all users on the server . Is there either a way to get the "owner" of the process or "scope" ProcessList to only "see" current user's processes?

Here is the test script I am using:

Dim $procs = ProcessList(2)

For $i = 1 To $procs[0]

$processCheck = StringInStr ( $procs[$i], "iExplore" )

If $processCheck <> 0 Then

MsgBox(4096, "TESTPID", $procs[$i])

EndIf

Next

Thanks for any ideas!

P.S. Are there any know issues w/ AutoIT and a multi-user environment like MetaFrame

Share this post


Link to post
Share on other sites
this-is-me

There is no support in autoit as of yet to check which user is running a process. Jon, any way to get this added? I also have been looking for this feature.


Who else would I be?

Share this post


Link to post
Share on other sites
anfad

Try my fresh-off-the-stove UDF to get it done. (Indentation is up to you :)

;===============================================================================

;

; Function Name: _ProcessGetOwner()

; Description: Get the owner of an open process

; Parameter(s): $vProcess - PID of a process.

; $strComputer - Name of target computer

; Requirement(s): AutoIt Beta v3.2.+

; cimwin32.dll (included with Windows)

; Return Value(s): On Success - Returns owners username of process

; 0 - Successful, returns username

;

; On Failure: Returns friendly errormessage and sets @Error to:

; 2 - Access denied

; 3 - Insufficient privilege

; 8 - Unknown failure

; 21 - Path not found

; Author(s): Andreas Fälldin

;===============================================================================

Func _ProcessGetOwner($vProcess,$strComputer)

Local $i_PID = ProcessExists($vProcess)

If Not $i_PID Then

SetError(1)

Return -1

EndIf

Local $wbemFlagReturnImmediately = 0x10

Local $wbemFlagForwardOnly = 0x20

Local $colItems = ""

Local $strUser=""

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2")

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessID = " & $i_PID, "WQL", _

$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then

For $objItem In $colItems

$rc = $objItem.GetOwner($strUser)

Switch $rc

Case 0

SetError(0)

Return $strUser

Case 2

SetError(2)

Return "ACCESS DENIED"

Case 3

SetError(3)

Return "INSUFFICIENT PRIVILEGE"

Case 8

SetError(8)

Return "UNKNOWN FAILURE"

Case 9

SetError(9)

Return "PATH NOT FOUND"

Case 21

SetError(21)

Return "INVALID PARAMETER"

Case Else

SetError(1)

Return -1

EndSwitch

EndFunc ;==>_ProcessGetOwner

Share this post


Link to post
Share on other sites
dizzydavidh

Nice!

The function was missing a next and endif at the end but once they were added it worked perfectly.

Thanks very much!

Share this post


Link to post
Share on other sites
November

Hi there Anfad,

I have a question for you:

; On Failure: Returns friendly errormessage and sets @Error to:

; 2 - Access denied

; 3 - Insufficient privilege

; 8 - Unknown failure

; 21 - Path not found

Are this error codes the same for all wmi queries?

Thanks in advance!

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.