Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
This article doesn't apply to hosted services in .NET. For the latest content on Windows services using Microsoft.Extensions.Hosting.BackgroundService and the Worker Service template, see:
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.
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 Code Snippets.
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).
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:
The service cannot be paused. (InvalidOperationException)
An error occurred when accessing a system API. (Win32Exception)
Control of services on the computer may be restricted by using the ServiceControllerPermissionAccess to set permissions in the ServiceControllerPermission.
Access to service information may be restricted by using the PermissionState to set permissions in the SecurityPermission.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Troubleshoot operating system service issues - Training
This module discusses the role of operating system services and how to troubleshoot issues that restrict functionality. This module also discusses resolving issues with signing in to Windows.