Jump to content



Photo

_ProcessListEx - UDF


  • Please log in to reply
6 replies to this topic

#1 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,244 posts

Posted 06 June 2008 - 11:29 PM

_ProcessListEx() UDF can return «Process Name», «Process ID», and «Process File Path».
Besides that, it can return processes by «File Resource Name», i.e. "ProductVersion", "CompanyName", etc.

AutoIt         
#include <Array.au3> ;============= Example with default usage ============= $aProcListEx = _ProcessListEx() If @error Then     MsgBox(48, "_ProcessListEx - Error", StringFormat("There was an error to get ProcessList (@error = %i)", @error)) Else     _ArrayDisplay($aProcListEx, "_ProcessListEx Demo (All Processes)") EndIf ;============= Example with default usage ============= ;============= Example with Resource Name usage ============= $aAutoItProcList = _ProcessListEx("CompiledScript", "AutoIt", 0) If @error Then     MsgBox(48, "_ProcessListEx - Error", StringFormat("There was an error to get ProcessList (@error = %i)", @error)) Else     _ArrayDisplay($aAutoItProcList, "_ProcessListEx Demo (AutoIt Processes)") EndIf ;============= Example with Resource Name usage ============= ;=============================================================================== ; ; Function Name:           _ProcessListEx() ; ; Function Description:    Gets Process List with extended info, plus can retrieve only a processes with specific resources strings. ; ; Parameter(s):            $sResourceName [Optional] - Resource name of the process filename, i.e. "CompiledScript". ;                          $sInResString [Optional] - String to check in the resource name. ;                          $iWholeWord [Optional] - Defines if the $sInResString will be compared as whole string (default is 1). ; ; Requirement(s):          None. ; ; Return Value(s):         On Success -  Return 2-dimentional array, where: ;                                                                   $aRet_List[0][0] = Total processes (array elements). ;                                                                   $aRet_List[N][0] = Process Name. ;                                                                   $aRet_List[N][1] = PID (Process ID). ;                                                                   $aRet_List[N][2] = Process File Path. ;                          On Failure -  Return '' (empty string) and set @error to: ;                                                                   1 - Unable to Open Kernel32.dll. ;                                                                   2 - Unable to Open Psapi.dll. ;                                                                   3 - No Processes Found. ; ; Author(s):               G.Sandler (a.k.a MrCreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _ProcessListEx($sResourceName="", $sInResString="", $iWholeWord=1)     Local $aProcList = ProcessList()     Local $hKernel32_Dll = DllOpen('Kernel32.dll'), $hPsapi_Dll = DllOpen('Psapi.dll')     Local $aOpenProc, $aProcPath, $sFileVersion, $aRet_List[1][1]         If $hKernel32_Dll = -1 Then Return SetError(1, 0, '')         If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & '\Psapi.dll')     If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & '\Psapi.dll')     If $hPsapi_Dll = -1 Then Return SetError(2, 0, '')         Local $vStruct      = DllStructCreate('int[1024]')     Local $pStructPtr   = DllStructGetPtr($vStruct)     Local $iStructSize  = DllStructGetSize($vStruct)         For $i = 1 To UBound($aProcList)-1         $aOpenProc = DllCall($hKernel32_Dll, 'hwnd', 'OpenProcess', _             'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $aProcList[$i][1])                 If Not IsArray($aOpenProc) Or Not $aOpenProc[0] Then ContinueLoop                 DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _             'hwnd', $aOpenProc[0], _             'ptr', $pStructPtr, _             'int', $iStructSize, _             'int_ptr', 0)                 $aProcPath = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _             'hwnd', $aOpenProc[0], _             'int', DllStructGetData($vStruct, 1), _             'str', '', _             'int', 2048)                 If Not IsArray($aProcPath) Or StringLen($aProcPath[3]) = 0 Then ContinueLoop                 $sFileVersion = FileGetVersion($aProcPath[3], $sResourceName)                 If $sResourceName = "" Or $sFileVersion = $sInResString Or _             ($iWholeWord = 0 And StringInStr($sFileVersion, $sInResString)) Then                         $aRet_List[0][0] += 1             ReDim $aRet_List[$aRet_List[0][0]+1][3]             $aRet_List[$aRet_List[0][0]][0] = $aProcList[$i][0]     ;Process Name             $aRet_List[$aRet_List[0][0]][1] = $aProcList[$i][1]     ;PID (Process ID)             $aRet_List[$aRet_List[0][0]][2] = $aProcPath[3]         ;Process File Path         EndIf     Next         DllClose($hKernel32_Dll)     DllClose($hPsapi_Dll)         If $aRet_List[0][0] < 1 Then Return SetError(3, 0, '')     Return $aRet_List EndFunc


Inspired by this thread, enjoy Posted Image
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team








#2 Scriptonize

Scriptonize

    Adventurer

  • Active Members
  • PipPip
  • 144 posts

Posted 09 June 2008 - 05:57 AM

Nice one.
I get an error though.
After closing the Gui an error pops up:

"There was an error to get ProcessList (@error=3)"
If you learn from It, it's not a mistake!WinServices

#3 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,244 posts

Posted 09 June 2008 - 06:49 AM

After closing the Gui an error pops up

What Gui? Please show an example.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#4 aNewLyfe

aNewLyfe

    Adventurer

  • Active Members
  • PipPip
  • 124 posts

Posted 09 June 2008 - 12:23 PM

thanks nice shortcut :)

Posted Image

I have a blog about programming but mostly about autoit and its in my language (turkish)Btw, feel free to visit it, i answer every comment :P here: autoit


#5 Andreik

Andreik

    Bishop

  • Active Members
  • PipPipPipPipPipPip
  • 2,503 posts

Posted 09 June 2008 - 12:25 PM

Very good script. Thanks MrCreatoR!
:)
When the words fail... music speaks

#6 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 09 June 2008 - 02:17 PM

Nice one.
I get an error though.
After closing the Gui an error pops up:

"There was an error to get ProcessList (@error=3)"

This Error appears in the example-Script, if you have no running COMPILED AutoItScripts when executing the second ProcessListEx
*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#7 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,244 posts

Posted 09 June 2008 - 04:00 PM

This Error appears in the example-Script, if you have no running COMPILED AutoItScripts when executing the second ProcessListEx

Sure, if you not having AutoIt scripts it will show that error, because the second example should return processes with "CompiledScript" resource name (with "AutoIt" string in it).

So that's normal :)

Edited by MrCreatoR, 09 June 2008 - 04:01 PM.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users