Sign in to follow this  
Followers 0
oleg

For In Question

4 posts in this topic

#1 ·  Posted (edited)

Got this script and the second For executed only once :o Can somebody explain why so i could get a brighter view on that ?

For $objProcess in $colProcesses

$ProcessName = $objProcess.Name

$ProcessId = $objProcess.ProcessId

$ProcessPriority = $objProcess.Priority

$ProcessMemUsage = $objProcess.WorkingSetSize

$objProcess.GetOwner ($Owner)

$ProcessMemUsage = ($ProcessMemUsage / 1024) / 1024

$ProcessMemUsage = Round($ProcessMemUsage, 1)

$cpuProcs = $objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process where name ='"& $objProcess.Name & "'")

For $obj In $cpuProcs

$Processcpu = $obj.name

Next

$LISTITEM = GUICtrlCreateListViewItem($ProcessName & "|" & $ProcessId & "|" & $ProcessMemUsage & " MB" & "|" & $Processcpu & "|" & $ProcessPriority & "|" & $Owner, $PSLIST)

Next

Edited by oleg

There is a hex ( 31303030303030 ) reasons i love AutoIt !

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

take a look at your select statement, your selecting only one process would be my guess, there for only 1 literation thru the loop

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Got this script and the second For executed only once :geek: Can somebody explain why so i could get a brighter view on that ?

Yes you right in the second for i select one process and that is what i want :o but isnt after that first for continues but dose not enter second no more ;)

Example

$colProcesses = $objWMIService.ExecQuery ( "Select * from Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

Dim $Processcpu

For $objProcess in $colProcesses

$ProcessName = $objProcess.Name

$ProcessId = $objProcess.ProcessId

$ProcessPriority = $objProcess.Priority

$ProcessMemUsage = $objProcess.WorkingSetSize

$objProcess.GetOwner ($Owner)

$ProcessMemUsage = ($ProcessMemUsage / 1024) / 1024

$ProcessMemUsage = Round($ProcessMemUsage, 1)

$cpuProcs = $objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process where name ='"& $objProcess.Name & "'")

This message box appears for each process selected by first for > MsgBox(0,"", $objProcess.Name

)

For $obj In $cpuProcs

This message box appears only once and display first matched process selected from first for > MsgBox(0,"",$obj.name)

$Processcpu = $obj.name

Next

$LISTITEM = GUICtrlCreateListViewItem($ProcessName & "|" & $ProcessId & "|" & $ProcessMemUsage & " MB" & "|" & $Processcpu & "|" & $ProcessPriority & "|" & $Owner, $PSLIST)

Next

Edited by oleg

There is a hex ( 31303030303030 ) reasons i love AutoIt !

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

what your selecting on won't work, try the ProcessId

for example:

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colProcesses = $objWMIService.ExecQuery ( "Select * from Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
Dim $Processcpu
For $objProcess In $colProcesses
    ConsoleWrite("Name: " & $objProcess.Name & @LF)
    ConsoleWrite("Caption: " & $objProcess.Caption & @LF)
    ConsoleWrite("Description: " & $objProcess.Description & @LF)
    ConsoleWrite("ProcessId: " & $objProcess.ProcessId & @LF)
    $ProcessName = $objProcess.Name
    $ProcessId = $objProcess.ProcessId
    $ProcessPriority = $objProcess.Priority
    $ProcessMemUsage = $objProcess.WorkingSetSize
;~  $objProcess.GetOwner ($Owner)
    $ProcessMemUsage = ($ProcessMemUsage / 1024) / 1024
    $ProcessMemUsage = Round($ProcessMemUsage, 1)
    $cpuProcs = ""
    $cpuProcs = $objWMIService.ExecQuery ("Select * from Win32_PerfFormattedData_PerfProc_Process where IDProcess ='" & $objProcess.ProcessId & "'", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $Processcpu = ""
    $IDProcess = ""
    For $obj In $cpuProcs
        $Processcpu = $obj.Name
        $IDProcess = $obj.IDProcess
    Next
    MsgBox(0,"test",$ProcessName & @LF & $Processcpu)
;~  $LISTITEM = GUICtrlCreateListViewItem($ProcessName & "|" & $ProcessId & "|" & $ProcessMemUsage & " MB" & "|" & $Processcpu & "|" & $ProcessPriority & "|" & $Owner, $PSLIST)
Next
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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  
Followers 0