Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Detect exe

Is there anyway from with OI to detect if a given executable (like winbatch.exe) is running under the current user session?

Comments

  • Jim,

    Yes, there are ways of doing this. However, it is much easier to detect whether or not the class of a form or a specific caption is running rather than the executable itself. When I know what the caption is going to be, then I look for that instead. Would that approach be sufficient?
  • I think so yes, how would I detect it based on specific caption?
  • Jim,

    Sorry for the delay in responding. I have been offline for a bit while my new internet service was being installed and configured.

    Sprezz has published a solution to this in one of their SENL newsletters. Go to page 10 and read the content under Example 3 - Finding a Window by Title Only.

    Disclaimer: I have not been able to get this to work for me. It is highly possible that I did not follow through with the instructions properly. My personal solution is now as straight forward, but it does work. It basically loops through all of the running windows using the GetWindowText API to get the caption. If the caption is a match for what I am looking for then my window is running. Here is some code: // The GetTopWindow API will return the handle of the first window running in z-order. StartHandle = GetTopWindow() NextHandle = StartHandle TextBuffer = Str(\00\, 100) // The GetWindowText API will return the caption text of the window. rv = GetWindowTextA(NextHandle, TextBuffer, Len(TextBuffer)) ThisCaption = TextBuffer[1, \00\] If ThisCaption EQ CaptionText then Handle = NextHandle // If the top window is not a match, then use the GetWindow API to retrieve the next running window's // handle. Continue to loop through each window until a match is found or there are no more windows // to process. Loop Until (NextHandle EQ 0) OR (Len(Handle)) NextHandle = GetWindow(NextHandle, 2) TextBuffer = Str(\00\, 100) rv = GetWindowTextA(NextHandle, TextBuffer, Len(TextBuffer)) ThisCaption = TextBuffer[1, \00\] If ThisCaption EQ CaptionText then Handle = NextHandle Repeat
  • Very cool, that looks perfect.

    Thank you.
  • Jim,

    Just curious, which solution did you go with?
  • In SYSPROCS DLL_USER32 added
    HANDLE STDCALL FindWindowA(LPVOID, LPCHAR) as FindWindowTitle

    Ran Declare_FCNS "DLL_USER32"

    Can then call

    Declare Function FindWindowTitle
    RetVal = FindWindowTitle(0, "OpenEngine":\00\)

    RetVal is non zero if OpenEngine is found.
  • I am now using FindWindow as declared in DLL_USER32 to find the Window via the Class. Too many thing can change the Window title.
Sign In or Register to comment.