I have a windows service and a windows application.I want to start and stop this window service from my windows application with arguments.Here is what i have got to start the service
foreach (ServiceController sc in ServiceController.GetServices())
{
if (sc.ServiceName == "serviceName")
{
//service is found
using (ServiceController serviceController = new ServiceController("serviceName"))
{
string[] args = new string[1];
args[0] = "Myargument";
if (serviceController.Status == ServiceControllerStatus.Running)
{
}
else { serviceController.Start(args); }
}
}
But it gives me cannot open service on computer '.' exception.I tried using app.manifest to force run as administrator but still it gives exception.I also tried this post here but exception is still there.Does any one know how to grant access to manage services in non-admin user in windows 7 ?