Jump to content

ProcessList problem


Nahuel
 Share

Recommended Posts

I wanted to update my processmanager and was trying to find a way of refreshing the process list only if there's a new process or one ended. This is an example:

#include <GUIConstants.au3>
#Include <GuiList.au3>

 GUICreate("Form2", 249, 305, 208, 147)
$ListadeProcesos = GUICtrlCreateList("", 32, 16, 185, 253)
GUISetState(@SW_SHOW)
pros()
AdlibEnable("pros",2000)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func pros()
$Procesos=ProcessList()
$NumDePros=_GUICtrlListCount($ListadeProcesos)
MsgBox(0,"","ProcessList: "&$Procesos[0][0]&@CR&"ListView: "&$NumDePros)
If $Procesos[0][0]<>$NumDePros Then
    GUICtrlSetData($ListadeProcesos,"")
    for $i = 1 to $Procesos[0][0]
        GUICtrlSetData($ListadeProcesos,$Procesos[$i][0])
    next
EndIf
EndFunc

My problem is that, for some reson, the number of processes returned by ProcessList doesn't match the number of items. There's a difference of 2, but sometimes it's 3. I checked with _ArrayDisplay() and I see what the problem is, there are three processes called 'svchost.exe'. ProcessList DOES return them but GUICtrlSetData($ListadeProcesos,$Procesos[$i][0]) will only add it once!! :)

Can anyone explain why this happens?

Link to comment
Share on other sites

  • Moderators

I wanted to update my processmanager and was trying to find a way of refreshing the process list only if there's a new process or one ended. This is an example:

#include <GUIConstants.au3>
#Include <GuiList.au3>

 GUICreate("Form2", 249, 305, 208, 147)
$ListadeProcesos = GUICtrlCreateList("", 32, 16, 185, 253)
GUISetState(@SW_SHOW)
pros()
AdlibEnable("pros",2000)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func pros()
$Procesos=ProcessList()
$NumDePros=_GUICtrlListCount($ListadeProcesos)
MsgBox(0,"","ProcessList: "&$Procesos[0][0]&@CR&"ListView: "&$NumDePros)
If $Procesos[0][0]<>$NumDePros Then
    GUICtrlSetData($ListadeProcesos,"")
    for $i = 1 to $Procesos[0][0]
        GUICtrlSetData($ListadeProcesos,$Procesos[$i][0])
    next
EndIf
EndFunc

My problem is that, for some reson, the number of processes returned by ProcessList doesn't match the number of items. There's a difference of 2, but sometimes it's 3. I checked with _ArrayDisplay() and I see what the problem is, there are three processes called 'svchost.exe'. ProcessList DOES return them but GUICtrlSetData($ListadeProcesos,$Procesos[$i][0]) will only add it once!! :)

Can anyone explain why this happens?

What happens if you replace:
for $i = 1 to $Procesos[0][0]
        GUICtrlSetData($ListadeProcesos,$Procesos[$i][0])
    nextoÝ÷ Ùh­«­¢+Ø$ÀÌØíÍ!½±ôÅÕ½ÐìÅÕ½Ðì(%½ÈÀÌØí¤ôÄѼÀÌØíAɽͽÍlÁulÁt($ÀÌØíÍ!½±µÀìôÀÌØíAɽͽÍlÀÌØí¥ulÁtµÀìÌäíðÌäì(%¹áÐ(%U%
ÑɱMÑÑ ÀÌØí1¥ÍÑAɽͽ̰ÀÌØíÍ!½±¤

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Well, you could try this as well, and if it works you might be able to see why:

#include <GUIConstants.au3>
#Include <GuiList.au3>

GUICreate("Form2", 249, 305, 208, 147)
$ListadeProcesos = GUICtrlCreateList("", 32, 16, 185, 253)
GUISetState(@SW_SHOW)
pros()
AdlibEnable("pros",2000)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func pros()
$Procesos=ProcessList()
$NumDePros=_GUICtrlListCount($ListadeProcesos)
MsgBox(0,"","ProcessList: "&$Procesos[0][0]&@CR&"ListView: "&$NumDePros)
If $Procesos[0][0]<>$NumDePros Then
    GUICtrlSetData($ListadeProcesos,"")
    for $i = 1 to $Procesos[0][0]
        GUICtrlSetData($ListadeProcesos,$Procesos[$i][0]&"|")
    next
EndIf
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yes that works perfectly! I see why your fix is doing, but my question was why can't we add many items with the same name? I guess that means that if I try:

Guictrlsetdata($Mylist,"hello")
Guictrlsetdata($Mylist,"hello")

it wouldn't work? Weird.

Link to comment
Share on other sites

  • Moderators

Yes that works perfectly! I see why your fix is doing, but my question was why can't we add many items with the same name? I guess that means that if I try:

Guictrlsetdata($Mylist,"hello")
Guictrlsetdata($Mylist,"hello")

it wouldn't work? Weird.

You didn't notice the separator necessary I guess? "|"?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You didn't notice the separator necessary I guess? "|"?

No no no, I did! You are not getting my point. Apparently it can work without a separator if the items are different, but not if they are the same word. I was just wondering why that happens...

This will add both 'hello' and 'bye' items

Guictrlsetdata($Mylist,"hello")
Guictrlsetdata($Mylist,"Bye")

This will only add hello once

Guictrlsetdata($Mylist,"hello")
Guictrlsetdata($Mylist,"hello")

But never mind, it's just curiosity :) Thanks a lot for your help.

Link to comment
Share on other sites

From the help file for GUICtrlSetData:

Remarks

For Combo or List control :

If the "data" corresponds to an already existing entry it is set as the default.

If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed.

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...