Mbee Posted March 5, 2018 Share Posted March 5, 2018 I'm faced with a problem working with a third-party application. One of the first things I do is to check to see if the third-party process in question is already running, and if not, I launch it. However, it turns out that on occasion a process with exactly the same name but otherwise dead (such as when the previous one failed to exit cleanly and cannot be completely killed except by rebooting) is still running, in which case I try to work with this dead application. In trying to find some way to differentiate between dead processes and live ones, the only difference I can find is that the dead process has zero "USER Objects" aka "USER handles" when I view the processes with Process Hacker and the like. How can I get this count given a PID (or whatever)? Thanks! Link to comment Share on other sites More sharing options...
Bilgus Posted March 5, 2018 Share Posted March 5, 2018 See _WinAPI_GetGuiResources in the autoIt helpfile Link to comment Share on other sites More sharing options...
Mbee Posted March 5, 2018 Author Share Posted March 5, 2018 (edited) 10 hours ago, Bilgus said: See _WinAPI_GetGuiResources in the autoIt helpfile Thanks, Bilgus! But I'm not sure that will work. The main issue relates to _WinAPI_GetGuiResources():. According to the help file, if it runs into a problem, it returns a count of zero. But what I'm looking for is a valid count of zero! There's no way to distinguish a valid count of zero objects from an error return. Can you suggest any solution or alternative function / algorithm? Well, I could call _WinAPI_GetLastError(). However, I have no idea what the return values could be. Any guidance? Thanks. Edited March 5, 2018 by Mbee Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 5, 2018 Moderators Share Posted March 5, 2018 Mbee, If you get 0 returned from _WinAPI_GetGuiResources then, as suggested in the Help file, call _WinAPI_GetLastError to see if there was an error returned - if not, then it is a valid 0. 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...
Mbee Posted March 5, 2018 Author Share Posted March 5, 2018 5 minutes ago, Melba23 said: Mbee, If you get 0 returned from _WinAPI_GetGuiResources then, as suggested in the Help file, call _WinAPI_GetLastError to see if there was an error returned - if not, then it is a valid 0. M23 Hi, Melba23, and thanks! While you were posting this, I was editing my previous post to indicate that I could do as you suggest. But as I told Bilgus, I've never used that function and I'm quite unclear as to what to expect as a return. In other words, how do I distinguish between an error and a non-error? Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 5, 2018 Moderators Share Posted March 5, 2018 Mbee, Quote I've never used that function Ditto - but I imagine that a return of 0 would mean no error - anything else would indicate a problem. 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...
Mbee Posted March 5, 2018 Author Share Posted March 5, 2018 16 minutes ago, Melba23 said: Mbee, Ditto - but I imagine that a return of 0 would mean no error - anything else would indicate a problem. M23 Frankly, I'm quite surprised and disappointed that, even in the help file, there's no information regarding the return values, not even whether it returns an integer or string! Even the example shown on the MSDN page on the equivalent function is quite ambiguous, but the primary indication was that it was a string. However, the MSDN page specifically on the function itself shows it's a DWORD, so it's an integer with bit 29 indicating whether it represents whether it's a system return code (bit 29 = 0) or a user code. Melba23, my friend, you're an all high AutoIt muckety-muck, or at least a demi-muckety-muck . Perhaps you could request that the help file be updated with this info? In any case, thanks again! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 5, 2018 Moderators Share Posted March 5, 2018 Mbee, Anyone can open a Trac ticket - over to you! 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...
Bilgus Posted March 5, 2018 Share Posted March 5, 2018 There is nothing wrong with that help entry for _WinAPI_GetGuiResources I understood it exactly just glancing at it, granted it doesn't give a return 'format' but in Autoit it doesn't matter What is this checking if bit 29 is set stuff you are on about? Link to comment Share on other sites More sharing options...
Mbee Posted March 5, 2018 Author Share Posted March 5, 2018 1 minute ago, Bilgus said: There is nothing wrong with that help entry for _WinAPI_GetGuiResources I understood it exactly just glancing at it, granted it doesn't give a return 'format' but in Autoit it doesn't matter What is this checking if bit 29 is set stuff you are on about? Read it yourself. https://msdn.microsoft.com/en-us/library/windows/desktop/ms679360(v=vs.85).aspx Also, your assertions are wrong (besides being rude). If it returned an error message string, you couldn't compare it to integer zero or one, so it does indeed matter. Earthshine 1 Link to comment Share on other sites More sharing options...
Bilgus Posted March 5, 2018 Share Posted March 5, 2018 No I've yet to be rude just direct, you are just being ambiguous GetLastError Return Value Returns the Last error code Related _WinAPI_GetLastErrorMessage _WinAPI_GetLastErrorMessage ( ) Return Value Success:the last error message. Link to comment Share on other sites More sharing options...
BrewManNH Posted March 5, 2018 Share Posted March 5, 2018 GetLastError returns an error message, GetGUIResources returns a 0 or the count of handles in use. The help file is correct. 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...
Bilgus Posted March 5, 2018 Share Posted March 5, 2018 (edited) I'm still unsure what you are on about did I miss a few posts or something? #include <WinAPI.au3> Local $iGDI_handles = _WinAPI_GetGuiResources(0, 0) ConsoleWrite("GDIh:" & $iGDI_handles & @CRLF) $ErrCode = _WinAPI_GetLastError() ConsoleWrite($ErrCode & ":" & BitAND($ErrCode, 0x20000000) & @CRLF) ConsoleWrite(_WinAPI_GetLastErrorMessage() & @CRLF) ConsoleWrite(@CRLF) $iGDI_handles = _WinAPI_GetGuiResources(0, -1) ConsoleWrite("GDIh:" & $iGDI_handles & @CRLF) $ErrCode = _WinAPI_GetLastError() ConsoleWrite($ErrCode & ":" & BitAND($ErrCode, 0x20000000) & @CRLF) ConsoleWrite(_WinAPI_GetLastErrorMessage() & @CRLF) ConsoleWrite(@CRLF) $iGDI_handles = _WinAPI_GetGuiResources(0, -1) ConsoleWrite("GDIh:" & $iGDI_handles & @CRLF) If $iGDI_handles = 0 Then $ErrCode = _WinAPI_GetLastError() ConsoleWrite($ErrCode & ":" & BitAND($ErrCode, 0x20000000) & @CRLF) ConsoleWrite(_WinAPI_GetLastErrorMessage() & @CRLF) EndIf Edited March 5, 2018 by Bilgus @Mbee Link to comment Share on other sites More sharing options...
Bilgus Posted March 5, 2018 Share Posted March 5, 2018 Func GetGuiResources($iFlag = 0, $iPID = -1) _WinAPI_SetLastError(0) Local $iGDI_handles = _WinAPI_GetGuiResources(0, $iPID) Local $iErrCode = _WinAPI_GetLastError() If $iErrCode <> 0 Then Return SetError(1, $iErrCode, -1) Return $iGDI_handles EndFunc maybe you are looking for something like this? 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