Sign in to follow this  
Followers 0
Chimp

who is the parent of an msgbox?

10 posts in this topic

Hello to You that are reading this,

With the WinExists() function I check if a windows (an msgbox in my case) with a specified text title appear on the screen, and when it does, I simply close it.

Select
Case WinExists(" Reset ok", "The reset command was executed on remote client")
WinClose(" Reset ok")
Case WinExists("client not online", "The client was unreachable")
WinClose("client not online")
EndSelect

well, is it there a way to know the handle of the executable who opened that window? (an msgbox on my case).

Thanks on advance.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

hi Wayfarer

no, the Windows Info Tool report nothing about the parent.

Edited by Pincopanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

you can try to modify example from _ProcessGetName to see if you can solve it with it


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

hi bogQ

The msgbox appears on screen, but without any associated process ID in taskmanager, so, apparently, no references to the windows (pid) are available to _ProcessGetName.

I would need an "_MsgBoxGetParent()" :) ......


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This one by Gary Frost works for me:

Even Tray Apps if I want to go to the folder where the exe is, I do About Box then hit the hotkey. My HomeFolder program just calls the function in the link above and gets the folder from the exe path.

edit: unless the Hwnd param is used in the MsgBox call, it does not have a parent. But you can still get the exe that launched it using the GF function... provided the Windows in question has the tools he uses.

Edited by MilesAhead

Share this post


Link to post
Share on other sites

I ran a simple script that just displays a message box in it. I ran a second script that just has WinGetProcess in it, I used the title of the message box in that function. It gave me the PID of the exe that is running, the MsgBox doesn't have its own PID, so if you can retrieve the process id of the message box, you have the parent process that created that message box.

Compile this script and run it, but don't click the message box button

GUICreate("test")
GUISetState()
While 1
    If MsgBox(64, "Test MsgBox", "Hello there") Then Exit
WEnd

Run this script, and it will retrieve the PID, you should see the PID of the program that spawned the MsgBox.

ConsoleWrite(WinGetProcess("Test MsgBox") & @crlf)


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

Share this post


Link to post
Share on other sites

Yes!

Thanks MilesAhead & Thanks BrewManNH

with

$pid = WinGetProcess("Title") (window or MsgBox is the same)

I can get the PID of the program that spawned the MsgBox.

thanks a lot again for the useful and quick help! :thumbsup:

bye


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

The Gary Frost function is slower. But it has the advantage that a 32 bit app using it under SysWow64 can get the path of the process associated with a window even if the process is 64 bit.

If both processes have the same "bitness" then this function will work You need the WinAPIEx UDF to include.

; _WindowExeInfo(ByRef $exePath, ByRef $cmdTail, ByRef $workDir, $WindowTitle = "[ACTIVE]")
; on success sets $exePath to executable path of program associated with
; window $WindowTitle and $cmdTail with it's command line args, if any.
;
; Returns 1 on success, 0 otherwise and sets @error.
;
Func _WindowExeInfo(ByRef $exePath, ByRef $cmdTail, ByRef $workDir, $WindowTitle = "[ACTIVE]")
$exePath = ""
$cmdTail = ""
$workDir = ""
Local $pid = WinGetProcess($WindowTitle)
If $pid = -1 Then Return SetError(1, 0, 0)
Local $pHandle = _WinAPI_OpenProcess(0x410, False, $pid)
If @error Then Return SetError(1, 1, 0)
$exePath = _WinAPI_GetModuleFileNameEx($pHandle)
If $exePath = "" Then
_WinAPI_CloseHandle($pHandle)
Return SetError(1, 2, 0)
EndIf
$workDir = _WinAPI_GetProcessWorkingDirectory($pid)
If $workDir = "" Then
_WinAPI_CloseHandle($pHandle)
Return 1
EndIf
$cmdTail = _WinAPI_GetProcessCommandLine($pid)
_WinAPI_CloseHandle($pHandle)
Return 1
EndFunc ;==>_WindowExeInfo

GetModuleFileNameEx() doesn't work across the 32/64 bit divide.

Edited by MilesAhead

Share this post


Link to post
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
Sign in to follow this  
Followers 0