Hi,
I have a windows forms app. and I would like to use it as a windows service. How can I do it?
Best Regards.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Mar 12, 2012, 11:42 PM
Sam HobbsPosted Mar 12, 2012, 11:41 PM
An alternative might be a system-wide low-level keyboard hook. I do not know if you can install them from a service but if you can then you are in business. Believe it or not, the Microsoft web site is having problems at the moment, at least for me so I cannot check it for you. I think the function to install hooks is SetWindowsSystemHookEx or something very much like that. You can use a system-wide low-level keyboard hook in C# so if you can do that in a service then you can test your code without making it a service then use the same code in a service, as long as it is allowed in a service.
I don't know the details of what you are doing to get "a screen-shot" but that will be more complicated. You might be able to solve that problem by another system-wide hook to hook messages sent to windows but in order to do that you must use a little unmanaged code (C++); there is no way to get around the need to have some unmanaged code for that. Without knowing what you need to do, my guess is that processing messages would be too complicated.
You can probably access windows (Windows windows) at the device driver level, but it might require extra work to relate the data to the application.
VulpesPosted Mar 12, 2012, 12:02 PM
RaysefoPosted Mar 12, 2012, 8:07 AM
Actually my UI is not visible so I don't care about the UI , since this applicaiton gets the key strokes and screen shots in background. Now do I have chance to convert?
Best Regards.
VulpesPosted Mar 12, 2012, 6:32 AM
Moreover, it's generally thought best if services don't interact with the desktop at all though there is a flag in the service's properties in the Management console which enables you to do this if you must.
Of course, none of this prevents you from rewriting the non-GUI aspects of the WF application as a service where feasible.