8

I have a site where I need to restart the site and its apppool each time I make changes. When I'm debugging one of the scripts it becomes a chore to do it manually each time (it's 5-6 clicks).

enter image description here enter image description here

Is there a way to automate it in a batch file?

Edit: I found how to restart the apppool from https://stackoverflow.com/a/38607626/492336, but I need to restart the site as well:

C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"MYAPPPOOLNAME"
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

10

After some searching and trial and error, I came up with a short script, where "Default Web Site" is the name of the site to restart:

C:\Windows\System32\inetsrv\appcmd stop apppool /apppool.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd stop site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"Default Web Site"

If you get this error:

message:The WAS service is not available - try starting the service first.

Try to execute with admin privileges.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • 2
    Worked perfectly! Thanks for putting the time in to figure it out! – Gup3rSuR4c Aug 13 '19 at 03:21
  • 1
    Is there any way to check the status (started or stopped) of apppool from batch script? – imsome1 Mar 06 '22 at 08:32
  • 1
    @imsome1 good idea - but [you should ask a new question for that](https://stackoverflow.com/questions/ask) – sashoalm Mar 06 '22 at 10:09
  • 1
    Worked for me! I had issues when Jenkins try to deploy build artifacts to IIS folder. Tried giving full access to users and nothing worked. When the app pool stopped before deploying and restarted afterward resolved the issue. Didn't have to stop and restart the site though – oshan2csd Nov 16 '22 at 00:51