Unexpected status SERVICE_START_PENDING in response to START control - windows-services

When trying to restart an existing windows service via NSSM, I randomly get the below message which is written to the error log/error output. Any ideas on how to rectify? Ideally, accept as a valid response.
Unexpected status SERVICE_START_PENDING in response to START control

You will get "SERVICE_START_PENDING" if the the service takes too long to start (it means the service hasn't told Windows that it's started yet). "Too long" is up to the application issuing the start request. In the case of NSSM this appears to be very short, so if your system is under load the service is taking longer to start than NSSM expects.
There appears to be no way to tell NSSM how long a start or stop operation should take. For stop requests it even ignores its own shutdown timeout settings. Your option then for using NSSM is to compile from source and add a timeout option. Otherwise use a different tool, e.g. net:
net stop <service>
net start <service>

I believe that this issue was caused by the service itself.
It is highly probable that the service has bug and hang, fail, or take too much time to stop properly. Which raise issue when try to start it.
If the service fail:
In my opinion, there is a potential workaround,by setting up a service recovery option in the service properties. Then select "Run a program" when the service failed.
Then code a batch to get the PID of this service and kill it, then use NSSM to start it again.
In this batch you may use "SC query" command to check the service status:
C:\Windows>sc query "MyService" | find "STATE"
STATE : 3 STOP_PENDING
Note that if you use NSSM only to hide the windows, you may achieve the same goal with the Task Scheduler only.
In the "General" tab on task property. If you select "Run whether user is logged on or not", this will run from session 0 which won't show any window to you.
Then what you need to do on your scheduled task are, to kill / restart the target process itself as you do now. This will work more robustly.
If the service is not an official windows service but more an EXE program file (dev on your side) then converted to a services with NSSM, there is a high chance of failure.
It could be better to rewrite/recompile the program as an actual Windows service.

The problem is that NSSM is timing out waiting for your service to start. Unfortunately it does not seem to be possible to provide NSSM with a custom timespan for the service start-up timeout.
One workaround is still use NSSM to install the service, but then use PowerShell to start and stop the service. PowerShell allows you to specify your own wait timeout (since you probably don't want your script to wait indefinitely).
$serviceName = 'My service'
$service = Get-Service $serviceName -ErrorAction Ignore
Write-Verbose "Starting service '$serviceName'."
$service.Start()
$waitTimeout = New-TimeSpan -Seconds 5
$service.WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Running, $waitTimeout)
You can read more about the PowerShell Get-Service command here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-service

Recently happened to me... not only I cannot restart the service but also stop it is not possible neither.
Lets kill it.
Identify the process id (PID). Replace [SERVICE-NAME] with your service's name.
sc queryex "[SERVICE-NAME]"
You should get something like this:
SERVICE_NAME: xxxxxxxxx
TYPE : 30 WIN32
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 4812
FLAGS :
Manually kill the process. Replace [PID] with the value from the previous step.
taskkill /pid [PID] /f
This error is also related to
Windows could not stop the [SERVICE-NAME] service on Local Computer.
Error 1053: The service did not respond to the start or control
request in a timely fashion.

Related

Could not start REST http interface listener. The requested port may already be in use.

Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.
Kill node.exe using below steps :
Open command prompt and issue taskkill /F /IM node.exe
Rerun the test
Or you can simply kill Node.js process from Task Manager.

Windows Service Install Ends in Rollback

When I try to install a Windows service:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil
I get, what looks to be, some success messages and some failure messages. Part way down:
An exception occurred during the Install phase.
System.ComponentModel.Win32Exception: The specified service has been marked for deletion
At the end:
The Rollback phase completed successfully.
The transacted install has completed.
The installation failed, and the rollback has been performed.
The service is given an entry in the Services applet, but it is marked as "Disabled". When I attempt to change it to another state, I get a "marked for deletion" error message.
There are no messages in the Event Log. There is nothing useful in the log file created by installutil.exe (I believe it's written to the current working directory).
I have no direction to go with this. What do I do?
It turns out that the install might, or probably will, fail if that service is highlighted in the Services applet. It's safest to just close the Services applet, install the service, and then re-open the Services applet. It's really stupid.
Also, make sure to run the console as admin.
I experienced the same and the issue for me was that a service with the same name was already installed. So in order to install the new service I had to uninstall the older services. I am learning how to create and setup windows services and thus the naming conflicting. Tried uninstalling the service first through:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil -u servicename.exe
Once this statement executes successfully, install your service and it should succeed without any rollbacks.
Right Click on Command Prompt and choose RUN AS ADMINISTRATOR
Then copy and paste in: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe C:\TestService\bin\Debug\TestService.exe
Result in TestService.InstallLog is:
Installing service TestService...
Service TestService has been successfully installed.
Some times this happens due to permission issues.
Run the "Developer Command Prompt for VS 2012" as Administrator.
Then it will work.
Adding few more check's and points to solve this above issue.
Build service in release mode and take release folder files and kept in different path
Copy that path and go to visual studio command prompt window and run this bellow sample command to install the service.
Please close services.msc window if its opened , then run C:Program Files (x86)\Microsoft Visual Studio 11.0>InstallUtil.exe C:\RunLocationServices\TestService.exe
Go services.msc and select that service and click on start ,if it changed to "started" then your service running fine.
Still if issue exists then
Another Checkpoint & SOLUTION
When a service starts, the service communicates to the Service Control Manager how long the service must have to start (the time-out period for the service).
If the Service Control Manager does not receive a "service started" notice from the service within this time-out period,
the Service Control Manager terminates the process that hosts the service.
This time-out period is typically less than 30 seconds.
If you do not adjust this time-out period, the Service Control Manager ends the process.
To adjust this time-out period, follow these steps:
1.Go to Start > Run > and type regedit
2.Navigate to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
With the control folder selected, right click in the pane on the right and select new DWORD Value
3.Name the new DWORD: ServicesPipeTimeout
4.Right-click ServicesPipeTimeout, and then click Modify
Click Decimal, type '180000', and then click OK
5.Restart the computer
Still if issue exists then problem in your service code ,infinate loop may occur due to your methods/classes of service calling. Do code review of each line.
This problem is due to security, you'd better open developer command prompt for VS 2012:
RUN AS ADMINISTRATOR
and install your service. It will surely fix your problem.
I tried and the issue was resolved.

HTTP The service is starting or stopping. Please try again later error on windows 7

I used following command to stop the HTTP service
net stop http /y
And I got following error message:
The service is starting or stopping. Please try again later.
Now the HTTP service is in a in-between state. Its neither stopped nor starting. What should i do?
I read some similar issues but they are not helping.
Can't stop IIS in windows 7
You should be able to kill it via the Task Manager.
Right-click on taskbar -> Start Task Manager Go to Process tab
If you can find the service under the Processes tab:
Right click and select "End Process"
If you don't see it under Processes (or don't know which is the process for the service you want to kill),
While on the Processes tab
Check "Show processes from all users" in the lower left
Then "View" menu and choose "Select Columns"
Check "PID" and hit OK
Go to the services tab to find the PID of the service you want to kill
Go back to Processes tab and Right-click -> End Processstrong text
Copied the answer from the https://superuser.com/questions/489949/force-windows-7-service-to-stop
and it worked for me.
There are probably some processes that have open handles to \Device\Http\*.
You need close these handles or processes (e.g. in Process Explorer) to let the HTTP service stop.
I did this (on Windows 10) and can be done on Windows 7 (see below):
Turn on the windows feature the IIS Management Console.
Windows search for "IIS Manager"
From the Manage Server Menu on the right, select "Stop"
it worked. (e.g. free up the port 80 )
I checked that the same can be done on Windows 7 : https://learn.microsoft.com/en-us/iis/install/installing-iis-7/installing-iis-on-windows-vista-and-windows-7
What worked for me (I am using Windows 10):
Restarted the PC - It reset the "starting and stopping state" and started Http service - Irrespective of OS worth trying
Opened command prompt in the administrator mode
Http Service is running by default, can check using command -> Net Start HTTP
Run command -> Net Stop HTTP
Following message is displayed
The following services depend on the HTTP Service service.
Stopping the HTTP Service service also stops these services.
WWW Publishing Service
W3C Logging Service
SSDP search
Feature Search Resource Release
Function Search Provider Host
Upon entering 'Y', HTTP Service stops

How to restart service using command prompt?

I want to restart Windows service using command prompt in [Icons] section using Inno Setup. Please help me to solve the problem.
You can use sc start [service] to start a service and sc stop [service] to stop it. With some services net start [service] is doing the same.
But if you want to use it in the same batch, be aware that sc stop won't wait for the service to be stopped. In this case you have to use net stop [service] followed by net start [service]. This will be executed synchronously.
You could create a .bat-file with following content:
net stop "my service name"
net start "my service name"
net.exe stop "servicename" && net.exe start "servicename"
To restart a running service:
net stop "service name" && net start "service name"
However, if you don't know if the service is running in the first place and want to restart or start it, use this:
net stop "service name" & net start "service name"
This works if the service is already running or not.
For reference, here is the documentation on conditional processing symbols.
This is my code, to start/stop a Windows service using SC command. If the service fails to start/stop, it will print a log info. You can try it by Inno Setup.
{ start a service }
Exec(ExpandConstant('{cmd}'), '/C sc start ServiceName', '',
SW_HIDE, ewWaitUntilTerminated, ResultCode);
Log('sc start ServiceName:'+SysErrorMessage(ResultCode));
{ stop a service }
Exec(ExpandConstant('{cmd}'), '/C sc stop ServiceName', '',
SW_HIDE, ewWaitUntilTerminated, ResultCode);
Log('sc stop ServiceName:'+SysErrorMessage(ResultCode));
You can start and stop and query services using the SC command. As for innosetup i'm not sure.
PowerShell features a Restart-Service cmdlet, which either starts or restarts the service as appropriate.
The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service. If a service was already stopped, it is started without notifying you of an error.
You can specify the services by their service names or display names, or you can use the InputObject parameter to pass an object that represents each service that you want to restart.
It is a little more foolproof than running two separate commands.
The easiest way to use it just pass either the service name or the display name directly:
Restart-Service 'Service Name'
It can be used directly from the standard cmd prompt with a command like:
powershell -command "Restart-Service 'Service Name'"

Stopping a windows service when the stop option is grayed out

I have created a windows service and in the service in control panel -> administrative tools -> services, its status is starting.
I want to stop this service, but the stop option is grayed out.
How can I start/stop the service?
Every time I restart, then it becomes stopped and I can delete it.
If you run the command:
sc queryex <service name>
where is the the name of the service, not the display name (spooler, not Print Spooler), at the cmd prompt it will return the PID of the process the service is running as. Take that PID and run
taskkill /F /PID <Service PID>
to force the PID to stop. Sometimes if the process hangs while stopping the GUI won't let you do anything with the service.
You could do it in one line (useful for ci-environments):
taskkill /fi "Services eq SERVICE_NAME" /F
Filter -> Services -> ServiceName equals SERVICE_NAMES -> Force
Source: https://technet.microsoft.com/en-us/library/bb491009.aspx
If the stop option is greyed out then your service did not indicate that it was accepting SERVICE_ACCEPT_STOP when it last called SetServiceStatus. If you're using .NET, then you need to set the CanStop property in ServiceBase.
Of course, if you're accepting stop requests, then you'd better make sure that your service can safely handle those requests, especially if your service is still progressing through its startup code.
As Aaron mentioned above, some services do not accept SERVICE_ACCEPT_STOP messages, by the time it was developed. And that is hard coded into the executable. Period. A workaroud would be not to have it started, and as you cannot change its properties, forcibly do the following:
Boot into safe mode (Windows 10 users might need msconfig > boot > safe boot)
Regedit into HKLM > System > ControlSet001 > Services
Locate your service entry
Change 'Start' key to 3 (manual startup) or 4 (disabled)
If you cannot change the entry, right-click on your service name on the left pane, select 'Permissions', check that 'Everyone' has full access and try step 4 again.
Don't forget to disable safe boot from msconfig again, and reboot !
Open command prompt with admin access and type the following commands there .
a)
tasklist
it displays list of all available services . There you can see the service you want to stop/start/restart . Remember PID value of the service you want to force stop.
b) Now type
taskkill /f /PID [PID value of the service]
and press enter. On success you will get the message
“SUCCESS: The process with PID has been terminated”.
Ex : taskkill /f /PID 5088
This will forcibly kill the frozen service. You can now return to Server Manager and restart the service.
sc queryex <service name>
taskkill /F /PID <Service PID>
eg
I solved the problem with the following steps:
Open "services.msc" from command / Windows RUN.
Find the service (which is greyed out).
Double click on that service and go to the "Recovery" tab.
Ensure that
First Failure action is selected as "Take No action".
Second Failure action is selected as "Take No action".
Subsequent Failures action is selected as "Take No action".
and Press OK.
Now, the service will not try to restart and you can able to delete the greyed out service from services list (i.e. greyed out will be gone).
Here's a simple method to kill a service you can't stop directly, if that service has dependencies.
Open the service's properties window & click on dependencies tab
See what it needs to run
Stop one of those if possible, being sure that it won't also crash Windows
For example, stopping "network store interface service" aka nsi will kill an unkillable dnscache service. It will also kill all network capabilities & may require restarting Windows to get them back. I've had to do this to edit the hosts file, sometimes dnscache refuses to let go & you can't update hosts without killing it first but you can't do it directly.
The crucial thing that a lot of the suggestions dont make clear is that you must 'start command window as administrator' even if your already logged in as an administrator.

Resources