IIS Environment Variables

This section describes what environment variables are provided by the IIS server for CGI programs.

To know how many environment variables are provided by the Web server, and what information they are containing, I wrote the follow Perl CGI program, CgiEnv.pl.

```#- CgiEnv.pl

print "Content-Type: text/html\n\n";
print "<html><body>\n";
foreach \$var (sort keys(%ENV)) {
print(\$var, ' = ', \$ENV{\$var}, "<br/>\n");
}
print "</html></body>\n";
```

Running it directly in a command window, I got:

```Content-Type: text/html

<html><body>
ALLUSERSPROFILE = C:\Documents and Settings\All Users.WINNT<br/>
APPDATA = C:\Documents and Settings\herong\Application Data<br/>
COMMONPROGRAMFILES = C:\Program Files\Common Files<br/>
COMPUTERNAME = localhost<br/>
COMSPEC = C:\WINNT\system32\cmd.exe<br/>
HOMEDRIVE = C:<br/>
HOMEPATH = \Documents and Settings\herong<br/>
LOGONSERVER = \\localhost<br/>
NUMBER_OF_PROCESSORS = 1<br/>
OS = Windows_NT<br/>
OS2LIBPATH = C:\WINNT\system32\os2\dll;<br/>
PATH = D:\Perl\bin\;C:\WINNT\system32;C:\WINNT;...
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH<br/>
PROCESSOR_ARCHITECTURE = x86<br/>
PROCESSOR_IDENTIFIER = x86 Family 6 Model 8 Stepping 1, GenuineInte...
PROCESSOR_LEVEL = 6<br/>
PROCESSOR_REVISION = 0801<br/>
PROGRAMFILES = C:\Program Files<br/>
PROMPT = \$P\$G<br/>
SESSIONNAME = Console<br/>
SYSTEMDRIVE = C:<br/>
SYSTEMROOT = C:\WINNT<br/>
TEMP = C:\DOCUME~1\herong\LOCALS~1\Temp<br/>
TMP = C:\DOCUME~1\herong\LOCALS~1\Temp<br/>
USERDOMAIN = home<br/>
USERPROFILE = C:\Documents and Settings\herong<br/>
WINDIR = C:\WINNT<br/>
</html></body>
```

Running it through IIS as a CGI application, I got:

```ALLUSERSPROFILE = C:\Documents and Settings\All Users.WINNT
COMMONPROGRAMFILES = C:\Program Files\Common Files
COMPUTERNAME = localhost
COMSPEC = C:\WINNT\system32\cmd.exe
CONTENT_LENGTH = 0
GATEWAY_INTERFACE = CGI/1.1
HTTPS = off
HTTP_ACCEPT = */*
HTTP_ACCEPT_LANGUAGE = en-us
HTTP_CONNECTION = Keep-Alive
HTTP_HOST = localhost
HTTP_USER_AGENT = Mozilla/4.0 (compatible; MSIE 6.0; MSNIA; Windows...
INSTANCE_ID = 1
NUMBER_OF_PROCESSORS = 1
OS = Windows_NT
OS2LIBPATH = C:\WINNT\system32\os2\dll;
PATH = D:\Perl\bin\;C:\WINNT\system32;C:\WINNT;...
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PATH_INFO = /cgi-bin/CgiEnv.pl
PATH_TRANSLATED = c:\inetpub\wwwroot\cgi-bin\CgiEnv.pl
PROCESSOR_ARCHITECTURE = x86
PROCESSOR_IDENTIFIER = x86 Family 6 Model 8 Stepping 1, GenuineIntel
PROCESSOR_LEVEL = 6
PROCESSOR_REVISION = 0801
PROGRAMFILES = C:\Program Files
REMOTE_HOST = 127.0.0.1
REQUEST_METHOD = GET
SCRIPT_NAME = /cgi-bin/CgiEnv.pl
SERVER_NAME = localhost
SERVER_PORT = 80
SERVER_PORT_SECURE = 0
SERVER_PROTOCOL = HTTP/1.0
SERVER_SOFTWARE = Microsoft-IIS/5.0
SYSTEMDRIVE = C:
SYSTEMROOT = C:\WINNT
TEMP = C:\WINNT\TEMP
TMP = C:\WINNT\TEMP
USERPROFILE = C:\Documents and Settings\Default User.WINNT
WINDIR = C:\WINNT
```

As you can see from the output, IIS has added some and removed some environment variables in the CGI environment.