Skip to main content

How to Start IIS (World Wide Web Publishing Service) in Batch Script

Internet Information Services (IIS) is Microsoft's enterprise-grade web server built into Windows Server and available as an optional feature on Windows 10/11 Pro and Enterprise editions. Starting IIS from a Batch Script is a common requirement for automated deployment pipelines, server startup sequences, and development environment bootstrapping.

In this guide, we will explore multiple methods to start IIS, including the dedicated iisreset command, the generic net start command, and the sc service controller, along with verification techniques and error handling.

Understanding IIS Services

IIS is not a single service. It is composed of multiple interrelated Windows services:

Service NameDisplay NameRole
W3SVCWorld Wide Web Publishing ServiceThe core web server that serves HTTP/HTTPS requests
WASWindows Process Activation ServiceManages application pool configuration and worker processes
IISADMINIIS Admin ServiceLegacy IIS 6 management service (may not exist on modern IIS)

Starting W3SVC is the primary action. If WAS is not already running, Windows will start it automatically as a dependency.

Method 1: Using IISRESET (The Official IIS Tool)

The iisreset command is the officially supported tool for starting, stopping, and restarting all IIS services in one operation.

@echo off
setlocal

:: Verify Admin Rights
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges required.
pause
exit /b 1
)

:: Verify IIS is installed
where iisreset >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] iisreset command not found.
echo IIS may not be installed on this machine.
echo Install it via: dism /Online /Enable-Feature /FeatureName:IIS-WebServer /All
pause
exit /b 1
)

echo Starting IIS...

iisreset /start

if %errorlevel% equ 0 (
echo.
echo [SUCCESS] IIS has been started.
) else (
echo.
echo [ERROR] Failed to start IIS. Exit code: %errorlevel%
echo Check the System Event Log for details.
)

pause

IISRESET Options

CommandAction
iisreset /startStarts all IIS services
iisreset /stopStops all IIS services
iisreset /restartStops then restarts all IIS services
iisreset /statusDisplays the current status of IIS services
info

iisreset is only available when the IIS Management Tools feature is installed. On Windows Server Core installations or minimal IIS setups, this tool may be absent even though the W3SVC service itself is installed and functional. In those cases, use Method 2 or Method 3.

Method 2: Using NET START (The Standard Service Controller)

If iisreset is not available (for example, on a minimal Windows Server Core installation), you can start the IIS service directly using the net start command.

@echo off
setlocal

net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Admin required.
pause
exit /b 1
)

:: Check if IIS is installed
sc query W3SVC >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] IIS ^(W3SVC^) is not installed on this machine.
pause
exit /b 1
)

echo Starting World Wide Web Publishing Service...

:: Start the WAS dependency first (if not running)
net start WAS >nul 2>&1

:: Start the core web server
net start W3SVC
if %errorlevel% equ 0 (
echo [SUCCESS] W3SVC started.
) else if %errorlevel% equ 2 (
echo [INFO] W3SVC is already running.
) else (
echo [ERROR] Failed to start W3SVC. Check the System Event Log for details.
)

pause

Why Start WAS First?

The World Wide Web Publishing Service (W3SVC) depends on the Windows Process Activation Service (WAS). If WAS is not running and you attempt to start W3SVC, Windows will usually auto-start the dependency. However, explicitly starting WAS first provides cleaner error messages and more predictable behavior in scripts, because a failure in WAS would otherwise surface as a cryptic W3SVC start failure.

Method 3: Using SC (Detailed Service Control)

The sc command provides more granular control and better error reporting than net start.

@echo off
setlocal

net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Admin required.
pause
exit /b 1
)

echo Starting IIS via SC...

:: Check if W3SVC exists
sc query W3SVC >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] IIS ^(W3SVC^) is not installed on this machine.
echo Install it via: dism /Online /Enable-Feature /FeatureName:IIS-WebServer /All
pause
exit /b 1
)

:: Check if already running
sc query W3SVC 2>nul | findstr /i "RUNNING" >nul
if %errorlevel% equ 0 (
echo [INFO] IIS is already running. No action needed.
pause
exit /b 0
)

:: Start the services
sc start WAS >nul 2>&1
sc start W3SVC >nul 2>&1

:: Wait for the service to fully start (poll up to 15 seconds)
set "attempts=0"
:wait_loop
timeout /t 1 /nobreak >nul
set /a "attempts+=1"
sc query W3SVC 2>nul | findstr /i "RUNNING" >nul
if %errorlevel% equ 0 goto :running
if %attempts% lss 15 goto :wait_loop

:: Timed out
echo [ERROR] IIS did not reach RUNNING state within 15 seconds.
echo Current state:
sc query W3SVC 2>nul | findstr /i "STATE"
pause
exit /b 1

:running
echo [SUCCESS] IIS is RUNNING.
pause
tip

The polling loop above replaces a fixed timeout /t 3 delay. A fixed delay is unreliable because service startup time varies depending on the number of application pools, bound certificates, and system load. The polling approach checks every second and exits as soon as the service reaches RUNNING state, or times out after 15 seconds with a clear error message.

Method 4: Comprehensive IIS Startup Script

For production environments, a robust startup script should check for the IIS feature, start all required services, verify they are running, and log the result.

@echo off
title IIS Startup Manager
setlocal enabledelayedexpansion

:: Log file
set "logfile=%~dp0iis_start.log"

:: Timestamp function using wmic
set "timestamp="
for /f "tokens=2 delims==" %%T in ('wmic os get LocalDateTime /value 2^>nul ^| find "="') do set "dt=%%T"
if defined dt (
set "timestamp=!dt:~0,4!-!dt:~4,2!-!dt:~6,2! !dt:~8,2!:!dt:~10,2!:!dt:~12,2!"
) else (
set "timestamp=%DATE% %TIME:~0,8%"
)

call :log "IIS Startup Script Initiated"

:: Admin check
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges are required.
call :log "ERROR: Not running as Administrator"
pause
exit /b 1
)

:: Check if IIS is installed
sc query W3SVC >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] IIS is not installed.
echo Install via: dism /Online /Enable-Feature /FeatureName:IIS-WebServer /All
call :log "ERROR: W3SVC service not found"
pause
exit /b 1
)

:: Start services in dependency order
echo Starting IIS services...

for %%S in (WAS W3SVC) do (
sc query %%S 2>nul | findstr /i "RUNNING" >nul
if !errorlevel! equ 0 (
echo %%S: Already running.
call :log "%%S: Already running"
) else (
echo %%S: Starting...
sc start %%S >nul 2>&1

:: Poll for up to 10 seconds
set "ready=0"
for /L %%i in (1,1,10) do (
if !ready! equ 0 (
timeout /t 1 /nobreak >nul
sc query %%S 2>nul | findstr /i "RUNNING" >nul
if !errorlevel! equ 0 set "ready=1"
)
)

if !ready! equ 1 (
echo %%S: Started successfully.
call :log "%%S: Started OK"
) else (
echo %%S: [FAIL] Could not be started!
call :log "%%S: FAILED to start"
sc query %%S 2>nul | findstr /i "STATE"
)
)
)

:: Final verification
echo.
echo Final Status:
iisreset /status 2>nul
if !errorlevel! neq 0 (
echo ^(iisreset not available, using sc query^)
sc query W3SVC 2>nul | findstr /i "STATE"
sc query WAS 2>nul | findstr /i "STATE"
)

echo.
call :log "Startup sequence complete"
echo Log saved to: %logfile%

pause
exit /b 0

:log
>> "%logfile%" echo [!timestamp!] %~1
goto :eof

Starting a Specific Application Pool

Sometimes you don't need to start the entire IIS server, just a specific application pool. The appcmd utility handles this.

@echo off
setlocal

set "pool_name=DefaultAppPool"
set "appcmd=%SystemRoot%\System32\inetsrv\appcmd.exe"

:: Verify admin rights
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges required.
pause
exit /b 1
)

:: Verify appcmd exists
if not exist "%appcmd%" (
echo [ERROR] appcmd.exe not found at: %appcmd%
echo IIS Management Tools may not be installed.
pause
exit /b 1
)

echo Starting Application Pool: %pool_name%

"%appcmd%" start apppool /apppool.name:"%pool_name%"

if %errorlevel% equ 0 (
echo [OK] %pool_name% started.
) else (
echo [ERROR] Failed to start %pool_name%. Exit code: %errorlevel%
echo Verify the pool name exists: "%appcmd%" list apppool
)

pause
info

The appcmd.exe utility is located at %SystemRoot%\System32\inetsrv\ and is only available when IIS Management Tools are installed. It is not in the default system PATH, so you must specify the full path. To see all available application pools, run: %SystemRoot%\System32\inetsrv\appcmd.exe list apppool

Common Mistakes

The Wrong Way: Starting Just IISADMIN

:: WRONG on modern IIS - IISADMIN is a legacy IIS 6 service
net start IISADMIN
danger

On IIS 7+ (Windows Server 2008 and later), the IISADMIN service may not exist or may not control the modern application pool architecture. Always target W3SVC and WAS.

The Wrong Way: Not Checking Installation

:: WRONG - Assumes IIS is installed
iisreset /start
echo IIS is now running.

If IIS is not installed, iisreset either fails with a cryptic error or is not found at all. Always verify the service exists via sc query W3SVC (or the command exists via where iisreset) before attempting to start it.

The Wrong Way: Not Verifying the Service Actually Started

:: WRONG - Assumes the start command guarantees RUNNING state
net start W3SVC
echo IIS is now serving requests.
warning

A service can accept the start command (returning errorlevel 0) but then fail during initialization due to port conflicts, certificate errors, or application pool configuration issues. The service enters a START_PENDING state and may transition to STOPPED moments later. Always verify the RUNNING state after starting, either by polling with sc query or by calling iisreset /status.

Best Practices

  1. Use iisreset /start for simplicity: It handles all IIS service dependencies automatically. Fall back to sc start on systems where iisreset is not installed.
  2. Use sc start for granular control: When you need to start specific services or capture detailed error codes.
  3. Verify after starting: Always confirm the service reached RUNNING state. Use a polling loop rather than a fixed delay for reliable detection.
  4. Check for IIS installation first: Verify the W3SVC service exists with sc query W3SVC before attempting any start operations. Provide the dism installation command in error messages.
  5. Log everything: In production environments, write timestamps and service states to a log file for post-incident analysis.
  6. Start dependencies explicitly: Start WAS before W3SVC for more predictable behavior and clearer error messages when a dependency failure occurs.

Conclusion

Starting IIS from a Batch Script is straightforward using iisreset /start for the complete IIS stack, or net start W3SVC for targeted service activation. The critical elements of a production-quality startup script are verifying IIS installation, starting dependency services in the correct order, confirming the RUNNING state post-launch, and logging all actions for auditability. By incorporating these practices, administrators can build reliable, automated IIS management workflows.