S
srcleveland
I am trying to have a windows service stop itself. I am currently
using the following code but I would like to find a way to stop the
service without having to shell out to a command prompt
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = " /C sc stop \"" + this.serviceDisplayName +
"\"";
p.Start();
p.WaitForExit();
One of the drawbacks of the above code is that you have to know the
name under which the service is running in order to be able to stop it.
using the following code but I would like to find a way to stop the
service without having to shell out to a command prompt
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = " /C sc stop \"" + this.serviceDisplayName +
"\"";
p.Start();
p.WaitForExit();
One of the drawbacks of the above code is that you have to know the
name under which the service is running in order to be able to stop it.