Namespace: System.ServiceP rocess
Assembly: System.ServiceP rocess (in system.servicep rocess.dll)
Add a reference to this assembly in your web project, create a
ServiceProcess object and go to town. Some sample code goodness:
// Toggle the Telnet service -
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceControll er sc = new ServiceControll er("Telnet");
Console.WriteLi ne("The Telnet service status is currently set to {0}",
sc.Status.ToStr ing());
if ((sc.Status.Equ als(ServiceCont rollerStatus.St opped)) ||
(sc.Status.Equa ls(ServiceContr ollerStatus.Sto pPending)))
{
// Start the service if the current status is stopped.
Console.WriteLi ne("Starting the Telnet service...");
sc.Start();
}
else
{
// Stop the service if its status is not set to "Stopped".
Console.WriteLi ne("Stopping the Telnet service...");
sc.Stop();
}
// Refresh and display the current service status.
sc.Refresh();
Console.WriteLi ne("The Telnet service status is now set to {0}.",
sc.Status.ToStr ing());
"Przemo" wrote:
Is it possible to start or stop a windows service from ASP.NET 2.0?
Some examples?
thanks
Przemo