How to: Pause a Windows Service (Visual Basic)

This example uses the ServiceController component to pause the IIS Admin service on the local computer.

Dim theController As System.ServiceProcess.ServiceController
theController = New System.ServiceProcess.ServiceController("IISAdmin")


' Pauses the service.

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.

This example requires:

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.

The following conditions may cause an exception:

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft