Jump to content
Sign in to follow this  
MadaraUchiha

List Processname, ProcessPID, ProcessPath

Recommended Posts

MadaraUchiha

Yo,

I like to list the Processname, PID and Executable Path in a ListView.

For the first two (name & PID) I can use ProcessList() Function, and for the Path

I use thiese DLL Calls:

Func _ProcessGetLocation($iPID)
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If $aProc[0] = 0 Then Return SetError(1, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
    Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
    If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
    Return $aReturn[3]
EndFunc

So I like to list them, like this:

#include <GuiConstants.au3>

Func _ProcessGetLocation($iPID)
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If $aProc[0] = 0 Then Return SetError(1, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
    Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
    If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
    Return $aReturn[3]
EndFunc


Dim $Table, $list,$test
GuiCreate("Processes", 300, 400, 200,200)
$Table = GuiCtrlCreateListView ('Process Name | Pid|Path',10,10,280,380)
$list = ProcessList()
    for $i = 1 to $list[0][0]
            GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1],$Table)
            For $test = 1 to $list[0][1]
                    GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1] $ ' | ' & _ProcessGetLocation($list[$i][1]),$Table)

            Next

    next

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

But it says: syntax error: illegal character?

This error occurs in this line:

GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1] $ ' | ' & _ProcessGetLocation($list[$i][1]),$Table)
 

How can I fix this?


Share this post


Link to post
Share on other sites
Melba23

MadaraUchiha,

Look at these:

; Original - error
GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1] $ ' | ' & _ProcessGetLocation($list[$i][1]),$Table)

; Altered - no error
GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1] & ' | ' & _ProcessGetLocation($list[$i][1]),$Table)
Can you see the difference? :huh:

If you still cannot see it: ;)

Look for a $/& mismatch

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
MadaraUchiha

>_<  Oh really, it was a & $ missmatch... Thanks...

Fixed it now, but the third column of my ListView stays empty anyways...? :o

#include <GuiConstants.au3>

Func _ProcessGetLocation($iPID)
    Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
    If $aProc[0] = 0 Then Return SetError(1, 0, '')
    Local $vStruct = DllStructCreate('int[1024]')
    DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
    Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
    If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
    Return $aReturn[3]
EndFunc


Dim $Table, $list,$test
GuiCreate("Processes", 300, 400, 200,200)
$Table = GuiCtrlCreateListView ('Process Name | Pid|Path',10,10,280,380)
$list = ProcessList()
    for $i = 1 to $list[0][0]
            GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1],$Table)
            For $test = 1 to $list[0][1]
                    GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1] & ' | ' & _ProcessGetLocation($list[$i][1]),$Table)

            Next

    next

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

I am kinda confused, because I have three columns, and normally it should fill all three, shouldn't it?

I have first for name, second for PID and third for Path.

But for some reason the Path won't popup in the third column?  :ermm:


Share this post


Link to post
Share on other sites
Melba23

MadaraUchiha,

What was the internal $test loop doing in your ListView creation code? As the upper limit was always 0 it never ran and so the only item that was entered into the ListView (by the outer loop) did not have a path element. :huh:

This amended loop works for me:

For $i = 1 To $list[0][0]
    ;GuiCtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1], $Table)
    ;For $test = 1 to $list[0][1]
    $sPath = _ProcessGetLocation($list[$i][1])
    If Not @error Then ; Why bother to return an error if you do not check for it?
        GUICtrlCreateListViewItem($list[$i][0] & ' | ' & $list[$i][1] & ' | ' & $sPath, $Table)
    EndIf
    ;Next
Next
Does it work for you too? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
MadaraUchiha

Yes :)

Thats already a good jump into the right direction, thnaks so far.^^

But, some processpath's got a bit... uh... messed up:

 

coxp4end.png

 

It's displaying garbage Text like Ä or Ľ.

Can I replace this with a clear N/A instead of this ? :D

Edited by Melba23
Removed profanity

Share this post


Link to post
Share on other sites
Melba23

MadaraUchiha,

I suggest you check whether the returned path has ":" as the second and third characters (StringMid will help here) and if it does not then you replace the string with "N/A". :)

M23

P.S. And there is no need to use such language when you post. :naughty:

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×