adspace


How do I automatically restart iis?

Answer Posted / Brashketu Dwivedi

To automatically restart IIS (Internet Information Services), you can add the following lines to your system's autostart folder. Go to 'C:Users<username>AppDataRoamingMicrosoftWindowsStart MenuProgramsStartup', create a new text file, name it 'iisrest.bat', and paste the following content:
```bash
@echo off
setlocal enabledelayedexpansion
cd /d %~dp0
set current=1
:loop
for /f "tokens=1,2 delims=:" %%a in ('wmic service where name="World Wide Web Publishing Service" get state /value') do if %%a == 4 set status=running
if not exist iisrest_%current%.txt (
echo Pausing IIS...
net pause iisadmin /app "Default Web Site"
echo Waiting for IIS to pause...
timeout /t 10 /nobreak > nul
if %status% == running goto loop
echo Creating iisrest_%current%.txt
powershell -command New-Item -Path .iisrest_%current%.txt
) else (
set /a current+=1
del iisrest_!current!-.txt 2>nul
)
echo Restarting IIS...
net start w3svc
timeout /t 60 /nobreak > nul
goto loop
```
Save and run the file as an administrator.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category