Jump to content

How to get number of process's "USER objects"?


Recommended Posts

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

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 by Mbee
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 :D. 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

  • Moderators

Mbee,

Anyone can open a Trac ticket - over to you!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

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 Gude
How 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

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 by Bilgus
@Mbee
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...