Quote:
Originally Posted by Kraizy
well, again vb.net but u should be able to translate it to c#:
PHP Code:
for each x in p as process in process.getprocessesbyname("notepad") where p.mainwindowtitle = "Untitled - Notepad" msgbox(x.id) next
Not sure if its 100% correct, I'm on my phone atm..also, if u r sure that there is only one same window title, u dont need to use a loop
@jD ur method is kinda overkill
|
You would need to use a loop. getprocessesbyname returns all processes with the friendly exe name. For example, I could have chrome.exe running and the "name" that I would use is getprocessesbyname("chrome"). However, I would need to loop through them all to find the one out of possible 100 processes that are running to find the single website title I was looking for, hence why you would need to loop.
EDIT: Sorry didn't see the call to "where". Still, chrome uses multiple child processes for each tab and each has the same main window title handle applied to them. FindWindow finds only the parent process to each child process.
ALSO, callig GetProcessesByName in a foreach or with a linq call on the end of it causes GetProcessesByName to be called each iteration of the loop. You are better storing it in a variable before using it in a foreach or a loop.
I just did some tests, the P/Invoke is almost 5x faster ^.^
-jD