In Windows, sometimes a service may become unresponsive or stuck and not be stopped using the usual net stop or Task Manager methods. In such cases, you can force kill the service using the taskkill command. This tutorial will guide you through the process of force killing a service on Windows.
In our AWS windows server, the Amazon SSM Agent service was hung during the startup. The service status kept showing starting always.
Now the only option available to forcefully kill this service by the process id on the Windows system. Below instructions will help you with it.
- 1. Find the Service name – Right-click on the service and open properties. Here you will find the service name under the General tab. For example, view the below screenshot.
In my case the service name is AmazonSSMAgent
- 2. Find the PID – Then execute the below command with the service name identified above.
sc queryex [servicename]
This will show you the service details on the console as below.
- 3. Kill Process by PID – Find out the service’s PID (process id) and force kill process by using the below command. Use pid number found with the previous command.
taskkill /f /pid <PID>
with the actual Process ID of the service you want to force kill.
All done. You can now start your service now.
Force killing a service using the taskkill command is a quick and effective way to stop unresponsive or stuck services on Windows. However, it should be used as a last resort, as it can result in data loss or other issues if incorrectly used. Always save any important data before attempting to force kill a service, and use this method only if other methods have failed to stop the service.