ServiceController::Start Method ()
.NET Framework (current version)
Starts the service, passing no arguments.
Assembly: System.ServiceProcess (in System.ServiceProcess.dll)
| Exception | Condition |
|---|---|
| Win32Exception | An error occurred when accessing a system API. |
| InvalidOperationException | The service was not found. |
The following example uses the ServiceController class to check whether the Alerter service is stopped. If the service is stopped, the example starts the service and waits until the service status is set to Running.
// Check whether the Alerter service is started. ServiceController^ sc = gcnew ServiceController; if ( sc ) { sc->ServiceName = "Alerter"; Console::WriteLine( "The Alerter service status is currently set to {0}", sc->Status ); if ( sc->Status == (ServiceControllerStatus::Stopped) ) { // Start the service if the current status is stopped. Console::WriteLine( "Starting the Alerter service..." ); try { // Start the service, and wait until its status is "Running". sc->Start(); sc->WaitForStatus( ServiceControllerStatus::Running ); // Display the current service status. Console::WriteLine( "The Alerter service status is now set to {0}.", sc->Status ); } catch ( InvalidOperationException^ e ) { Console::WriteLine( "Could not start the Alerter service." ); } } }
ServiceControllerPermissionSecurityPermission
for controlling services on the computer. Associated enumeration: ServiceControllerPermissionAccess::Control
for unrestricted access to service information. Associated enumeration: PermissionState::Unrestricted
.NET Framework
Available since 1.1
Available since 1.1
Show: