Stopping a windows service when the stop option is grayed out - windows-services

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.

Related

Can't disable/stop GbpSv Windows Service

I'm trying to set a windows process called "GbpSv" to disabled and although my user is administrator, all the commands are disabled.
Ex:
C:\Users\Andre>sc config "GbpSv" start=disabled
[SC] OpenService FAILED 5:
Access is denied.
C:\Users\Andre>net stop "GbpSv"
The requested pause, continue, or stop is not valid for this service
I'm using Windows 8.1.
Trying to kill the process:
C:\Program Files (x86)\GbPlugin>tasklist | FindStr Gbp
GbpSv.exe 104 Services 0 16.520 K
GbpSv.exe 5324 Console 1 13.448 K
C:\Program Files (x86)\GbPlugin>taskkill /pid 104
ERROR: The process with PID 104 could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
C:\Program Files (x86)\GbPlugin>taskkill /f /pid 104
ERROR: The process with PID 104 could not be terminated.
Reason: Access is denied.
You can't merely stop it like that. You'll have to purge it completely from your machine because it's a security plugin that some banks provide in order to secure your access to their internet banking services. Therefore it's very well protected from malicious removal by rogue apps.
Here's how you can remove it:
First you'll have to delete the Program files\Gbplugin folder. I deleted it by booting into Linux (you could use an Ubuntu live CD), mounting the Windows partition and deleting it. Logging in as a Windows administrator or into Secure Mode should do the trick as well.
But in order to get rid of the Gpb Service, Gbplugin and Warsaw (its companion app, written by "Gas Tecnologia"), you'll have to delete all of their entries on the Regedit. Just open regedit, press ctrl+f, look for "Gpb", "Gbplugin", "Gpbsv" and "Warsaw" and delete the entries. Be careful not to delete unrelated stuff!
You can uninstall Warsaw from the Control Panel. Make sure you delete the DLLs left on your local folder (you can easily find them with the Windows Explorer Search).
On the next reboot the service should be disabled.
If you don't uninstall it and delete the Regedit entries mentioned above, it will keep reinstalling Gpb silently over and over again. So leave no stone unturned.
Obs: To reboot into secure mode using Windows 8.1, hold the Shift key while choosing the restart option from the "Power Options".

Unexpected status SERVICE_START_PENDING in response to START control

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.

wont let me run rails s because there is another server running but i don't know how to access that server

How do I close the old server even though I can't see its terminal anymore so I can access my project?
I tried exiting out of the program then exiting back in but nothing would work.
keeps bringing up this error:
A server is already running. Check C:/Users/Nathan/Documents/Aptana Studio 3 Workspace/Nathans First project/tmp/pids/server.pid.
Exiting
Use netstat to find the process id running on the port the server has bound to. Then kill that process.
run cmd.exe as administrator.
To list process
C:\> netstat -a -b
Find the process id that is bound to the port your server runs on
C:\> Taskkill /PID <the process id (pid) of the server> /F
can you visit your app from the url 127.0.0.1:3000, 3000 is the port your app suppose to be running.
Case 1. if you can visit at the location, then use the activity monitor or something like that , find the ruby process and kill it.
Case 2. if you can not visit, then just delete the file C:/Users/Nathan/Documents/Aptana Studio 3 Workspace/Nathans First project/tmp/pids/server.pid will be fixed this problem. It is cause by a abnormal server exist like you shutdown your computer without shutdown the server normally.
Check you tmp/pids/server.pid file under your app which wil have the process id of other instance of rails server currently running. First kill that process using kill -9 process_id in your linux terminal. Check how to kill a process for your particular version
Delete the server.pid file in the C:/Users/Nathan/Documents/Aptana Studio 3 Workspace/Nathans First project/tmp/pids/ directory and restart the server.
Make sure you close the command prompt window and open it again before restarting the server.
Hope this helps!

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

Resources