Checking a Windows Service State and Starting one

  • Thread starter Thread starter John Wright
  • Start date Start date
J

John Wright

I need to know how to check the state of a windows service. I need to
determine if the windows service "Smart Card" is running. If it is not
running, I need to start the service. Also it would be nice to set it to
automatic so I wouldn't have to keep checking. Anyone know how to start a
service from VB.NET code? I want to put the check and service activation in
my program startup module. Thanks.

John
 
I need to know how to check the state of a windows service. I need to
determine if the windows service "Smart Card" is running. If it is not
running, I need to start the service. Also it would be nice to set it to
automatic so I wouldn't have to keep checking. Anyone know how to start a
service from VB.NET code? I want to put the check and service activation in
my program startup module. Thanks.

John

John,

Look at System.ServiceProcess.ServiceController, I believe it should
provide you with what you need.
 
Thanks. That is what I needed.

John
Tom Shelton said:
John,

Look at System.ServiceProcess.ServiceController, I believe it should
provide you with what you need.
 
Thanks. That is what I needed.


Look at System.ServiceProcess.ServiceController, I believe it should
provide you with what you need.

If a sample you need then:

Add a service controller from toolbox and associate with the service
you desire.
Note that here is "myservice" is your control name and set "service
name" as "SCardSvr" for Smart Card.

If myservice.Status = ServiceProcess.ServiceControllerStatus.Stopped
Then
MsgBox("Service is NOT working, please start service",
MsgBoxStyle.Exclamation, "Warning")
ElseIf myservice.Status =
ServiceProcess.ServiceControllerStatus.Running Then
MsgBox("Service is Working!", MsgBoxStyle.Information, "Have fun")
End If

Hope this helps.
 
Back
Top