Louky
Louky

Reputation: 61

Start Windows Service remotely access

I'm trying to start and stop a windows service on server1 from a deployed asp.net application on server2.

I'm using the following code to start it but an "Access denied" exception is thrown because I'm a non-admin user:

string serviceName = System.Configuration.ConfigurationSettings.AppSettings["ServiceName"];
string machineName = System.Configuration.ConfigurationSettings.AppSettings["MachineName"];

System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController(serviceName, machineName);

if (service.Status == ServiceControllerStatus.Running)
{
    return Json("Service is running.", JsonRequestBehavior.AllowGet);
}
TimeSpan timeout = TimeSpan.FromMilliseconds(1000);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);

if (service.Status == ServiceControllerStatus.Running)
{
    return Json("Service started successfully.", JsonRequestBehavior.AllowGet);
}
else
{
    return Json("Could not start the service.", JsonRequestBehavior.AllowGet);
}

Can anyone help me, please ?

Upvotes: 1

Views: 1056

Answers (1)

Louky
Louky

Reputation: 61

to control windows service remotly we need administrator rights so i only edited the permissions for my windows service using Service Security Editor .http://www.coretechnologies.com/products/ServiceSecurityEditor it may help you.

Upvotes: 2

Related Questions