Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ServiceController not working???

Status
Not open for further replies.
Jan 23, 2002
63
0
0
US
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
 
OK, I found the answer. The class IS working, it's Microsoft's own tool that wasn't reading the value correctly.

Damn, the thing works fast!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top