Tom Brix
Tom Brix

Reputation: 1

Powershell New Service Failing To Start or Manually Run: Error 1053

I created a new service in Powershell (as administrator) PSVersion 5.1.17763.1007. The new service exists, but fails to run in either Powershell or Services.

In Powershell:

PS C:\Windows\system32> Get-Service ztest|Start-Service

Start-Service : Service 'ztest (zTest)' cannot be started due to the following error: Cannot start service zTest on computer '.'. At line:1 char:19 + Get-Service ztest|Start-Service \ ~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand

In Services: I receive a 1053 error The service did not respond to the start or control request in a timely fashion.

What Has Been Done: I used a powershell script that I have converted to a .exe file via Win-PS2Exe. When I run the .exe file, the program works as expected.

Creating New Service: New-Service -Name zTest1 -BinaryPathName $filepath -DisplayName zTest1 -Description $description -StartupType Automatic -Credential $cred

I have changed Timeout settings in Regedit, added both files and folders to trusted locations, granted ownership and full access to the service account for .exe files and folders, I have written PS Scripts and converted it to a .exe (Win-PS2Exe) powershell.exe -executionpolicy bypass -file 'C:\users\...\desktop\RunTESTNoCommentsReview.exe'

About the .exe file: The .exe file does not end. It is in an infinite while loop pausing 1 minute at a time.

I have read people saying potential issues with the name not being what it is expected to be in Windows Service Manager, but I couldn't find any additional documentation past their comments.

My Machine: I am currently running Windows Server 2019 Standard that is up to date.

I am unsure if I am supposed to register the service somewhere, or what else I could be missing.

Upvotes: 0

Views: 2716

Answers (1)

postanote
postanote

Reputation: 16096

Continuing from my comment.

You are not showing any of your code that you say is being used as your service.

There are many examples of how to do this all over the web.

For Example:

$serviceName = "MyService"

if (Get-Service $serviceName -ErrorAction SilentlyContinue)
{
    $serviceToRemove = Get-WmiObject -Class Win32_Service -Filter "name='$serviceName'"
    $serviceToRemove.delete()
    "service removed"
}
else
{
    "service does not exists"
}

"installing service"

$secpasswd = ConvertTo-SecureString "MyPassword" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (".\MYUser", $secpasswd)
$binaryPath = "c:\servicebinaries\MyService.exe"
New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic -credential $mycreds

"installation completed"

So, without MRE stuff like the above, you force us to assume.

Upvotes: 1

Related Questions