Microsoft KB Archive/221081

= How to use Windows Script Host scripts as CGI scripts =

Article ID: 221081

Article Last Modified on 1/17/2007

-

APPLIES TO


 * Microsoft Internet Information Server 4.0
 * Microsoft Internet Information Services 5.0
 * Microsoft Visual Basic, Scripting Edition 1.1
 * Microsoft Visual Basic, Scripting Edition 2.0
 * Microsoft Visual Basic, Scripting Edition 3.0
 * Microsoft Visual Basic, Scripting Edition 4.0
 * Microsoft Visual Basic, Scripting Edition 5.0

-



This article was previously published under Q221081



SUMMARY
When attempting to call a Visual Basic Script from a Web server in the context of a CGI script, the script may fail to run properly. The most likely reason for this is that the scripting engine is typically executed in the security context of the IUSR_Machine created by IIS when it is installed.

Unfortunately, the Cscript.exe (the scripting engine) requires the presence of certain registry entries for IUSR_Machine user. Since a HKEY_CURRENT_USER hive is not available for the IUSR_Machine, IIS will load the HKEY_USERS\.DEFAULT hive in its place. However, the HKEY_USERS\.DEFAULT hive does not contain the neccessary keys and entries for the scripting engine.

In these cases, a CGI error will occur, without any additional information. Or if the Cscript.exe file was launched in batch mode, an error will appear indicating it was unable to load the settings for the specified user. This document will show how to configure the IIS machine to allow Visual Basic Scripts to be executed as a CGI script.



MORE INFORMATION
This article assumes that the Windows Script Host is installed on the IIS server machine; the default installation option of NT Option Pack will do this.

Use the following steps to enable VBScript support:  Open a command prompt. To do this, follow these steps:  Click Start, and then click Run. Type cmd, and then click OK.  Locate the Inetpub\AdminScripts folder. (This location may vary depending on your installation of Internet Information Server). Type the following commands:

cscript adsutil.vbs SET w3svc/CreateCGIWithNewConsole "1"

cscript adsutil.vbs SET w3svc/CreateProcessAsUser "0"

 Configure the .vbs extension to be mapped to the Cscript.exe located in the %SYSTEMROOT%\System32 directory. Do this through the Microsoft Management Console. Specifically, the configuration steps for IIS4 are as follows:  Run the IIS4 Management Console application.</li> Edit the properties for your Web site (right-click on your Web site in the tree display and select Properties).</li> Select the Home Directory tab.</li> In the Application Settings box, select Configuration.</li> On the App Mappings tab select Add.</li>  The executable will be the following on a WinNT 4.0 machine (make sure to use correct path to Cscript.exe on your WinNT installation): C:\WINNT\system32\CSCRIPT.EXE.exe %s %s </li></ol>

Enter .vbs for the extension.

 Make sure that the Script Engine and Check that files exists check boxes are selected.</li> Save the file by clicking OK, Apply, OK, and OK again.</li></ol> </li>  Using the Registry Editor, create the following Keys and Entries:

HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Script Host HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Script Host\Settings Verify that Everyone has Read access to these two keys.

Now create the following entries under: HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Script Host\Settings

BatchMode: REG_DWORD: 0 DisplayLogo: REG_DWORD: 0 Timeout: REG_DWORD: 0 </li> Now copy the .vbs script file to a virtual directory on the server which has execute/script permissions. By default the /scripts directory will have the neccessary permissions.</li></ol>

You should be able to test whether the configuration works or not by creating the following script:

Option Explicit WScript.Echo "Content-Type: text/html" WScript.Echo WScript.Echo "If you see this, it worked." Save the above script in the /scripts directory as Test.vbs. Now invoke the script using any browser with the following URL: http://server/scripts/test.vbs. NOTE: Similar limitations apply to all situation where a Cscript.exe script is launched from the security context of a local system or a local system impersonating a user. The above changes to the Registry should remedy these situations.

<div class="references_section">