Hi,
There is a windows service on server that can be started or stopped from asp.net web application and it worked fine since it ran under the local user account (name it AA) which is not AD account (also an application pool identity). Web app is hosted on the same machine as service. Service was configured to log on as local system.
But when I changed log in to web app so the users can log in using their AD account I can't start/stop service from web app anymore. I've googled for solutions, tried them all but had no success. My application pool identity for web app is AD user (name it XY) created just for this. This XY user is localy in adminstrators group and assigned "Log on as a service" permission. If I run Visual Studio 2017 as administrator then it works ok.
This is code:
ServiceController sc = new ServiceController("service name", _serviceMachineName); //_serviceMachineName - parameter set in database so this could be done on remote machine
if ((sc.Status.Equals(ServiceControllerStatus.Stopped)) ||
(sc.Status.Equals(ServiceControllerStatus.StopPending)))
{
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);
btnStartStopService.Text = GetGlobalResourceObject("AspxResources", "stop_service").ToString();
divStatus.InnerHtml = GetGlobalResourceObject("AspxResources", "service_status_running_html").ToString();
}
else
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped);
btnStartStopService.Text = GetGlobalResourceObject("AspxResources", "start_service").ToString();
divStatus.InnerHtml = GetGlobalResourceObject("AspxResources", "service_status_stopped_html").ToString();
}
How should I configure service log on (to run under local system, network service or AD user) should I change c# code ... to make it start/stop from web app?