Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

cannot open service "servicename" on computer '.'.

$
0
0
For some reason, when using the code below, when I click any of the 2 buttons to stop or start the spooler service, I get the error attached. I've googled it, but I could not find the reason why. Any ideas?

Imports System.ServiceProcess
Public Class Form1
    Dim Spooler As New ServiceController("Spooler")
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Spooler.Status.Equals(ServiceControllerStatus.Running) Then Label1.Text = "Running" : PictureBox1.BackColor = Color.Green : Button1.Enabled = False : Button2.Enabled = True
        If Spooler.Status.Equals(ServiceControllerStatus.Stopped) Then Label1.Text = "Stopped" : PictureBox1.BackColor = Color.Red : Button1.Enabled = True : Button2.Enabled = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Spooler.Start()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Spooler.Stop()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>