Toggle a service on or off -

Toggle a service

Snippet Code

Rate this page :
  [ 0 votes]

Add a reference to the System.ServiceProcess namespace, by going to Project > Add Reference.. and selecting it from the list in the .NET tab.Here u toggle Adobe Version Cue CS3 service

Imports System.ServiceProcess Function ToggleProcess(ByVal strServiceName As String) As Boolean Dim service As New ServiceController(strServiceName) Select Case service.Status Case ServiceControllerStatus.Stopped service.Start() Case ServiceControllerStatus.Running service.Stop() Case Else service.Dispose() Return False End Select service.Dispose() Return True End Function ' Example Usage Try ToggleProcess("Adobe Version Cue CS3") Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try


Ask Questions

Ask Question