Microsoft windows start service

Start or stop Windows service from command line (CMD)

We normally use Services.msc to start or stop or disable or enable any service. We can do the same from windows command line also using net and sc utilities. Below are commands for controlling the operation of a service.

Command to stop a service:

To start a service:

You need to have administrator privileges to run net start/stop commands. If you are just a normal user on the computer, you would get an error like below.

To disable a service:

To enable a service:

To make a service start automatically with system boot:

Note: Space is mandatory after ‘=’ in the above sc commands.

This SC command works on a Windows 7 machine and also on the down-level editions of Windows i.e Windows XP/2003 and Windows Vista. Again, if you do not have administrator previliges you would get the below error.

Note that the service name is not the display name of a service. Each service is given a unique identification name which can be used with net or sc commands. For example, Remote procedure call (RPC) is the display name of the service. But the service name we need to use in the above commands is RpcSs.
So to start Remote procedure call service the command is:

These service names are listed below for each service. The first column shows the display name of a service and the second column shows the service name that should be used in net start or net stop or sc config commands.

Start-Service

Starts one or more stopped services.

Syntax

Description

The Start-Service cmdlet sends a start message to the Windows Service Controller for each of the specified services. If a service is already running, the message is ignored without error. You can specify the services by their service names or display names, or you can use the InputObject parameter to supply a service object that represents the services that you want to start.

Examples

Example 1: Start a service by using its name

This example starts the EventLog service on the local computer. The Name parameter identifies the service by its service name.

Example 2: Display information without starting a service

This example shows what would occur if you started the services that have a display name that includes «remote».

The DisplayName parameter identifies the services by their display name instead of their service name. The WhatIf parameter causes the cmdlet to display what would happen when you run the command but does not make changes.

Example 3: Start a service and record the action in a text file

This example starts the Windows Management Instrumentation (WMI) service on the computer and adds a record of the action to the services.txt file.

First we use Get-Service to get an object that represent the WMI service and store it in the $s variable. Next, we start the service. Without the PassThru parameter, Start-Service does not create any output. The pipeline operator (|) passes the object output by Start-Service to the Format-List cmdlet to format the object as a list of its properties. The append redirection operator (>>) redirects the output to the services.txt file. The output is added to the end of the existing file.

Example 4: Start a disabled service

This example shows how to start a service when the start type of the service is Disabled.

Читайте также:  Добавить драйвер принтера linux

The first attempt to start the Telnet service (tlntsvr) fails. The Get-CimInstance command shows that the StartMode property of the Tlntsvr service is Disabled. The Set-Service cmdlet changes the start type to Manual. Now, we can resubmit the Start-Service command. This time, the command succeeds. To verify that the command succeeded, run Get-Service .

Parameters

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Aliases: cf
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

Specifies the display names of the services to start. Wildcard characters are permitted.

Type: String [ ]
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

Specifies services that this cmdlet omits. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as s* . Wildcard characters are permitted.

Type: String [ ]
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

Specifies services that this cmdlet starts. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as s* . Wildcard characters are permitted.

Type: String [ ]
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: True

Specifies ServiceController objects representing the services to be started. Enter a variable that contains the objects, or type a command or expression that gets the objects.

Type: ServiceController [ ]
Position: 0
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Specifies the service names for the service to be started.

The parameter name is optional. You can use Name or its alias, ServiceName, or you can omit the parameter name.

Type: String [ ]
Aliases: ServiceName
Position: 0
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

Returns an object that represents the service. By default, this cmdlet does not generate any output.

Type: SwitchParameter
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Aliases: wi
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

Inputs

System.ServiceProcess.ServiceController, System.String

You can pipe objects that represent the services or strings that contain the service names to this cmdlet.

Outputs

None, System.ServiceProcess.ServiceController

This cmdlet generates a System.ServiceProcess.ServiceController object that represents the service, if you specify PassThru. Otherwise, this cmdlet does not generate any output.

Notes

This cmdlet is only available on Windows platforms.

  • You can also refer to Start-Service by its built-in alias, sasv . For more information, see about_Aliases.
  • Start-Service can control services only if the current user has permission to do this. If a command does not work correctly, you might not have the required permissions.
  • To find the service names and display names of the services on your system, type Get-Service . The service names appear in the Name column, and the display names appear in the DisplayName column.
  • You can start only the services that have a start type of Manual, Automatic, or Automatic (Delayed Start). You cannot start the services that have a start type of Disabled. If a Start-Service command fails with the message Cannot start service \ on computer , use Get-CimInstance to find the start type of the service and, if you have to, use the Set-Service cmdlet to change the start type of the service.
  • Some services, such as Performance Logs and Alerts (SysmonLog) stop automatically if they have no work to do. When PowerShell starts a service that stops itself almost immediately, it displays the following message: Service \ start failed.

How to: Start Services

After a service is installed, it must be started. Starting calls the OnStart method on the service class. Usually, the OnStart method defines the useful work the service will perform. After a service starts, it remains active until it is manually paused or stopped.

Services can be set up to start automatically or manually. A service that starts automatically will be started when the computer on which it is installed is rebooted or first turned on. A user must start a service that starts manually.

By default, services created with Visual Studio are set to start manually.

Читайте также:  Yandex music linux client

There are several ways you can manually start a service — from Server Explorer, from the Services Control Manager, or from code using a component called the ServiceController.

You set the StartType property on the ServiceInstaller class to determine whether a service should be started manually or automatically.

Specify how a service should start

After creating your service, add the necessary installers for it. For more information, see How to: Add Installers to Your Service Application.

In the designer, click the service installer for the service you are working with.

In the Properties window, set the StartType property to one of the following:

To have your service install Set this value
When the computer is restarted Automatic
When an explicit user action starts the service Manual

To prevent your service from being started at all, you can set the StartType property to Disabled. You might do this if you are going to reboot a server several times and want to save time by preventing the services that would normally start from starting up.

These and other properties can be changed after your service is installed.

There are several ways you can start a service that has its StartType process set to Manual — from Server Explorer, from the Windows Services Control Manager, or from code. It is important to note that not all of these methods actually start the service in the context of the Services Control Manager; Server Explorer and programmatic methods of starting the service actually manipulate the controller.

Start a service from Server Explorer

In Server Explorer, add the server you want if it is not already listed. For more information, see How to: Access and Initialize Server Explorer-Database Explorer.

Expand the Services node, and then locate the service you want to start.

Right-click the name of the service, and then select Start.

Start a service from Services

Open the Services app.

Select your service in the list, right-click it, and then select Start.

Start a service from code

Create an instance of the ServiceController class, and configure it to interact with the service you want to administer.

Call the Start method to start the service.

Практическое руководство. Запуск служб How to: Start Services

Установленную службу необходимо запустить. After a service is installed, it must be started. Процедура запуска вызывает метод OnStart в классе службы. Starting calls the OnStart method on the service class. Как правило, метод OnStart определяет полезные действия, которые будет выполнять служба. Usually, the OnStart method defines the useful work the service will perform. Запущенная служба остается активной, пока не будет приостановлена или остановлена вручную. After a service starts, it remains active until it is manually paused or stopped.

Службы можно настроить на запуск автоматически или вручную. Services can be set up to start automatically or manually. Служба, которая запускается автоматически, будет запущена при первом включении или перезагрузке компьютера, на котором она установлена. A service that starts automatically will be started when the computer on which it is installed is rebooted or first turned on. Службу, которая запускается вручную, должен запустить пользователь. A user must start a service that starts manually.

По умолчанию службы, созданные с помощью Visual Studio, настроены на запуск вручную. By default, services created with Visual Studio are set to start manually.

Есть несколько способов запуска службы вручную: из диспетчера служб или обозревателя сервера либо из кода, используя компонент, который называется ServiceController. There are several ways you can manually start a service — from Server Explorer, from the Services Control Manager, or from code using a component called the ServiceController.

Вы можете задать свойство StartType в классе ServiceInstaller, чтобы определить способ запуска службы — вручную или автоматически. You set the StartType property on the ServiceInstaller class to determine whether a service should be started manually or automatically.

Настройка способа запуска службы To specify how a service should start

Создав службу, добавьте для нее необходимые установщики. After creating your service, add the necessary installers for it. Дополнительные сведения см. в разделе Практическое руководство. Добавление установщиков в приложение-службу. For more information, see How to: Add Installers to Your Service Application.

В конструкторе щелкните установщик процессов службы, с которой вы работаете. In the designer, click the service installer for the service you are working with.

В окне свойств задайте свойству StartType одно из следующих значений: In the Properties window, set the StartType property to one of the following:

Чтобы установить службу To have your service install Задайте это значение Set this value
При перезапуске компьютера When the computer is restarted Автоматический Automatic
При запуске службы с помощью явного действия пользователя When an explicit user action starts the service Manual (Вручную) Manual

Чтобы полностью запретить запуск службы, можно задать свойству StartType значение Disabled (Отключено). To prevent your service from being started at all, you can set the StartType property to Disabled. Это можно сделать, если вы собираетесь перезагружать сервер несколько раз и хотите сэкономить время, запретив запуск служб, которые обычно запускаются одновременно. You might do this if you are going to reboot a server several times and want to save time by preventing the services that would normally start from starting up.

Эти и другие свойства можно изменить после установки службы. These and other properties can be changed after your service is installed.

Есть несколько способов запуска службы, для процесса StartType которой настроено значение Manual (Вручную): из диспетчера служб или обозревателя серверов либо из кода. There are several ways you can start a service that has its StartType process set to Manual — from Server Explorer, from the Windows Services Control Manager, or from code. Важно отметить, что в действительности не все эти методы приводят к запуску службы в контексте диспетчера служб. При использовании обозревателя сервера и программных способов применяется контроллер. It is important to note that not all of these methods actually start the service in the context of the Services Control Manager; Server Explorer and programmatic methods of starting the service actually manipulate the controller.

Запуск службы вручную из обозревателя сервера To manually start a service from Server Explorer

В обозревателе сервера добавьте нужный сервер, если его нет в списке. In Server Explorer, add the server you want if it is not already listed. Дополнительные сведения см. в разделах «Практическое руководство. Подключение и инициализация обозревателя серверов или обозревателя баз данных». For more information, see How to: Access and Initialize Server Explorer-Database Explorer.

Разверните узел Службы и выберите службу, которую нужно запустить. Expand the Services node, and then locate the service you want to start.

Щелкните службу правой кнопкой мыши и выберите команду Запустить. Right-click the name of the service, and click Start.

Запуск службы вручную из диспетчера служб To manually start a service from Services Control Manager

Откройте диспетчер служб, сделав следующее: Open the Services Control Manager by doing one of the following:

В Windows XP и 2000 Professional щелкните правой кнопкой мыши значок Мой компьютер на рабочем столе и выберите Управление. In Windows XP and 2000 Professional, right-click My Computer on the desktop, and then click Manage. В открывшемся диалоговом окне разверните узел Службы и приложения. In the dialog box that appears, expand the Services and Applications node.

В Windows Server 2003 и Windows 2000 Server нажмите кнопку Пуск, выберите Программы, Администрирование и Службы. In Windows Server 2003 and Windows 2000 Server, click Start, point to Programs, click Administrative Tools, and then click Services.

В Windows NT версии 4.0 можно открыть это диалоговое окно на панели управления. In Windows NT version 4.0, you can open this dialog box from Control Panel.

Теперь ваша служба должна отобразиться в списке Службы. You should now see your service listed in the Services section of the window.

Выберите службу в списке, щелкните ее правой кнопкой мыши и нажмите кнопку Запустить. Select your service in the list, right-click it, and then click Start.

Запуск службы вручную из кода To manually start a service from code

Создайте экземпляр класса ServiceController и настройте его для взаимодействия со службой, которой нужно управлять. Create an instance of the ServiceController class, and configure it to interact with the service you want to administer.

Чтобы запустить службу, вызовите метод Start. Call the Start method to start the service.

Читайте также:  Микрофон настройка linux mint
Оцените статью