title: setting and reading environment variables in IIS 10
body: <p>I can not figure out how to set and read environment variables in Microsoft Internet Information Services (IIS) version 10. I have a Fast CGI app that requires environment variables. In previous versions of IIS I just set system-wide variables in the Windows "System Properties". However in IIS 10 my FCGI app isn't reading them. So my first question is if there are steps that need to be taken so that the IIS process can read system variables?</p>
  
  <p>Alternatively, how do I set environment variables within IIS 10? This <a href="https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/applicationpools/add/environmentvariables/" rel="nofollow noreferrer">Microsoft site</a> explains it but not in enough detail for me to get it working. Specifically, in what file and in which section do you put the <code>&lt;environmentVariables&gt;</code> section? The example XML and the command line example have <code>name="Contoso"</code> (see below) but what is that - the name of the application pool, or my FCGI app, or something else?</p>
  
  <p><code>&lt;applicationPools&gt;
      &lt;add name="Contoso" managedRuntimeVersion="v4.0" managedPipelineMode="Classic"&gt;
          &lt;environmentVariables&gt;
              &lt;add name="foo" value="bar" /&gt;
          &lt;/environmentVariables&gt;
      &lt;/add&gt;
  &lt;/applicationPools&gt;</code></p>
  
  <p>Edit in response to Jokies Ding: 
  <code>MAP22</code> and <code>PROJ_LIB</code> are the two environment variables that I need. In C:\Windows\System32\inetsrv\Config\applicationHost.config
  I have:</p>
  
  <pre><code>    &lt;applicationPools&gt;
          &lt;add name="DefaultAppPool" /&gt;
          &lt;add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" /&gt;
          &lt;add name=".NET v4.5" managedRuntimeVersion="v4.0" /&gt;
          &lt;add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0" /&gt;
          &lt;applicationPoolDefaults managedRuntimeVersion="v4.0"&gt;
              &lt;processModel identityType="ApplicationPoolIdentity" /&gt;
              &lt;environmentVariables&gt;
                  &lt;add name="PROJ_LIB" value="/gdal/bin/proj6/SHARE" /&gt;
                  &lt;add name="MAP22" value="/tetonwy/mapserv/main.map" /&gt;
              &lt;/environmentVariables&gt;
          &lt;/applicationPoolDefaults&gt;
      &lt;/applicationPools&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    &lt;fastCgi&gt;
          &lt;application fullPath="C:\gdal\bin\ms\apps\mapserv.exe"&gt;
              &lt;environmentVariables&gt;
                  &lt;environmentVariable name="MAP22" value="C:\tetonwy\mapserv\main.map" /&gt;
                  &lt;environmentVariable name="PROJ_LIB" value="C:\gdal\bin\proj6\SHARE" /&gt;
              &lt;/environmentVariables&gt;
          &lt;/application&gt;
      &lt;/fastCgi&gt;
  </code></pre>
  
  <p>and in a cmd window the environment variables are visible</p>
  
  <p><code>C:\&gt;set MAP22
  MAP22=C:\tetonwy\mapserv\main.map
  C:\&gt;set PROJ_LIB
  PROJ_LIB=C:\gdal\bin\proj6\SHARE</code></p>
  
  <p>So it seems like I've got the variables set all over the place but the app isn't seeing them. <code>C:\gdal\bin\ms\apps\mapserv.exe</code> is the FastCGI app that isn't seeing the environment variables. It's a compiled C program that I have used in previous versions of IIS.</p>