I encountered a problem where I wanted to stop and start IIS by using either the command line or powershell versions of stopping and starting IIS.
NET STOP W3SVC
NET START W3SVC
Both of those stopped and started the World Wide Publishing service correctly. But both appeared to not stop/recycle the worker processes. With Net start and stop giving an error message when IIS was already stopped and/or started before running those commands, resulting in a scheduled task error code.
I found that using the IISRESET command, it does close those worker processes and when IIS was already stopped and/or started it didn’t return an error, thus resulting in the scheduled task returning a nice 0x0 (success)
Thus: use the following commands (also within powershell) if you want to stop/start IIS websites. This will always work as intended and not return an error code (in some cases, where the others would)
2 thoughts on “Net stop/start W3SVC and Stop/Start-Service W3SVC vs IISRESET STOP/START”
Thanks for the info. This change worked for me.
I know its an old post but stopping WAS should stop the worker processes and prevent the issue you mention while avoiding the use of iisreset.
At least thats how its officially recommended in https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc732317(v=ws.10)?redirectedfrom=MSDN#using-a-command-line