Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Initialisiert eine neue Instanz der ServiceController-Klasse, die keinem bestimmten Dienst zugeordnet ist.
Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in system.serviceprocess.dll)
Syntax
'Declaration
Public Sub New
'Usage
Dim instance As New ServiceController
public ServiceController ()
public:
ServiceController ()
public ServiceController ()
public function ServiceController ()
Beispiel
Im folgenden Beispiel wird mithilfe der ServiceController-Klasse überprüft, ob der Warndienst beendet wurde. Im Beispiel wird der Dienst gestartet, sofern er beendet wurde, und es wird gewartet, bis der Dienststatus auf Running festgelegt ist.
' Check whether the Alerter service is started.
Dim sc As New ServiceController()
sc.ServiceName = "Alerter"
Console.WriteLine("The Alerter service status is currently set to {0}", sc.Status)
If sc.Status = ServiceControllerStatus.Stopped Then
' 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
Console.WriteLine("Could not start the Alerter service.")
End Try
End If
// Check whether the Alerter service is started.
ServiceController sc = new ServiceController();
sc.ServiceName = "Alerter";
Console.WriteLine("The Alerter service status is currently set to {0}",
sc.Status.ToString());
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.ToString());
}
catch (InvalidOperationException)
{
Console.WriteLine("Could not start the Alerter service.");
}
}
// 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." );
}
}
}
// Check whether the Alerter service is started.
ServiceController sc = new ServiceController();
sc.set_ServiceName("Alerter");
Console.WriteLine("The Alerter service status is currently set to {0}",
sc.get_Status().ToString());
if (sc.get_Status().Equals(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.get_Status().ToString());
}
catch (InvalidOperationException exp) {
Console.WriteLine("Could not start the Alerter service.");
}
}
.NET Framework-Sicherheit
- Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter .
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ServiceController-Klasse
ServiceController-Member
System.ServiceProcess-Namespace