私のコードを以下に示します。ボタンをクリックすると、サービスを調べて、何をする必要があるかを判断するはずです。ただし、停止しているかどうかを確認する部分を取得すると、既に開始されているにもかかわらず、開始しようとしているため、エラーが発生します。停止に対して false を返すはずなのに、サービスを開始しようとする理由がわかりません。
任意のヘルプをいただければ幸いです。
Dim sc As New System.ServiceProcess.ServiceController("LPT:One Job Queue Engine")
'This sets the Machine Name/IP Address
'Removed machine name.
sc.MachineName = "**********"
'This tells the service to stop
If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
sc.Stop()
'This tells the program to wait until the service is stopped
sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)
'This starts the service once it has stopped
sc.Start()
End If
'Here is where the problem is!
**If sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped) Then
sc.Start()
End If**
If sc.Status = ServiceProcess.ServiceControllerStatus.StopPending Then
sc.ExecuteCommand("taskkill /F /IM lptjqe.exe")
sc.Start()
End If