'Cannot start service on computer '.'
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"
Solution 1:[1]
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.
Solution 2:[2]
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
Solution 3:[3]
I had the same problem, for me the issue was that the service was supposed to run with a user's credentials and the user's password has changed - after which the service could not log in anymore and failed to run.
You can review the "Service Control Manager" log, immediately after the failure, like this:
> Get-EventLog -LogName System -Source 'Service Control Manager' -Newest 5
----- ---- --------- ------ ---------- -------
19762 Sep 30 12:31 Error Service Control M... 3221232472 The SERVICE_NAME service failed to start due to the following error: ...
19761 Sep 30 12:31 Error Service Control M... 3221232510 The SERVICE_NAME service was unable to log on as .\USERNAME with the currently configured password due to the following error: ...
#...
> (Get-EventLog -LogName System -Source 'Service Control Manager' -Newest 5)[1] | Format-List
Index : 19764
EntryType : Error
InstanceId : 3221232510
Message : The SERVICE_NAME service was unable to log on as .\USERNAME with the currently configured password due to the following error:
%%1326
To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).
Category : (0)
CategoryNumber : 0
ReplacementStrings : {SERVICE_NAME, .\USERNAME, %%1326}
Source : Service Control Manager
TimeGenerated : 9/30/2021 12:35:02 PM
TimeWritten : 9/30/2021 12:35:02 PM
UserName :
Error 1326 is "Bad username or password".
Solution 4:[4]
If this is also a .NET Console Application, you must call ServiceBase.Run in your main method in Program.cs. This fixed this error for me.
See more specific code here: .NET console application as Windows service
Solution 5:[5]
For me it was an incorrect value in appsettings.json
. Did not escape some special characters.
Solution 6:[6]
This error message is very generic and does not say anything useful. The reason could be missing configuration files, missing .NET frameworks or anything that the program depends on.
To see the real reason open the Windows event log and look for any errors under Windows Logs -> Application.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Boop |
Solution 3 | Guss |
Solution 4 | AndyClaw |
Solution 5 | SLCH000 |
Solution 6 | Rye bread |