Restart a Windows Service using vb.net

S

Sean

Greetings,

Is there a sample code that shows how to restart a windows service using
VB.Net?

Sean
 
P

Peter Huang [MSFT]

Hi

You may try to see if the code below helped you.
Imports System.ServiceProcess
Module Module2
Public Sub Main()
Dim sc As New ServiceController("Themes")
sc.Stop()
Console.ReadLine()
sc.Start()
End Sub
End Module

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jay B. Harlow [MVP - Outlook]

Sean,
I use code the following, which is similar to Peter's code, to "Restart" a
service:

Dim controller As New ServiceController("Themes")
controller.Stop()
controller.WaitForStatus(ServiceControllerStatus.Stopped)
controller.Start()

Note the WaitForStatus waits until the service has come to a complete halt
before starting it again.

Hope this helps
Jay
 

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