Yigalr01 Posted July 21, 2010 Share Posted July 21, 2010 (edited) Hello ! I am looking for a way to detect a PID of some subprocess .... By AutoIt script i creating (dynamically) a BAT file with environment specifications... ----------------- BAT FILE -------------------------------------- set path=C:\oracle\product\10.2.0\client_1\bin;%windir%;%windir%\system32 set ORACLE_HOME=C:\mll\oracle\product\10.2.0\client_1 set NLS_LANG=AMERICAN_AMERICA.IW8ISO8859P8 set NLS_DATE_FORMAT=YYYY-MM-DD HH24:MI:SS cd \ cd /d y:\centura start /SEPARATE /HIGH c:\soft1.exe exit ------------------------------------------------------- After creation that Autoit script - execute this BAT file. From a Bat file I call to EXE file (For example soft1.exe), witch call to another exe file (soft2.exe) I am looking for a way to detect PID of soft1.exe and soft2.exe Please help ! Edited July 21, 2010 by Yigalr01 Link to comment Share on other sites More sharing options...
KaFu Posted July 21, 2010 Share Posted July 21, 2010 (edited) Just yesterday saw the function _ProcessGetChildren($i_pid) as part of this question: Enhancing AutoIT ScreenSaver Example. From a quick look it might be what you're searching , give it a try...Edit: Gave it a quick test, be aware that this seems limited to 32bit though...expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <array.au3> $aRes = _ProcessGetChildren(ProcessExists("explorer.exe")) ConsoleWrite(@error) _ArrayDisplay($aRes) ; _ProcessGetChildren Func _ProcessGetChildren($i_pid) Local Const $TH32CS_SNAPPROCESS = 0x00000002 Local $a_tool_help = DllCall('Kernel32.dll', 'long', 'CreateToolhelp32Snapshot', 'int', $TH32CS_SNAPPROCESS, 'int', 0) If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_pid) Local $tagPROCESSENTRY32 = _ DllStructCreate _ ( _ 'dword dwsize;' & _ 'dword cntUsage;' & _ 'dword th32ProcessID;' & _ 'uint th32DefaultHeapID;' & _ 'dword th32ModuleID;' & _ 'dword cntThreads;' & _ 'dword th32ParentProcessID;' & _ 'long pcPriClassBase;' & _ 'dword dwFlags;' & _ 'char szExeFile[260]' _ ) DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32)) Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32) Local $a_pfirst = DllCall('Kernel32.dll', 'int', 'Process32First', 'long', $a_tool_help[0], 'ptr', $p_PROCESSENTRY32) If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_pid) Local $a_pnext, $a_children[11] = [10], $i_child_pid, $i_parent_pid, $i_add = 0 $i_child_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ProcessID') If $i_child_pid <> $i_pid Then $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ParentProcessID') If $i_parent_pid = $i_pid Then $i_add += 1 $a_children[$i_add] = $i_child_pid EndIf EndIf While 1 $a_pnext = DllCall('Kernel32.dll', 'int', 'Process32Next', 'long', $a_tool_help[0], 'ptr', $p_PROCESSENTRY32) If IsArray($a_pnext) And $a_pnext[0] = 0 Then ExitLoop $i_child_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ProcessID') If $i_child_pid <> $i_pid Then $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, 'th32ParentProcessID') If $i_parent_pid = $i_pid Then If $i_add = $a_children[0] Then ReDim $a_children[$a_children[0] + 10] $a_children[0] = $a_children[0] + 10 EndIf $i_add += 1 $a_children[$i_add] = $i_child_pid EndIf EndIf WEnd If $i_add <> 0 Then ReDim $a_children[$i_add + 1] $a_children[0] = $i_add EndIf DllCall('Kernel32.dll', 'int', 'CloseHandle', 'long', $a_tool_help[0]) If $i_add Then Return $a_children Return SetError(3, 0, 0) EndFunc ;==>_ProcessGetChildrenEdit 2: And why created a bat file at all? Take a look at EnvSet(). Edited July 21, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Yigalr01 Posted July 21, 2010 Author Share Posted July 21, 2010 Thank You for response ! I will try using _ProcessGetChildren... And thank you for a tip about EnvSet() Link to comment Share on other sites More sharing options...
Ascend4nt Posted July 21, 2010 Share Posted July 21, 2010 There's a function in my Process Functions UDF that does the same thing as above basically, but has Unicode support, is x64 safe, and allows more than just PID filtering. However, I believe all that needs to be changed for the above code for x64 safety is the tagPROCESSENTRY32 struct, namely 'th32DefaultHeapID' needs to be made a 'ulong_ptr'. If you want to add Unicode support, you'll have to change a few other things as well (char to wchar, function names for Process32First/Next need 'W' appended..) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) 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