Stop/Start SQL

In your project you must add a reference to the System.ServiceProcess.Dll

Code:
Dim x As System.ServiceProcess.ServiceController

        For Each x In ServiceProcess.ServiceController.GetServices()
            If x.ServiceName = "MSSQLSERVER" Then
                If x.Status <> ServiceProcess.ServiceControllerStatus.Running Then
                    x.Stop()
                    MessageBox.Show("Service has Stopped")
                Else
                    x.Start()
                    MessageBox.Show("Service has started")
                End If
            End If
        Next
 
Back
Top