jftuga Posted October 31, 2013 Share Posted October 31, 2013 I need to run an operation [the _ReduceMemory() function] on several groups of processes, such as IE, Outlook, and another 3rd party program. This function requires a PID. However, I want to be able to skip the active window. I can use WinGetTitle(["active"]) to see if the current active window matches my criteria. I can use WinGetProcess() to get the PID, however there are always multiple instances of the 3rd party program running and this process only returns one PID, not all of them. I can use WinList() to get an HWND, but don't know how to convert this to PID. I want to run _ReduceMemory() on the non-active instances while skipping the active foreground process. I can't seem to reconcile how to do this. Any help would be greatly appreciated. '?do=embed' frameborder='0' data-embedContent>> Thanks, -John Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
KaFu Posted October 31, 2013 Share Posted October 31, 2013 (edited) Local $var = WinList() Local $s_PID_Buffer For $i = 2 To $var[0][0] If BitAND(WinGetState($var[$i][1]), 2) Then ; is visible if not StringInStr($s_PID_Buffer,";" & WinGetProcess($var[$i][1]) & ";") then ; show PID only once $s_PID_Buffer &= ";" & WinGetProcess($var[$i][1]) & ";" ConsoleWrite($i & @TAB & "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1] & @CRLF & "PID: " & WinGetProcess($var[$i][1]) & @CRLF & @CRLF) endif EndIf Next"Is visible" and "Show PID only once" are of course optional.Afaik Winlist() returns the windows in z-order, meaning the first one is the currently active one. So starting the enumeration with $i = 2 should skip the active window. Edited October 31, 2013 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)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...
jftuga Posted October 31, 2013 Author Share Posted October 31, 2013 KaFu, When I run this, it returns about 10 items, each with a HWND and corresponding PID. Thanks! How can I then determine which of these is the active window? -John Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 31, 2013 Moderators Share Posted October 31, 2013 jftuga. How can I then determine which of these is the active window?As KaFu told you:Afaik Winlist() returns the windows in z-order, meaning the first one is the currently active one. So starting the enumeration with $i = 2 should skip the active window.which is also my experience. You could also get the active handle directly and so avoid it when looping through the list: $hActive = WinGetHandle("[ACTIVE]")M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jftuga Posted October 31, 2013 Author Share Posted October 31, 2013 I did a sleep(2000) at the beginning and set $i=1, just to see what happened. In this 2 second period, I switched to IE. The program returned: i=8 Title=Start Handle=0x0003001A PID: 5800 i=25 Title=Remote Manager Handle=0x00010164 PID: 568 i=43 Title=Getting the win title and pid of active window - General Help and Support - AutoIt Forums - Windows Internet Explorer Handle=0x00040A1C PID: 5852 i=45 Title=Windows Command Processor Handle=0x00190886 PID: 4800 So I am not 100% sure z-order is returned for me on Win 7. That being said, $hActive = WinGetHandle("[ACTIVE]") will be very helpful. I think this is exactly what I needed. Thanks M23! Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
BrewManNH Posted October 31, 2013 Share Posted October 31, 2013 Just an FYI, the _ReduceMemory function doesn't actually reduce the memory used by a program, it just takes what's in memory and swaps it out to the hard drive to the swap file. This just makes your programs run slower, doesn't really do much in the way of reducing memory used, and generally isn't a useful thing to do. Let Windows manage the memory used, the developers of it probably have a much better idea of how to manage memory than the average user. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jdelaney Posted October 31, 2013 Share Posted October 31, 2013 to get the pid #include <WinAPI.au3> $iProcessID = "" _WinAPI_GetWindowThreadProcessId(WinGetHandle("[ACTIVE]"), $iProcessID) ConsoleWrite($iProcessID & @CRLF) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. 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