Recipe 12.2. Stopping and Starting IISProblemYou want to stop and restart IIS as a whole, individual IIS services, or individual sites. SolutionUsing a graphical user interface
Using a command-line interfaceThe following command restarts all IIS services on the computer: > iisreset To stop IIS services on a remote computer with IP address 172.16.12.5 do the following: > iisreset 172.16.12.5 /stop To verify that IIS services have been stopped on the remote computer, do the following: > iisreset 172.16.12.5 /status To prevent iisreset from being used to stop IIS services, type the following command at the local console of your IIS computer: > iisreset /disable To stop the WWW service only on your IIS computer: > net stop w3svc To start it again: > net start w3svc To stop the IISAdmin service and all dependent IIS services: > net stop /y iisadmin To stop the Default Web Site only while leaving other web sites running, use this command: > iisweb /stop "Default Web Site" To start it again: > iisweb /start "Default Web Site" Using VBScript' This code stops and starts the specific web site. ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>" 'e.g., web01.rallencorp.com strPath = "<IISPath>" 'e.g., W3SVC/1 ' ------ END CONFIGURATION --------- set objIIS = GetObject("IIS://" & strComputer & "/" & strPath) objIIS.Stop WScript.Echo "Web site " & strComputer & "/" & strPath & " successfully stopped" objIIS.Start WScript.Echo "Web site " & strComputer & "/" & strPath & " successfully started" DiscussionIn previous versions of IIS, you often had to restart IIS frequently to keep a flaky application running. With IIS 6, you can use application pool recycling (see Recipe 12.23) instead, which restarts only the worker processes associated with that application and leaves other applications running. The only time you should need to restart IIS using the procedures outlined above is when you make a major configuration change to your computer, such as installing a new ISAPI filter or COM component. Using a graphical user interfaceIf you can't restart IIS using IIS Manager, it means you may have disabled restarts by running iisreset /disable on your computer previously. Run iireset /enable and try again. Using a command-line interfaceTo stop and start the FTP service, use net stop msftpsvc and net start msftpsvc (or the sc equivalents), and to stop and start individual FTP sites, use the iisftp.vbs command script. Using a VBScriptIf you want to restart a particular web or FTP site, set the strPath variable to the name of the service (e.g., W3SVC) followed by a forward slash and the numeric identifier for the site as seen in IIS Manager. To restart all IIS web services, set strPath to W3SVC. See AlsoRecipe 7.1 and Recipe 12.23 |