Checking a Windows Service State and Starting one

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
 
T

Tom Shelton

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.
 
J

John Wright

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.
 
K

kimiraikkonen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top