How to prevent error message when AppPool is already stopped
Asked Answered
E

2

12

I am running the following cmd on my MSBuild using PsEXEC.

%systemroot%\system32\inetsrv\appcmd stop apppool /apppool.name:MyAppPool

If the MyAppPool is already stopped, and try to stop again, I am getting error message.

ERROR ( message:Application pool "MyAppPool" already stopped.

This is stopping my build. How to handle this situation?

If MyAppPool is already started and issue a start again, no error message appears.

Efta answered 11/3, 2014 at 11:58 Comment(0)
P
6

You can try this: PsExec \\localhost cmd /c "%systemroot%\system32\inetsrv\appcmd list apppool /name:MyAppPool /state:Started /xml | %systemroot%\system32\i netsrv\appcmd stop apppool /in| exit 0"

Prostyle answered 11/3, 2014 at 12:8 Comment(3)
PsExec \\localhost %systemroot%\system32\inetsrv\appcmd list apppool /name:MyAppPool /state:Started /xml | %systemroot%\system32\inetsrv\appcmd stop apppool /in exited on SERVER with error code 1. Any idea?Efta
The command apparently sets the exit code (%errorlevel%) to 1 when it did nothing which affects psexec. try adding | set errorlevel=0 or exit 0Prostyle
Still getting the same exit code after adding "| exit 0" at the end. 'C:\Windows\system32\inetsrv\appcmd exited with error code 1.'Efta
S
16

Just add "| exit 0"

%systemroot%\system32\inetsrv\appcmd stop apppool /apppool.name:MyAppPool  | exit 0
Senghor answered 23/2, 2018 at 7:38 Comment(1)
It is very strange that only AppPool Stop throws error when it is already stopped. Stop Site, Start Site, Start AppPool can be called multiple times without error. Anyway this solution work for me perfectly. Thanks.Saprolite
P
6

You can try this: PsExec \\localhost cmd /c "%systemroot%\system32\inetsrv\appcmd list apppool /name:MyAppPool /state:Started /xml | %systemroot%\system32\i netsrv\appcmd stop apppool /in| exit 0"

Prostyle answered 11/3, 2014 at 12:8 Comment(3)
PsExec \\localhost %systemroot%\system32\inetsrv\appcmd list apppool /name:MyAppPool /state:Started /xml | %systemroot%\system32\inetsrv\appcmd stop apppool /in exited on SERVER with error code 1. Any idea?Efta
The command apparently sets the exit code (%errorlevel%) to 1 when it did nothing which affects psexec. try adding | set errorlevel=0 or exit 0Prostyle
Still getting the same exit code after adding "| exit 0" at the end. 'C:\Windows\system32\inetsrv\appcmd exited with error code 1.'Efta

© 2022 - 2025 — McMap. All rights reserved.