Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine all current Win process
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01064064
Message ID:
01064477
Views:
225
I just discovered it and was going to post my finding. You are way too fast Sergery...< s >
Thanks again.

>You've to pass output parameter by reference. However doing so generates an error when owner cannot be determined. Below is modified code that works.
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
>
>
>>I'm trying the code in the last link
>>
>>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
>>
>>
>>in VFP it looks like this:
>>
>>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
>>
>>
>>I'm not sure the first example works "as is" as the variable "strNameOfUser" was not declared, the help says the "GetOwner" method has 2 "output" variables. Anyhow ;), it's not working, the strNameOfUser is never filled althought the method call returns 0 (success). I tried pre-filling it with null, 0, "" and a x number of spaces, it remains untouched.
>>Do you know how to proceed from here?
>>
>>TIA
>>
>>Max

...Y soy feliz, bien feliz, asi lo grito;
Mira, que el mundo sepa, que se sepa:
Soy feliz....                       

...And I'm happy, quite happy, so do I yell it;
Look, so the world knows it, so be known:
I'm happy...
 

Ismael Rivera "Oye cosita linda"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform