Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I get the window handle by giving the process name that is running?

Tags:

c#

process

How can I get the window handle by giving the process name or window title in c#.. given the process is in running already

like image 878
satya Avatar asked Dec 23 '09 15:12

satya


People also ask

How do I find the process handle by name?

auto processId = FindProcessId(L"blabla.exe"); Show activity on this post. You can use GetModuleName (I think?) to get the name and check against that. Most of the GetModuleName, QueryFullProcessImage name, etc., require a handle and thus won't be of much use.

How can I get Hwnd from process id?

You can use EnumWindows and GetWindowThreadProcessId() functions as mentioned in this MSDN article.

What is main window handle?

The MainWindowHandle property is a value that uniquely identifies the window that is associated with the process. A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window, the MainWindowHandle value is zero.


1 Answers

You can use the Process class.

Process[] processes = Process.GetProcessesByName("someName");  foreach (Process p in processes) {     IntPtr windowHandle = p.MainWindowHandle;      // do something with windowHandle } 
like image 124
Ryan Alford Avatar answered Sep 20 '22 10:09

Ryan Alford