HOME > .NET Framework > Forum > Asp.net. สั่งให้ start-stop-restart service ใน control panel ของ Windows ได้ยังไงครับ (Start/Stop Services With ASP.NET)
Asp.net. สั่งให้ start-stop-restart service ใน control panel ของ Windows ได้ยังไงครับ (Start/Stop Services With ASP.NET)
มี tool serviecontroler อยู่ครับ ให้ใส่ชื่อ process ลงไปก็ส่ง ได้แล้วครับ
Date :
2010-11-23 21:58:14
By :
mahapali
No. 3
Guest
Code (VB.NET)
'Try
Dim squidService As New System.ServiceProcess.ServiceController("Squid")
If squidService.Status = ServiceProcess.ServiceControllerStatus.Running Then
' Problem Occurs Here.
squidService.Stop()
End If
squidService.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)
squidService.Start()
squidService.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running)
'Catch ex As Exception
'lblInfo.Text = "An error occurred while attempting to restart squid: " + ex.Message
'End Try
' Visual Basic
Sub Main()
Dim myController As _
New System.ServiceProcess.ServiceController("IISAdmin")
If myController.CanStop Then
Debug.WriteLine(myController.ServiceName & " can be stopped.")
Else
Debug.WriteLine(myController.ServiceName & " cannot stop.")
End If
End Sub
Code (C#)
// C#
public static void Main(string[] args)
{
System.ServiceProcess.ServiceController myController =
new System.ServiceProcess.ServiceController("IISAdmin");
if (myController.CanStop)
{
System.Diagnostics.Debug.WriteLine(
myController.DisplayName + " can be stopped.");
}
else
{
System.Diagnostics.Debug.WriteLine(
myController.DisplayName + " cannot stop.");
}
}