I am trying to create windows service with below code
$params = @{
Name = "abc"
BinaryPathName = "C:\Users\dell\Downloads\abinstall\abc.exe"
DisplayName = "Windows Service"
StartupType = "Automatic"
Description = "This is a service."
}
New-Service @params
When i try to run above script i get an output like this
Start-Service : Service 'Windows Service (abc)' cannot be started due to the following error: Cannot start
service abc on computer '.'.
At C:\Users\dell\Downloads\abinstall\start.ps1:14 char:4
+ Start-Service -Name "abc"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand
I am running this in administrator powershell.
PS C:\Users\Public\k2agent-bkp> Get-CimInstance win32_service | Where-Object Name -eq "abc"
ProcessId Name StartMode State Status ExitCode
--------- ---- --------- ----- ------ --------
0 abc Auto Stopped OK 0
I have tried restarting computer after deleting the service.
I am running this on windows 10 workstation.
abc.exe is wrapper over java jar.
Can anyone help me with this ?
Thanks in advance.