|
-
March 16th, 2003, 09:09 PM
#1
Finding window handle from a service
Hi All!
I´m sorry if this ha been posted already but I haven´t been able to find it....
I have an NT service that is trying to send a message to a user application window. I know the window title so I´m trying to use FindWindow and FindWindowEx to get a handle that I can use to send messages using PostMessage and SendMessage... As long as I do it from a "normal" application (Window or console based) it works neat and tidy, but when run from my service, the same piece of code i sunable to retrieve a handle to the window....
So, my question is: How do I correctly get the handle of a user application from an NT service?
Thanks in advance!
-
April 10th, 2003, 01:55 AM
#2
You should set your service to interact with the desktop.
-
April 10th, 2003, 05:55 PM
#3
Doesn´t work if the service runs as a user account(which mine has to do)....
However, I now have found a way to find the handle to an interactive window anyway.
Thanks anyway!
-
April 11th, 2003, 10:43 PM
#4
How did you do it? If you tell us we may also be benefitted.
Muthu
-
April 12th, 2003, 10:50 AM
#5
Well, it was actually simpler than I thought....
In short (I don´t have the details here, but if you like I can elaborate more later on):
Start by getting the Process object of the target application (the one running in user context), using GetProcessByName(string processname).
Now that you have the process you can actually find an IntPtr handle to the main window of the target process by using Process.GetMainWindow() (don´t remember the exact name, but it was similar to that).
Now you have IntPtr that you can pass to the API function PostMessage or SendMessage as the recieving window!
Let me know if you have any problems implementing this...
Greetings!
-
April 12th, 2003, 08:09 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|