0

I have a below script which is attached to a windows service on stop command:-

wmic service where name='%NS_SERVICE_NAME%' get ProcessId | more +1 > tmp.txt
set /p NS_PID=<tmp.txt
del tmp.txt
for /f %%i in ('wmic process where "(ParentProcessId=%NS_PID%)" get ProcessId ^| more +1') do (
    for /f %%a in ('wmic process where "(ParentProcessId=%%i)" get ProcessId ^| more +1') do (
        echo %%a|findstr "^[-][1-9][0-9]*$ ^[1-9][0-9]*$ ^0$">nul && TASKKILL /F /PID %%a || rem
        IF %ERRORLEVEL% NEQ 0 do (
           exit
        )
    )
)

which works fine on Windows 7 and service stops quickly in 1-2 seconds, but in case of Windows Server 2012 the service does not stop and keeps in stopping state unless the process related to it is ended.

The error which I get in logs is as below:- "No Instance(s) Available."

Can some one help me in this regard.

3
  • what is service1 and service2 here ? Sep 14, 2016 at 12:15
  • get-service NameOfFirstService, NameOfSecondService | stop-service -force just the names of services
    – SimonS
    Sep 14, 2016 at 13:27
  • stopping the service uses the code mentioned above only, so no success. Sep 15, 2016 at 7:24

0

You must log in to answer this question.

Browse other questions tagged .