Can anyone help? I have been struggling with creating a service which calls an external process but it just doesn't work. Please see attached code. The service installs and starts and stops fine but the call to the external process does not work.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
namespace ExternalCommand
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
System.Diagnostics.Process.Start(@"c:\windows\system32\notepad.exe");
}
protected override void OnStop()
{
System.Diagnostics.Process.Start(@"c:\windows\system32\cmd.exe");
}
}
}
AlanPosted Jul 19, 2008, 4:03 PM
A windows service runs in its own 'windows station' which, unlike the user's desktop, is not interactive. This is probably why you can't see the applications you're launching from the service.
In the service management console, if you click on the properties for your service then, under the Log On tab, there is an option called "Allow Service to interact with the desktop" under Local System Account.
I'd see if it makes any difference if you check this option.