Imports System.ServiceProcess

Public Class Form1

Private Sub btnQueryBES_Click(sender As System.Object, e As System.EventArgs) Handles btnQueryBES.Click
 Dim txt As String = "besclient" & SC(txtIPAddress.Text, "besclient", "query")
End Sub
Private Sub btnStartBES_Click(sender As System.Object, e As System.EventArgs) Handles btnStartBES.Click
 Dim txt As String = "besclient" & SC(txtIPAddress.Text, "besclient", "start")
End Sub
Private Sub btnStopBES_Click(sender As System.Object, e As System.EventArgs) Handles btnStopBES.Click
 Dim txt As String = "besclient" & SC(txtIPAddress.Text, "besclient", "stop")
End Sub
Function SC(MachineName As String, ServiceName As String, cmd As String) As String
 Dim txt As String = ""
 Dim TermService As New System.ServiceProcess.ServiceController(ServiceName, MachineName)

Select Case LCase(cmd)
 Case "start"
 TermService.Start()
 Case "stop"
 TermService.Stop()
 Case Else
 End Select

Select Case LCase(TermService.Status)
 Case "1"
 txt = " stopped"
 Case "2"
 txt = " starting"
 Case "3"
 txt = " stop pending"
 Case "4"
 txt = " running"
 Case Else
 txt = " undetermined"
 End Select

Return txt
 End Function

End Class