title: How to start IIS Express in background mode from cmd or PowerShell and VS Code?
body: <p>I'm using VS Code with php-debug extension, IIS Express and PHP (IIS/PHP from Web PI) and trying to automate IIS Express startup with a <code>preLaunchTask</code> on <code>launch.json</code> file from Visual Studio Code. So I wrote those things below on my <code>launch.json</code> and <code>tasks.json</code> files.</p>
  
  <p>All things work nicely, except for the fact that VS Code keeps locked on IIS Startup, because IIS stay running, waiting for the user input (i.e.: "Q" to quit IIS). This way, even with IIS running ok, I couldn't debug inside VS Code, because it's waiting the IIS task to finish.</p>
  
  <p>I've tried with Powershell and <code>Start-Job</code> (PS script excerpt below) without success, because PowerShell seems to start IIS, but nothing happens (IIS is not started).</p>
  
  <p>How could I accomplish that?
  Where I'm doing it wrong?
  Thank you in advance.</p>
  
  <p><strong>launch.json</strong></p>
  
  <pre><code>{
      "version": "0.2.0",
      "configurations": [
          {
              "name": "Listen for XDebug",
              "type": "php",
              "request": "launch",
              "port": 9000, "preLaunchTask": "start_server"
          }
      ]
  }
  </code></pre>
  
  <p><strong>tasks.json -- cmd version</strong></p>
  
  <pre><code>{
     "version": "0.1.0",
     "command": "cmd.exe",
     "isShellCommand": true,
     "args": [
         "/C",
         "runphp.cmd"
     ],
     "tasks": [
         {
             "taskName": "start_server",
             "isBuildCommand": false,
             "showOutput": "always"
         }
     ]
  }
  </code></pre>
  
  <p><strong>tasks.json -- Powershell version</strong></p>
  
  <pre><code>{
     "version": "0.1.0",
     "command": "PowerShell.exe",
     "isShellCommand": true,
     "args": [
         "-ExecutionPolicy",
         "ByPass",
         "-File",
         ".\\wahoo.ps1" // my powershell script
     ],
     "tasks": [
         {
             "taskName": "start_server",
             "isBuildCommand": false,
             "showOutput": "always"
         }
     ]
  }
  </code></pre>
  
  <p><strong>wahoo.ps1 -- only used when I set the powershell version from tasks.json</strong></p>
  
  <pre><code>$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
  $command = @'
  cd $scriptDir | cmd.exe /C runphp.cmd
  '@
  
  Start-Job -Name "IISPHP" -Arg $command -ScriptBlock {
      param ($command)
      Invoke-Expression -Command:$command
      Start-Sleep 3
  }
  </code></pre>
  
  <p>My <code>runphp.cmd</code>is an adapted version of the original <code>runphp.cmd</code> from IIS/PHP installation folder to suit my needs and contains the following:</p>
  
  <p><strong>runphp.cmd</strong></p>
  
  <pre><code>SET pf=%ProgramFiles%
  if DEFINED ProgramFiles(x86) SET pf=%ProgramFiles(x86)%
  
  set appcmd="%pf%\iis express\appcmd.exe"
  set iisexpress="%pf%\iis express\iisexpress.exe"
  
  cd &gt; tmpFile
  set /p currentdir= &lt; tmpFile
  del tmpFile
  
  where php-cgi.exe &gt; tmpFile
  set /p phprt= &lt; tmpFile
  del tmpFile
  if DEFINED phprt goto setup_iis
  SET phprt=%pf%\PHP\v5.3\php-cgi.exe
  
  :setup_iis
  %appcmd% set config /section:system.webServer/fastCgi "/+[fullPath='%phprt%']" "/apphostconfig:%currentdir%\applicationhost.config"
  %appcmd% set config /section:system.webServer/handlers "/+[name='PHP-FastCGI',path='*.php',modules='FastCgiModule',verb='*', scriptProcessor='%phprt%',resourceType='Either']" "/apphostconfig:%currentdir%\applicationhost.config"
  %iisexpress% /site:EmptySite /config:"%currentdir%\applicationhost.config"
  </code></pre>