How to: Continue a Windows Service (Visual Basic)
Warning
This documentation isn't for the latest version of Windows Service. For the latest content on Windows Services using BackgroundService and the Worker Service template, see:
This example uses the ServiceController component to continue the IIS Admin service on the local computer.
Example
Dim theController As System.ServiceProcess.ServiceController
theController = New System.ServiceProcess.ServiceController("IISAdmin")
' Checks that the service is paused.
If theController.Status =
System.ServiceProcess.ServiceControllerStatus.Paused Then
' Continues the service.
theController.Continue()
End If
This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Windows Operating System > Windows Services. For more information, see Code Snippets.
Compiling the Code
This example requires:
A project reference to System.serviceprocess.dll.
Access to the members of the System.ServiceProcess namespace. Add an
Imports
statement if you are not fully qualifying member names in your code. For more information, see Imports Statement (.NET Namespace and Type).
Robust Programming
The MachineName property of the ServiceController class is the local computer by default. To reference Windows services on another computer, change the MachineName property to the name of that computer.
You cannot call the Continue method on a service until the service controller status is Paused.
The following conditions may cause an exception:
The service cannot be resumed. (InvalidOperationException)
An error occurred when accessing a system API. (Win32Exception)
.NET Framework Security
Control of services on the computer may be restricted by using the ServiceControllerPermissionAccess enumeration to set permissions in the ServiceControllerPermission class.
Access to service information may be restricted by using the PermissionState enumeration to set permissions in the SecurityPermission class.
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for