Starting a process from inside a windows service

  • Thread starter Thread starter Dilip Krishnan
  • Start date Start date
D

Dilip Krishnan

You may want to consider a ms task/job instead. Ideally a service
shouldnt have a gui dependency
 
Hi,

I am trying to start a process from inside a .NET service. The process is a
simple GUI app, the service will start up the GUI and then stop itself. The
service starts the app, but no GUI appears. However, I can see the
application running in the task manager. I made sure that CreateNoWindow was
set to false and still no GUI appears. If i run the application by double
clicking on it, the GUI appears fine. Here is the code:

Process p = new Process();
p.StartInfo.FileName = _basedir + "DbUpdate.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.UseShellExecute = true;
p.Start();

Essentially, I am checking the version of a database and if it is not the
correct version, I want to stop the service and start up the updating
utility. The service runs, starts the process, and exits as expected, but
the GUI does not appear, except as a process in Task Manager. If it matters,
I am executing the code through a class using remoting and it is in the
constructor of the class. Also note that the service exits immediately after
starting the process, although I did not think that would be a problem.

If anyone has any insight into the cause of this problem, it would be very
helpful to me.

-Timothy Shih
 
Timothy,

You have to check the properties of the service, and make sure that the
checkbox that says "allow service to interact with desktop" is checked.
However, this is a bad idea, because you can not guarantee that you always
have an interactive user session to show a GUI for.

Hope this helps.
 
Nicholas Paldino said:
Timothy,

You have to check the properties of the service, and make sure that the
checkbox that says "allow service to interact with desktop" is checked.
However, this is a bad idea, because you can not guarantee that you always
have an interactive user session to show a GUI for.

....and if your service is running under the Local System account (which is
the case most of the time unless you change it to a more restrictive
account), the GUI application you are trying to launch will have all the
Local System account right, which means even more rights than the
Administrator account! Definitely no a good idea.
 
Back
Top