nowandever29
MIS
Hi,
I've got the following code, designed to query, stop and start a remote Windows service. It comiles happily, and runs nicely, with the status label changing dutifully as you hit stop or start.
The problem is, it doesn't actually touch the remote machine - the status label doesn't reflect the actual service status, and stop and start have no effect.
Am I missing something? I'm using VB.Net 2005. Thanks!
Imports System.ServiceProcess
Public Class ServiceStuff
Private Sub ServiceCheck(ByVal HostName As String, ByVal ServiceName As String, ByVal Action As Int32)
Dim ServCont As New System.ServiceProcess.ServiceController
ServCont.MachineName = HostName
ServCont.ServiceName = ServiceName
Select Case Action
Case 1
ServCont.Start()
Case 2
ServCont.Stop()
Case Else
lblStatus.Text = ServCont.Status.ToString
End Select
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ServiceCheck("OLHDC01", "Spooler", 0)
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
ServiceCheck("OLHDC01", "Spooler", 1)
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
ServiceCheck("OLHDC01", "Spooler", 2)
End Sub
End Class
I've got the following code, designed to query, stop and start a remote Windows service. It comiles happily, and runs nicely, with the status label changing dutifully as you hit stop or start.
The problem is, it doesn't actually touch the remote machine - the status label doesn't reflect the actual service status, and stop and start have no effect.
Am I missing something? I'm using VB.Net 2005. Thanks!
Imports System.ServiceProcess
Public Class ServiceStuff
Private Sub ServiceCheck(ByVal HostName As String, ByVal ServiceName As String, ByVal Action As Int32)
Dim ServCont As New System.ServiceProcess.ServiceController
ServCont.MachineName = HostName
ServCont.ServiceName = ServiceName
Select Case Action
Case 1
ServCont.Start()
Case 2
ServCont.Stop()
Case Else
lblStatus.Text = ServCont.Status.ToString
End Select
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ServiceCheck("OLHDC01", "Spooler", 0)
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
ServiceCheck("OLHDC01", "Spooler", 1)
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
ServiceCheck("OLHDC01", "Spooler", 2)
End Sub
End Class