Click here to Skip to main content
16,009,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application,I set the global keyboard and mouse hook. I want to the name of exe application to which hooked key is passed so that it will help me for finding to which application that key is used.please tell me, How can get the exe application name(notepad,wordpad etc).
Thanks,
Posted

1 solution

First of all, you don't explain what do you mean by application name. As the application processing your hooked message can be anything (no only .NET assembly), there is no such concept. Too different application can carry the same executable file name, identical text of the windows header, and still be the different, so whatever you do, there in no 100% certain identification.

What you can get is the information on the application's main window handle and hence its text. First of all, you need to obtain some native Windows API methods using P/Invoke.
You can call Windows API GetWindow with parameter GW_OWNER and GetParent to find out the main application windows. (You always use GetWindowText to find out the text of the windows header, but as I say, it is not a reliably unique identifier.)

Then you can list all processes using the class System.Diagnostics.Process and identify the process showing the windows in question by its HWND. This way you can obtain all available process information on the process processing your hook.

—SA
 
Share this answer
 
Comments
Manfred Rudolf Bihy 9-Mar-11 16:51pm    
Good answer. 5+
Sergey Alexandrovich Kryukov 9-Mar-11 18:37pm    
Thank you, hope it helps.
--SA
Sergey Alexandrovich Kryukov 9-Mar-11 18:39pm    
Ujwala, I understand my Answer needs further work. If you're still interested, you can try to implement it, and if you have any problems, feel free to ask a follow-up question.
(Please, don't post as an Answer (a very irritating common mistake), use "Improve question" or "Add comment".
Good luck,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900