You can use a Perl script to test for the proper installation and execution of Common Gateway Interface (CGI) scripts with Internet Information Server.
Use a text editor to create a file with the following lines of code. Save the file in the /Scripts directory as Hello.pl.
After you create the file, configure Perl to run securely with Internet Information Server. Do not locate Perl.exe in any directory accessible by a user. Create a script mapping in the Registry for Perl.exe to enable the script to run by using Perl.
1. Click the Start button, then point to Run. In the Open box, type regedt32.exe and then click OK.
2. Click the HKEY_LOCAL_MACHINE window and locate the following key:
\System
\CurrentControlSet
\Services
\W3SVC
\Parameters
\ScriptMap
3. From the Edit menu, click Add Value.
4. In the Add Value dialog box, enter the value name .pl with the data type REG_SZ.
5. In the String Editor dialog box type the string value
full path\perl.exe %s
and click OK.
This instructs Internet Information Server to interpret all files with the extension .pl by using Perl.exe.
6. To implement these changes, quit the Registry Editor, then stop and restart the WWW service.
7. Test the Perl script with your browser. For example, in Internet Explorer, type
http://Servername/scripts/helloworld.pl?
When you attempt to run a script on a client Web browser, an Unhandled File Type dialog box might appear. It requests that you save the file as a different filename or in a different location (Save As).
The problem is that the /Scripts directory has both Read and Execute access permissions set in Internet Service Manager. To work around this problem, do one of the following:
http://myserver/scripts/test.exe?
A CGI script compiled with a 16-bit C compiler might fail to run on Internet Information Server.
For example, say you use a 16-bit compiler to compile and build an executable file out of this C language source code:
If you then run the .exe file from the command prompt of Windows NT, the correct HTML output is generated. However, the results will be different if you place the same executable file in the /Scripts directory of the computer running Internet Information Server. If you try to run it from a Web browser by using the syntax.
http://Server/Path/File.exe?
it fails to generate the correct page.
To correct this problem, use a 32-bit C compiler to compile and build the C language source code. Microsoft C/C++ 4.0 and C/C++ 2.0 are 32-bit C compilers.
Microsoft Internet Information Server does not return a user name for the variable REMOTE_USER unless both of the following are true:
If you use anonymous authentication, all users are authenticated with the IUSR_computername account, and the variable is not assigned a value by default.
One method of obtaining the REMOTE_USER variable is to create a batch file with the following lines and save it in the /Scripts directory, or a directory enabled in Internet Information Server for execute permissions:
This batch file lists the environment variables used by Internet Information Server, including the REMOTE_USER variable. The list is returned as an HTML page to the Web browser that started the batch file.
Make sure you have configured script mapping for .bat or .cmd files, as described in the Internet Information Server Installation and Administration Guide.
You run the script from a browser by typing a URL with the syntax
http://Server_Name /Script
For example, you might type
http://www.company.com/scripts/environment.cmd?
The question mark at the end of the URL is required. The question mark signals the server that this is a GET request, which makes the server return script results rather than downloading the file to the user.
When submitting an HTML form or clicking a link to a script from a Web browser, the following message might be returned:
This error is caused by missing or incorrect CGI header information. In this case, the headers are missing because the script file cannot be run. Therefore, the message was displayed instead of the output from the script.
The CGI specification calls for the script file to return at least one header. This header indicates how to fill out the remainder of the HTTP headers as required by that protocol. HTTP also requires a blank line between the end of the headers and the start of the document. Some servers return an error if the blank line is not present. The only headers currently supported by the CGI specification are:
For more information about these headers, see the HTTP and CGI protocol draft specifications at http://www.w3.org.