I have a Windows Service that runs in my computer and is initialized when the computer turns on (it has a few dependencies on other services, but is initialized right after them).
Then, I have a different application, that depends on that service for running (the application contains an UI).
I would like to start this application whenever the service is started. Therefore, I use the following code in the "OnStart()" event of the service:
var process = new Process();
process.StartInfo = new ProcessStartInfo
{
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Maximized
};
try
{
process = Process.Start(applicationPath);
return (true);
}
catch (Exception e)
{
Logger.Log("ApplicationHelper::OpenApplication Error: " + e.Message);
Logger.Log(applicationPath);
return (false);
}
What happens is that the process of the application starts running, but the UI is not shown. I can only see that the process is running in the task manager. How can I launch the application from the Windows Service?
I have already enabled the option to interact with desktop, but it did not help.
I am using .Net 4 and Windows 7.
Thanks!
In fact, when I try to open the service, a windows message pops up saying that it is a different user than the current logged one trying to send a message. But I can't configure the starting user of the service to be the current one.
It is possible for a service to launch an application in the context of the logged-in user, but it is very difficult. In this case, since the service starts as soon as the system has booted, there probably isn't a user logged in yet anyway!
Instead, just add the application to the Run key in the registry, so that it will start when the user logs in. Since it is dependent on the service, you should probably get it to check whether the service has started yet and wait if necessary.