I have created an windows service. I want to open some windows based application from this service.
But my windows service is unable to start desktop applications. To enable the access I had to do the following steps:
Opened the administrative tool "Services"
Right clicked on my service and had to select "properties"
Then in the "Log On" tab, selected "Allow service to interact with desktop".
After that my service can open desired windows based processes.
Can I configure my windows service in the code (C#) to access the desktop so that I won't have to change the access permission manually after installation?
In .NET you can override the
OnCommited
method of the service installer class to configure the service to access the desktop. The code will look as follows:Just... don't. That isn't the job of a service. For this job you should be using a user app (perhaps in their startup) that (if necessary) talks to a service via IPC. I'm believe the plan is to make the UI unavailable from services at some point (Vista onwards? I stopped doing service<=>desktop a long time ago).
For considerations:
What you are proposing only really scales to 1, and possibly not event that if you consider that "session 0" is reserved for admin use on some systems (so the interactive user isn't necessarily on session 0).