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.

embert
  • 7,336
  • 10
  • 49
  • 78
teenboy
  • 368
  • 2
  • 12

2 Answers2

15

Just add "| exit 0"

%systemroot%\system32\inetsrv\appcmd stop apppool /apppool.name:MyAppPool  | exit 0
Pavel
  • 524
  • 4
  • 8
  • 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. – Major May 18 '18 at 07:43
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"

Boklucius
  • 1,896
  • 17
  • 19
  • 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? – teenboy Mar 11 '14 at 14:27
  • The command apparently sets the exit code (%errorlevel%) to 1 when it did nothing which affects psexec. try adding `| set errorlevel=0` or `exit 0` – Boklucius Mar 11 '14 at 14:33
  • Still getting the same exit code after adding "| exit 0" at the end. 'C:\Windows\system32\inetsrv\appcmd exited with error code 1.' – teenboy Mar 11 '14 at 14:48