0
votes

Used ServiceController to start my windows service from a Windows Form application. But this is not working.

ServiceController service = new ServiceController(serviceName);

This statement not working.

Is there any other way to start windows service from my application.

Service Display Name: Duress Alert Service
Service Name: Service1

How I can restart my service in c#?

Your help is really appreciated! Thanks!

EDIT 1:

According to MSDN from below answer:

ServiceController sc  = new ServiceController();
sc.ServiceName = "Service1";

It shows red line under ServiceName and error:

ServiceController does not contains the definition of ServiceName. No extension method 'ServiceName' no accepting a first argument of type controller could not be found (are you missing a using directive or an assembly reference?)

While I have added the reference of service process:

using System.ServiceProcess;

But it still showing the error.

1
ServiceController works. - jspcal
What do you mean by not working? Show the exception. - Richard Schneider
There is something fishy going on with this user stackoverflow.com/questions/6667799/… You answered a question on this yesterday then pasted your answer as a question today - TheGeneral
@TheGeneral yes I have posted that answer related to adding reference how is that answer is same to this question? - stefan

1 Answers

2
votes