MrCreatoR Posted June 6, 2008 Share Posted June 6, 2008 _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.expandcollapse popup#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 EndFuncInspired by this thread, enjoy Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler 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 ProgramUDFs: 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 UDF 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 Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Scriptonize Posted June 9, 2008 Share Posted June 9, 2008 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 Link to comment Share on other sites More sharing options...
MrCreatoR Posted June 9, 2008 Author Share Posted June 9, 2008 After closing the Gui an error pops upWhat Gui? Please show an example. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler 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 ProgramUDFs: 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 UDF 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 Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
aNewLyfe Posted June 9, 2008 Share Posted June 9, 2008 thanks nice shortcut ~ Every Living Thing is a Code Snippet of World Application ~ Link to comment Share on other sites More sharing options...
Andreik Posted June 9, 2008 Share Posted June 9, 2008 Very good script. Thanks MrCreatoR! When the words fail... music speaks. Link to comment Share on other sites More sharing options...
ProgAndy Posted June 9, 2008 Share Posted June 9, 2008 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* [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 Link to comment Share on other sites More sharing options...
MrCreatoR Posted June 9, 2008 Author Share Posted June 9, 2008 (edited) This Error appears in the example-Script, if you have no running COMPILED AutoItScripts when executing the second ProcessListExSure, 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 June 9, 2008 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler 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 ProgramUDFs: 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 UDF 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 Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team 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