FireFox Posted May 9, 2009 Share Posted May 9, 2009 (edited) Hi, I want to display the icon for each process on the listview but im always getting the same icon... I have disabled lines 143, 147, 148 because there is an API error for some "process" with no icons Right Click on the listview and click on UpDate to see whats the problem CODE;~ #include <WinAPI.au3> #include <GUIListView.au3> ;~ #include 'include\_WinApiHook.au3' #include <ImageListConstants.au3> Opt('GUIOnEventMode', 1) ;~ $v_pi = DllOpen('psapi.dll') $GUI = GUICreate('', 500, 330, -1, -1, 0x00040000) GUISetOnEvent(-3, '_Exit') ;~ GUICtrlCreateGroup('Analyze', 5, 5, 490, 55) ;~ $r_pr = GUICtrlCreateRadio(' ', 15, 25, 14, 14) ;~ $r_sv = GUICtrlCreateRadio(' ', 100, 25, 14, 14) ;~ $r_rd = GUICtrlCreateRadio(' ', 185, 25, 15, 14) GUICtrlCreateTab(5, 65, 500, 205) GUICtrlCreateTabItem('Process') $l_pr = GUICtrlCreateListView('Process|Path', 15, 95, 475, 180) GUICtrlSendMsg($l_pr, 0x101E, 0, 190) GUICtrlSendMsg($l_pr, 0x101E, 1, 260) $c_ct = GUICtrlCreateContextMenu($l_pr) $m_up = GUICtrlCreateMenuItem('Update', $c_ct) GUICtrlSetOnEvent($m_up, '_UpDate') $f_lc = _GUIImageList_Create(16, 16, 5, 3) ;~ GUICtrlCreateTabItem('Module(s)') ;~ $l_rt = GUICtrlCreateListView('Module|Path|Danger', 15, 95, 475, 180) ;~ GUICtrlSendMsg($l_rt, 0x101E, 0, 150) ;~ GUICtrlSendMsg($l_rt, 0x101E, 1, 230) ;~ GUICtrlSendMsg($l_rt, 0x101E, 2, 80 ) GUISetState(@SW_SHOW, $GUI) While 1 Sleep(250) WEnd Func _Exit( ) Exit EndFunc Func _UpDate( ) $pl = ProcessList( ) _GUICtrlListView_BeginUpdate($l_pr) For $p = 1 To $pl[0][0] $f_pgp = _ProcessGetPath($pl[$p][0]) _GUICtrlListView_AddItem($l_pr, $pl[$p][0]) _GUICtrlListView_AddSubItem($l_pr, $p - 1, $f_pgp, 1) _GUIImageList_AddIcon($f_lc, $f_pgp) Next _GUICtrlListView_EndUpdate($l_pr) _GUICtrlListView_SetImageList($l_pr, $f_lc, 1) EndFunc ;~ Func _Services( ) ;~ ;~ EndFunc ;~ Func _Regedit( ) ;~ ;~ EndFunc ;~ Func _EnumModules($process) ;~ Local $aMods, $modules ;~ Local $hProcess = _GetProcHandle($process) ;~ If $hProcess Then ;~ Local $modules = DllStructCreate('ptr[1024]') ;~ Local $ret = DllCall($v_pi, 'int', 'EnumProcessModules', 'ptr', $hProcess, 'ptr', _ ;~ DllStructGetPtr($modules), 'dword', DllStructGetSize($modules), 'dword*', 0) ;~ If $ret[4] > 0 Then ;~ Local $nummods = $ret[4] / 4 ;~ Local $aMods[$nummods][4] ;~ For $i = 1 To $nummods ;~ $aMods[$i - 1][0] = DllStructGetData($modules, 1, $i); base address ;~ $aMods[$i - 1][1] = 'n/a'; module name ;~ $aMods[$i - 1][2] = 'n/a'; module path ;~ Local $name = _GetModuleBaseNameW($hProcess, Ptr($aMods[$i - 1][0])) ;~ If $name Then $aMods[$i - 1][1] = $name ;~ Local $path = _GetModuleFileNameW($hProcess, Ptr($aMods[$i - 1][0])) ;~ If $path Then $aMods[$i - 1][2] = $path ;~ $aMods[0][3] += 1 ;~ Next ;~ EndIf ;~ _WinAPI_CloseHandle($hProcess) ;~ EndIf ;~ ;~ Return $aMods ;~ EndFunc ;==>_EnumModules ;~ Func _GetModuleFileNameW($hProcess, $hModule) ;~ Local $path = '' ;~ Local $ret = DllCall($v_pi, 'dword', 'GetModuleFileNameExW', 'ptr', $hProcess, _ ;~ 'ptr', $hModule, 'wstr', '', 'dword', 260) ;~ If $ret[0] Then ;~ $path = $ret[3] ;~ EndIf ;~ ;~ Return $path ;~ EndFunc ;==>_GetModuleFileNameW ;~ Func _GetModuleBaseNameW($hProcess, $hModule) ;~ Local $name = '' ;~ Local $ret = DllCall($v_pi, 'dword', 'GetModuleBaseNameW', 'ptr', $hProcess, _ ;~ 'ptr', $hModule, 'wstr', '', 'dword', 260) ;~ If $ret[0] Then ;~ $name = $ret[3] ;~ EndIf ;~ ;~ Return $name ;~ EndFunc ;==>_GetModuleBaseNameW ; #FUNCTION# ==================================================================================================== ================ ; Name...........: _GUIImageList_AddIcon ; Description ...: Adds an icon to an image list ; Syntax.........: _GUIImageList_AddIcon($hWnd, $sFile[, $iIndex=0[, $fLarge = False]) ; Parameters ....: $hWnd - Handle to the control ; $sFile - Path to the icon that contains the image ; $iIndex - Specifies the zero-based index of the icon to extract ; $fLarge - Extract Large Icon ; Return values .: Success - The index of the image ; Failrue - -1 ; Author ........: Paul Campbell (PaulIA) ; Modified.......: ; Remarks .......: ; Related .......: _GUIImageList_Add, _GUIImageList_AddBitmap ; Link ..........; ; Example .......; Yes ; ==================================================================================================== =========================== Func _GUIImageList_AddIcon($hWnd, $sFile, $iIndex = 0, $fLarge = False) Local $tIcon, $iResult, $hIcon $tIcon = DllStructCreate("int Handle") If $fLarge Then $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, DllStructGetPtr($tIcon), 0, 1) Else $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, 0, DllStructGetPtr($tIcon), 1) EndIf ;~ _WinAPI_Check("_GUIImageList_AddIcon", ($iResult <= 0), -1) $hIcon = DllStructGetData($tIcon, "Handle") $iResult = _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon) ;~ _WinAPI_Check("_GUIImageList_AddIcon", ($iResult = -1), -2) ;~ _WinAPI_DestroyIcon($hIcon) Return $iResult EndFunc ;==>_GUIImageList_AddIcon ; #FUNCTION# ==================================================================================================== ================ ; Name...........: _GUIImageList_Create ; Description ...: Create an ImageList control ; Syntax.........: _GUIImageList_Create([$iCX=16[, $iCY=16[, $iColor=4[, $iOptions=0[, $iInitial=4[, $iGrow=4]]]]]]) ; Parameters ....: $iCX - Width, in pixels, of each image ; $iCY - Height, in pixels, of each image ; $iColor - Image color depth: ; |0 - Use the default behavior ; |1 - Use a 4 bit DIB section ; |2 - Use a 8 bit DIB section ; |3 - Use a 16 bit DIB section ; |4 - Use a 24 bit DIB section ; |5 - Use a 32 bit DIB section ; |6 - Use a device-dependent bitmap ; $iOptions - Option flags. Can be a combination of the following: ; |1 - Use a mask ; |2 - The images in the lists are mirrored ; |4 - The image list contains a strip of images ; $iInitial - Number of images that the image list initially contains ; $iGrow - Number of images by which the image list can grow when the system needs to make room for new ; +images. This parameter represents the number of new images that the resized image list can contain. ; Return values .: Success - Handle to the new control ; Failure - 0 ; Author ........: Paul Campbell (PaulIA) ; Modified.......: ; Remarks .......: ; Related .......: _GUIImageList_Destroy ; Link ..........; ; Example .......; Yes ; ==================================================================================================== =========================== Func _GUIImageList_Create($iCX = 16, $iCY = 16, $iColor = 4, $iOptions = 0, $iInitial = 4, $iGrow = 4) Local $aColor[7] = [$ILC_COLOR, $ILC_COLOR4, $ILC_COLOR8, $ILC_COLOR16, $ILC_COLOR24, $ILC_COLOR32, $ILC_COLORDDB] Local $iFlags, $aResult If BitAND($iOptions, 1) <> 0 Then $iFlags = BitOR($iFlags, $ILC_MASK) If BitAND($iOptions, 2) <> 0 Then $iFlags = BitOR($iFlags, $ILC_MIRROR) If BitAND($iOptions, 4) <> 0 Then $iFlags = BitOR($iFlags, $ILC_PERITEMMIRROR) $iFlags = BitOR($iFlags, $aColor[$iColor]) $aResult = DllCall("ComCtl32.dll", "hwnd", "ImageList_Create", "int", $iCX, "int", $iCY, "int", $iFlags, "int", $iInitial, "int", $iGrow) Return $aResult[0] EndFunc ;==>_GUIImageList_Create ; #FUNCTION# ==================================================================================================== ================ ; Name...........: _GUIImageList_ReplaceIcon ; Description ...: Replaces an image with an icon or cursor ; Syntax.........: _GUIImageList_ReplaceIcon($hWnd, $iIndex, $hIcon) ; Parameters ....: $hWnd - Handle to the control ; $iIndex - Index of the image to replace. If -1, the function appends the image to the end of the list. ; $hIcon - Handle to the icon or cursor that contains the bitmap and mask for the new image ; Return values .: Success - The index of the image ; Failure - -1 ; Author ........: Paul Campbell (PaulIA) ; Modified.......: Gary Frost (GaryFrost) changed return type from hwnd to int ; Remarks .......: Because the system does not save hIcon you can destroy it after the function returns if the icon or cursor was ; created by the CreateIcon function. You do not need to destroy hIcon if it was loaded by the LoadIcon function ; the system automatically frees an icon resource when it is no longer needed. ; Related .......: ; Link ..........; ; Example .......; Yes ; ==================================================================================================== =========================== Func _GUIImageList_ReplaceIcon($hWnd, $iIndex, $hIcon) Local $aResult $aResult = DllCall("ComCtl32.dll", "int", "ImageList_ReplaceIcon", "hwnd", $hWnd, "int", $iIndex, "hwnd", $hIcon) Return $aResult[0] EndFunc ;==>_GUIImageList_ReplaceIcon ; #FUNCTION# =============================================================================== ; Name...........: _ProcessGetPath( ; Description ...: Retrieves a process file path ; Syntax.........: _ProcessGetPath($vProcess) ; Parameters ....: $vProcess - PID or name of a process ; Requirements...: kernel32.dll, psapi.dll ; Return values .: Success - A full process path ; @error = 0 ; Failure - Empty string ; @error = 1 - Invalid process name/PID ; @error = 2 - kernel32.dll failed to open (wrong version?) ; @error = 3 - Could not OpenProcess ; @error = 4 - psapi.dll failed to open (doesn't exist?) ; @error = 5 - returned path is empty or invalid ; Author ........: JScript, Larry, SmOke_N ; Modified.......: mrRevoked - reformated, error checking ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; ; ============================================================================================ Func _ProcessGetPath($vProcess) Local $i_PID, $hKernel32, $hPsapi, $aProcessHandle, $tDLLStruct, $iError, $sProcessPath $i_PID = ProcessExists($vProcess) If Not $i_PID Then Return SetError(1, 0, "");process doesn't exist? $hKernel32 = DllOpen("Kernel32.dll") $iError = @error If $iError Then DllClose($hKernel32) Return SetError(2, $iError, ""); dllopen kernell32.dll failed EndIf $aProcessHandle = DllCall($hKernel32, "int", "OpenProcess", "int", 0x0400 + 0x0010, "int", 0, "int", $i_PID) $iError = @error If $iError Or $aProcessHandle[0] = 0 Then DllClose($hKernel32) Return SetError(2, $iError, "");openprocess failed EndIf $hPsapi = DllOpen("Psapi.dll") $iError = @error If $iError Then DllClose($hKernel32) DllClose($hPsapi) Return SetError(3, $iError, ""); dllopen psapi.dll failed EndIf $tDLLStruct = DllStructCreate("char[1000]") DllCall($hPsapi, "long", "GetModuleFileNameEx", "int", $aProcessHandle[0], "int", 0, "ptr", DllStructGetPtr($tDLLStruct), "long", DllStructGetSize($tDLLStruct)) $iError = @error DllCall($hKernel32, "int", "CloseHandle", "int", $aProcessHandle[0]) DllClose($hKernel32) DllClose($hPsapi) If $iError Then $tDLLStruct = 0 Return SetError(4, $iError, "");getmodulefilenamex failed EndIf $sProcessPath = DllStructGetData($tDLLStruct, 1) $tDLLStruct = 0 ;format the output If StringLen($sProcessPath) < 2 Then Return SetError(5, 0, "");is empty or non readable If StringLeft($sProcessPath, 4) = "\??\" Then $sProcessPath = StringReplace($sProcessPath, "\??\", "") If StringLeft($sProcessPath, 20) = "\SystemRoot\System32" Then $sProcessPath = StringReplace($sProcessPath, "\SystemRoot\System32", @SystemDir) Return SetError(0, 0, $sProcessPath) EndFunc;==>_ProcessGetPath Thanks for anyhelp ! Cheers, FireFox. Edited May 9, 2009 by FireFox Link to comment Share on other sites More sharing options...
FireFox Posted May 9, 2009 Author Share Posted May 9, 2009 @Everyone I have now resolved the problem, here is the new script : CODE ;~ #include <WinAPI.au3> #include <GUIListView.au3> #include 'include\_WinApiHook.au3' #include <ImageListConstants.au3> Opt('GUIOnEventMode', 1) Local $v_pi = DllOpen('psapi.dll') Local $n_pr = '[system Process]' $GUI = GUICreate('', 500, 330, -1, -1, 0x00040000) GUISetOnEvent(-3, '_Exit') ;~ GUICtrlCreateGroup('Analyze', 5, 5, 490, 55) ;~ $r_pr = GUICtrlCreateRadio(' ', 15, 25, 14, 14) ;~ $r_sv = GUICtrlCreateRadio(' ', 100, 25, 14, 14) ;~ $r_rd = GUICtrlCreateRadio(' ', 185, 25, 15, 14) GUICtrlCreateTab(5, 65, 500, 205) GUICtrlCreateTabItem('Process') $l_pr = _GuiCtrlListView_Create($GUI, 'Process|Path', 15, 95, 475, 180) ;~ _GUICtrlListView_SetExtendedListViewStyle($l_pr, 35) _GUICtrlListView_SetColumnWidth($l_pr, 0, 190) _GUICtrlListView_SetColumnWidth($l_pr, 1, 260) $f_lc = _GUIImageList_Create(16, 16, 5, 3) $b_up = GUICtrlCreateButton('Update', 145, 65, 50, 20) GUICtrlSetOnEvent($b_up, '_UpDate') $t_rt = GUICtrlCreateTabItem('Module(s)') $l_rt = GUICtrlCreateListView('Module|Path|Danger', 15, 95, 475, 180) GUICtrlSendMsg($l_rt, 0x101E, 0, 150) GUICtrlSendMsg($l_rt, 0x101E, 1, 230) GUICtrlSendMsg($l_rt, 0x101E, 2, 80 ) GUISetState(@SW_SHOW, $GUI) _UpDate( ) While 1 Sleep(250) $c_pr = _GUICtrlListView_GetItemTextString($l_pr) If $n_pr <> $c_pr Then _AutoUpdate($c_pr ) $n_pr = $c_pr EndIf WEnd Func _Exit( ) Exit EndFunc Func _UpDate( ) $pl = ProcessList( ) _GUICtrlListView_DeleteAllItems($l_pr) _GUICtrlListView_BeginUpdate($l_pr) For $p = 1 To $pl[0][0] If $pl[$p][0] <> '[system Process]' _ And $pl[$p][0] <> 'System' Then $f_pgp = _ProcessGetPath($pl[$p][0] ) _GUICtrlListView_AddItem($l_pr, $pl[$p][0], $p - 3) _GUIImageList_AddIcon($f_lc, $f_pgp) _GUICtrlListView_AddSubItem($l_pr, $p - 3, $f_pgp, 1) EndIf Next _GUICtrlListView_EndUpdate($l_pr) _GUICtrlListView_SetImageList($l_pr, $f_lc, 1) EndFunc Func _AutoUpdate($r_pr) _GUICtrlListView_BeginUpdate($l_rt) _GUICtrlListView_DeleteAllItems($l_rt) $p_ID = ProcessExists(StringLeft($r_pr, StringInStr($r_pr, '|') - 1) ) $g_aMods = _EnumModules($p_ID) If IsArray($g_aMods) Then _ArraySort($g_aMods, 0, 0, 0, 1) For $i = 0 To UBound($g_aMods) - 1 GUICtrlCreateListViewItem($g_aMods[$i][1] & '|' & _ $g_aMods[$i][2], $l_rt) Next EndIf _GUICtrlListView_EndUpdate($l_rt) GUICtrlSetData($t_rt, UBound($g_aMods) & ' module(s)') EndFunc ;~ Func _Services( ) ;~ ;~ EndFunc ;~ Func _Regedit( ) ;~ ;~ EndFunc Func _EnumModules($process) Local $aMods, $modules Local $hProcess = _GetProcHandle($process) If $hProcess Then Local $modules = DllStructCreate('ptr[1024]') Local $ret = DllCall($v_pi, 'int', 'EnumProcessModules', 'ptr', $hProcess, 'ptr', _ DllStructGetPtr($modules), 'dword', DllStructGetSize($modules), 'dword*', 0) If $ret[4] > 0 Then Local $nummods = $ret[4] / 4 Local $aMods[$nummods][3] For $i = 1 To $nummods $aMods[$i - 1][0] = DllStructGetData($modules, 1, $i) ; base address $aMods[$i - 1][1] = _GetModuleBaseNameW($hProcess, Ptr($aMods[$i - 1][0])) $aMods[$i - 1][2] = _GetModuleFileNameW($hProcess, Ptr($aMods[$i - 1][0])) $a_path = StringReplace($aMods[$i - 1][2], '\??\', '') $a_path = StringReplace($a_path, '\SystemRoot', @WindowsDir) $aMods[$i - 1][2] = $a_path Next EndIf _WinAPI_CloseHandle($hProcess) EndIf Return $aMods EndFunc ;==>_EnumModules Func _GetModuleFileNameW($hProcess, $hModule) Local $path = '' Local $ret = DllCall($v_pi, 'dword', 'GetModuleFileNameExW', 'ptr', $hProcess, _ 'ptr', $hModule, 'wstr', '', 'dword', 260) If $ret[0] Then Return $ret[3] EndFunc ;==>_GetModuleFileNameW Func _GetModuleBaseNameW($hProcess, $hModule) Local $name = '' Local $ret = DllCall($v_pi, 'dword', 'GetModuleBaseNameW', 'ptr', $hProcess, _ 'ptr', $hModule, 'wstr', '', 'dword', 260) If $ret[0] Then Return $ret[3] EndFunc ;==>_GetModuleBaseNameW ; #FUNCTION# ==================================================================================================== ================ ; Name...........: _GUIImageList_AddIcon ; Description ...: Adds an icon to an image list ; Syntax.........: _GUIImageList_AddIcon($hWnd, $sFile[, $iIndex=0[, $fLarge = False]) ; Parameters ....: $hWnd - Handle to the control ; $sFile - Path to the icon that contains the image ; $iIndex - Specifies the zero-based index of the icon to extract ; $fLarge - Extract Large Icon ; Return values .: Success - The index of the image ; Failrue - -1 ; Author ........: Paul Campbell (PaulIA) ; Modified.......: FireFox ; Remarks .......: ; Related .......: _GUIImageList_Add, _GUIImageList_AddBitmap ; Link ..........; ; Example .......; Yes ; ==================================================================================================== =========================== Func _GUIImageList_AddIcon($hWnd, $sFile, $iIndex = 0, $fLarge = False) Local $tIcon, $iResult, $hIcon $tIcon = DllStructCreate("int Handle") If $fLarge Then $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, DllStructGetPtr($tIcon), 0, 1) If $iResult <> 1 Then Return _GUIImageList_AddIcon($hWnd, 'shell32.dll', 071, True) Else $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, 0, DllStructGetPtr($tIcon), 1) If $iResult <> 1 Then Return _GUIImageList_AddIcon($hWnd, 'shell32.dll', 071) EndIf $hIcon = DllStructGetData($tIcon, "Handle") $iResult = _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon) _WinAPI_DestroyIcon($hIcon) Return $iResult EndFunc ;==>_GUIImageList_AddIcon ; #FUNCTION# ==================================================================================================== ================ ; Name...........: _GUIImageList_Create ; Description ...: Create an ImageList control ; Syntax.........: _GUIImageList_Create([$iCX=16[, $iCY=16[, $iColor=4[, $iOptions=0[, $iInitial=4[, $iGrow=4]]]]]]) ; Parameters ....: $iCX - Width, in pixels, of each image ; $iCY - Height, in pixels, of each image ; $iColor - Image color depth: ; |0 - Use the default behavior ; |1 - Use a 4 bit DIB section ; |2 - Use a 8 bit DIB section ; |3 - Use a 16 bit DIB section ; |4 - Use a 24 bit DIB section ; |5 - Use a 32 bit DIB section ; |6 - Use a device-dependent bitmap ; $iOptions - Option flags. Can be a combination of the following: ; |1 - Use a mask ; |2 - The images in the lists are mirrored ; |4 - The image list contains a strip of images ; $iInitial - Number of images that the image list initially contains ; $iGrow - Number of images by which the image list can grow when the system needs to make room for new ; +images. This parameter represents the number of new images that the resized image list can contain. ; Return values .: Success - Handle to the new control ; Failure - 0 ; Author ........: Paul Campbell (PaulIA) ; Modified.......: ; Remarks .......: ; Related .......: _GUIImageList_Destroy ; Link ..........; ; Example .......; Yes ; ==================================================================================================== =========================== Func _GUIImageList_Create($iCX = 16, $iCY = 16, $iColor = 4, $iOptions = 0, $iInitial = 4, $iGrow = 4) Local $aColor[7] = [$ILC_COLOR, $ILC_COLOR4, $ILC_COLOR8, $ILC_COLOR16, $ILC_COLOR24, $ILC_COLOR32, $ILC_COLORDDB] Local $iFlags, $aResult If BitAND($iOptions, 1) <> 0 Then $iFlags = BitOR($iFlags, $ILC_MASK) If BitAND($iOptions, 2) <> 0 Then $iFlags = BitOR($iFlags, $ILC_MIRROR) If BitAND($iOptions, 4) <> 0 Then $iFlags = BitOR($iFlags, $ILC_PERITEMMIRROR) $iFlags = BitOR($iFlags, $aColor[$iColor]) $aResult = DllCall("ComCtl32.dll", "hwnd", "ImageList_Create", "int", $iCX, "int", $iCY, "int", $iFlags, "int", $iInitial, "int", $iGrow) Return $aResult[0] EndFunc ;==>_GUIImageList_Create ; #FUNCTION# ==================================================================================================== ================ ; Name...........: _GUIImageList_ReplaceIcon ; Description ...: Replaces an image with an icon or cursor ; Syntax.........: _GUIImageList_ReplaceIcon($hWnd, $iIndex, $hIcon) ; Parameters ....: $hWnd - Handle to the control ; $iIndex - Index of the image to replace. If -1, the function appends the image to the end of the list. ; $hIcon - Handle to the icon or cursor that contains the bitmap and mask for the new image ; Return values .: Success - The index of the image ; Failure - -1 ; Author ........: Paul Campbell (PaulIA) ; Modified.......: Gary Frost (GaryFrost) changed return type from hwnd to int ; Remarks .......: Because the system does not save hIcon you can destroy it after the function returns if the icon or cursor was ; created by the CreateIcon function. You do not need to destroy hIcon if it was loaded by the LoadIcon function ; the system automatically frees an icon resource when it is no longer needed. ; Related .......: ; Link ..........; ; Example .......; Yes ; ==================================================================================================== =========================== Func _GUIImageList_ReplaceIcon($hWnd, $iIndex, $hIcon) Local $aResult $aResult = DllCall("ComCtl32.dll", "int", "ImageList_ReplaceIcon", "hwnd", $hWnd, "int", $iIndex, "hwnd", $hIcon) Return $aResult[0] EndFunc ;==>_GUIImageList_ReplaceIcon ; #FUNCTION# =============================================================================== ; Name...........: _ProcessGetPath( ; Description ...: Retrieves a process file path ; Syntax.........: _ProcessGetPath($vProcess) ; Parameters ....: $vProcess - PID or name of a process ; Requirements...: kernel32.dll, psapi.dll ; Return values .: Success - A full process path ; @error = 0 ; Failure - Empty string ; @error = 1 - Invalid process name/PID ; @error = 2 - kernel32.dll failed to open (wrong version?) ; @error = 3 - Could not OpenProcess ; @error = 4 - psapi.dll failed to open (doesn't exist?) ; @error = 5 - returned path is empty or invalid ; Author ........: JScript, Larry, SmOke_N ; Modified.......: mrRevoked - reformated, error checking ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; ; ============================================================================================ Func _ProcessGetPath($vProcess) Local $i_PID, $hKernel32, $hPsapi, $aProcessHandle, $tDLLStruct, $iError, $sProcessPath $i_PID = ProcessExists($vProcess) If Not $i_PID Then Return SetError(1, 0, "");process doesn't exist? $hKernel32 = DllOpen("Kernel32.dll") $iError = @error If $iError Then DllClose($hKernel32) Return SetError(2, $iError, ""); dllopen kernell32.dll failed EndIf $aProcessHandle = DllCall($hKernel32, "int", "OpenProcess", "int", 0x0400 + 0x0010, "int", 0, "int", $i_PID) $iError = @error If $iError Or $aProcessHandle[0] = 0 Then DllClose($hKernel32) Return SetError(2, $iError, "");openprocess failed EndIf $hPsapi = DllOpen("Psapi.dll") $iError = @error If $iError Then DllClose($hKernel32) DllClose($hPsapi) Return SetError(3, $iError, ""); dllopen psapi.dll failed EndIf $tDLLStruct = DllStructCreate("char[1000]") DllCall($hPsapi, "long", "GetModuleFileNameEx", "int", $aProcessHandle[0], "int", 0, "ptr", DllStructGetPtr($tDLLStruct), "long", DllStructGetSize($tDLLStruct)) $iError = @error DllCall($hKernel32, "int", "CloseHandle", "int", $aProcessHandle[0]) DllClose($hKernel32) DllClose($hPsapi) If $iError Then $tDLLStruct = 0 Return SetError(4, $iError, "");getmodulefilenamex failed EndIf $sProcessPath = DllStructGetData($tDLLStruct, 1) $tDLLStruct = 0 ;format the output If StringLen($sProcessPath) < 2 Then Return SetError(5, 0, "");is empty or non readable If StringLeft($sProcessPath, 4) = "\??\" Then $sProcessPath = StringReplace($sProcessPath, "\??\", "") If StringLeft($sProcessPath, 20) = "\SystemRoot\System32" Then $sProcessPath = StringReplace($sProcessPath, "\SystemRoot\System32", @SystemDir) Return SetError(0, 0, $sProcessPath) EndFunc;==>_ProcessGetPath Cheers, FireFox. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now