script to automatically force kill windows service with different PID each time.
I have a windows service that gets hung after a security scan. We have a long term fix but I need a short term fix.
The only way to fix is to reboot or force kill the service since it becomes grayed out after one fail and the attempt to restart.
It seems to run:
sc queryex "AppNAME"
taskkill /F /PID 4500
sc start "APPNAME"
This works while doing manually every time on the server since the PID changes.
How can I write a batch script that will fire off once it cannot restart 2/3 times?
How can the variable of the different PID each time be carried over to the taskkill?
Is there a better way to do this? PowerShell Script?
This is a Windows Server 2008R2 box and the longterm plan is I'm building a Server 2016 virtual machine to move application.