Dim service As New ServiceController("MyServiceName")
If (service.Status.Equals(ServiceControllerStatus.Stopped)) OrElse (service.Status.Equals(ServiceControllerStatus.StopPending)) Then
service.Start()
Else
service.Stop()
End If
Imports System
Imports System.ServiceProcess
Imports System.IO
Imports System.Threading
Class RestartIIS
Shared Sub Main(ByVal commandLineArgs() as String)
Run(commandLineArgs(0))
End Sub
Public Sub Run(ByVal machineName as String)
Console.WriteLine("Please enter the Server Name: ")
Dim ServerName As String = Console.ReadLine()
Dim sc As ServiceController = New ServiceController("W3SVC", machineName)
sc.Stop()
Thread.Sleep(2000)
sc.Start()
Console.Write("Press Enter to Exit")
Console.ReadLine()
End Sub
End Class