Starting services programatically
-
How do I start a service programatically? Is there a way to do it from the command prompt or in the service installer? Thanks a lot, Jim Did I post well? Rate it! Did I post badly? Rate that too!
Add the
System.ServiceProcess.dll
as a reference and useSystem.ServiceProcess.ServiceController
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots -
Add the
System.ServiceProcess.dll
as a reference and useSystem.ServiceProcess.ServiceController
xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots -
Thanks, but how do I use that? I don't see a start command. Thanks, Jim Did I post well? Rate it! Did I post badly? Rate that too!
-
Thanks, but how do I use that? I don't see a start command. Thanks, Jim Did I post well? Rate it! Did I post badly? Rate that too!
You didn't look very hard. ServiceController.Start Method[^] docs on MSDN.
ServiceController myService = new ServiceController(@"MyServiceName");
if ( (myService.Status.Equals(ServiceControllerStatus.Stopped) ) ||
( myService.Status.Equals(ServiceControllerStatus.StopPending) ) )
{
myService.Start();
}
else
{
Console.WriteLine("Service is already running...");
}RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome