472,808 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,808 software developers and data experts.

Get Executable name from Window Handle

I need to get the executable name for window under the cursor. I feel like
my code is pretty close but the i never find a process.Handle that matches
the handle under my mouse.

here is my code:
public object ParentExecutable(IntPtr hWndUnderMouse)
{
object p = null;
System.Diagnostics.Process[] allProcesses =
System.Diagnostics.Process.GetProcesses();
for(int iii = 0; iii < allProcesses.Length; iii++)
{
try
{
if(((System.Diagnostics.Process)allProcesses[iii]).Handle ==
hWndUnderMouse)
{
p = ((System.Diagnostics.Process)allProcesses[iii]);
iii = allProcesses.Length;
}
}
catch{}
}
return p;
}
Thanks in advance for any help,
~Logan
Jul 21 '05 #1
2 8067
I figured out what i needed to do. here is the new code
[DllImport("user32")]
public extern static int GetWindowThreadProcessId(
int hwnd,
ref int lpdwProcessId);
public object ParentExecutable(IntPtr hWnd)
{
object p = null;
int id = 0;
int i = UnManagedMethods.GetWindowThreadProcessId(hWnd.ToI nt32(),ref id);

System.Diagnostics.Process[] allProcesses =
System.Diagnostics.Process.GetProcesses();
for(int iii = 0; iii < allProcesses.Length; iii++)
{
try
{
if(((System.Diagnostics.Process)allProcesses[iii]).Id == id)
{
p = ((System.Diagnostics.Process)allProcesses[iii]);
iii = allProcesses.Length;
}
}
catch{}
}
return p;
}
"Logan" <lo***@globalweb.net> wrote in message
news:uk**************@TK2MSFTNGP14.phx.gbl...
I need to get the executable name for window under the cursor. I feel like
my code is pretty close but the i never find a process.Handle that matches
the handle under my mouse.

here is my code:
public object ParentExecutable(IntPtr hWndUnderMouse)
{
object p = null;
System.Diagnostics.Process[] allProcesses =
System.Diagnostics.Process.GetProcesses();
for(int iii = 0; iii < allProcesses.Length; iii++)
{
try
{
if(((System.Diagnostics.Process)allProcesses[iii]).Handle ==
hWndUnderMouse)
{
p = ((System.Diagnostics.Process)allProcesses[iii]);
iii = allProcesses.Length;
}
}
catch{}
}
return p;
}
Thanks in advance for any help,
~Logan

Jul 21 '05 #2
>I need to get the executable name for window under the cursor.

There's a Win32 API function GetWindowModuleFileName that does this.

I feel like
my code is pretty close but the i never find a process.Handle that matches
the handle under my mouse.


That's because window handles and process handles are different
things.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jay Haslup | last post by:
I am trying to figure out how to get the CMD (dos) window to come up when I call a executable. I have this working on a Win2000/apache machine and am trying to use the same code on a identical...
3
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
2
by: er441298 | last post by:
we are upgrading an application which is JS heavy to run on IE6. When in IE 5.0, and when the following command is executed on a child window (top.window.name), it returns an actual window ID ( a...
1
by: George Cooper | last post by:
Can anyone help please. I need a small executable (either the VB code or the program itself will do) to run within a batch file to activate a running 3rd party DOS window (identified by the window...
3
by: Regis Melo | last post by:
Hello, I'm trying to get the "EXE" name of app that runs the current window. To get the current window I use: private static extern int GetForegroundWindow();
14
by: libs | last post by:
I have A.exe that should catch the return code of B.exe (both are written in VB.net) so A.exe can continue processing other commands. but A.exe cannot catch B's return code so an exception is not...
2
by: Logan | last post by:
I need to get the executable name for window under the cursor. I feel like my code is pretty close but the i never find a process.Handle that matches the handle under my mouse. here is my code:...
11
by: Bit byte | last post by:
I want to create a GUI-less windows executable (i.e. an executable that has no gui) and no console. The idea is to have this running as a kind of daemon (it can't be a service, for reasons I wont...
4
by: drodrig | last post by:
Hi. I am trying to close/kill all processes that show visible windows on Windows XP. So far I've created a script that uses win32gui.EnumWindows to iterate through all windows, check for which...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.