|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
How to: Pause a Windows Service (Visual Basic)
This example uses thecomponent 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. theController.Pause()
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.
Compiling the Code
This example requires:
A project reference to System.serviceprocess.dll.
Access to the members of thenamespace. Add an Imports statement if you are not fully qualifying member names in your code. For more information, see .
Theproperty 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: