Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot start service on computer '.'

Tags:

powershell

I'm trying to create and start a windows service using PowerShell.

The service is created but cannot be started when I use various names besides one particular name.

When I create the service with the name of the exe file it can be started but when I give it a different name it fails to start.

I'm running the PowerShell script as administrator.

Any advises?

function InstallService(
    [string] $MsDeployHost,
    [string] $ServiceName,
    [string] $DisplayName,
    [string] $ServicePath,
    [string] $ServiceDescription,
    [object] $Credential) {
    if($MsDeployHost -eq "local") {        
        New-Service -name $ServiceName -binaryPathName $ServicePath -displayName $ServiceName -StartupType Automatic
        Start-Service -name $ServiceName
    } else { ....  

The Error I get: Start-Service : Service 'Service1 (Service1)' cannot be started due to the following error: Cannot start service Service1 on computer '.'.

When I try to start it manually I get: "Error 1053: The service did not respond to the start or control request in a timely fashion"

like image 705
Itai Mo Avatar asked Jun 06 '16 06:06

Itai Mo


People also ask

How do I force a service to start?

Start service Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to start a service and press Enter: net start "SERVICE-NAME" In the command, replace "SERVICE-NAME" for the name or display name of the service.

How do I start a local computer service?

Right click in the service in Window Services and go to Properties. Then go to Log On tab and select Local System account. Click on Ok button and start the service.


Video Answer


2 Answers

The problem is that, unless your service is written to handle it, you need to use a particular service name in order to run a particular service (and note that the name is case-sensitive). This is because the service, on startup, needs to register with the Service Control Manager to receive start/stop notifications and send status updates, using its service name. If you install the service with a different name, but the executable has no way of knowing this (through a configuration setting or whatnot), this registration will fail and the service can't start (to the operating system, it will look as if the service is failing to respond).

You can set the display name to whatever you like, but you cannot use an arbitrary service name unless the service is designed to support this.

like image 194
Jeroen Mostert Avatar answered Oct 01 '22 22:10

Jeroen Mostert


My problem was that the service was Disabled in the services control manager.

I then put it in manual state and Start-Service worked.

hth

like image 40
Boop Avatar answered Oct 01 '22 21:10

Boop