Microsoft KB Archive/261205

From BetaArchive Wiki

How to Use Windows Script Host Scripts as CGI Scripts

Q261205



The information in this article applies to:


  • Microsoft Internet Information Services version 5.0



IMPORTANT: This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information about how to do this, view the "Restoring the Registry" Help topic in Regedit.exe or the "Restoring a Registry Key" Help topic in Regedt32.exe.


SYMPTOMS

When you attempt to call a Visual Basic Script from a Web server in the context of a CGI script, the script may fail to run properly.



CAUSE

This usually occurs because the scripting engine is typically executed in the security context of the IUSR_MachineName account created by IIS when it is installed. However, the Cscript.exe file (the scripting engine) requires the presence of certain registry entries for the user context that it runs under (for anonymous access this is the IUSR_MachineName account). Because an HKEY_CURRENT_USER hive is created for the IUSR_Machine account, IIS loads the HKEY_USERS\.DEFAULT hive in its place. However, the HKEY_USERS\.DEFAULT hive does not contain the necessary keys and entries for the scripting engine.

In these cases, a CGI error message occurs without any additional information. This is the correct behavior for CGI error messages. If you debug the actual HTTP error message, you see this as an HTTP 502 502 "Bad Gateway" ("The server received an invalid response from the server from which it was trying to retrieve information.") error message.

To configure the IIS computer to allow Visual Basic scripts to be executed as a CGI script, see the "More Information" section of this article.



MORE INFORMATION

The Windows Script Host is installed on all Windows 2000 (IIS 5.0) computers. Use the following steps to enable Visual Basic script support:

  1. Configure the .vbs extension to map to the Cscript.exe file located in the %SYSTEMROOT%\System32 folder. To do this through the Microsoft Management Console (MMC), the configuration steps for IIS 4.0 are as follows:

    1. Open the IIS 4.0 Management Console application.
    2. Right-click your Web site, and then click Properties.
    3. Click the Home Directory tab.
    4. In the Application Settings dialog box, select Configuration.
    5. On the Application Mappings tab, click Add.
    6. On a Windows NT 4.0-based computer, the executable is as follows. (Make sure to use correct path to Cscript.exe).
    7. Type .vbs for the extension.
    8. Make sure that the Script Engine and Check that files exists check boxes are selected.
    9. Save the file by clicking OK. Click Apply, and then click OK twice.
  2. In the Registry Editor, create the following registry keys and entries:

    HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Script Host

    HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Script Host\Settings

    Make sure that Everyone has Read access to these two registry keys.

    Under the HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Script Host\Settings registry key, add the following:

    BatchMode: REG_DWORD: 0

    DisplayLogo: REG_DWORD: 0

    Timeout: REG_DWORD: 0

  3. Add the metabase parameters by performing the following steps.

    WARNING: Using Adsutil.vbs incorrectly can cause serious problems that may require you to reinstall Internet Information Server 4.0. Microsoft cannot guarantee that problems resulting from the incorrect use of Adsutil.vbs can be solved. Use Adsutil.vbs at your own risk.

    To set the value, do the following:

  4. Open a command window (cmd), and go to the Inetpub\AdminScripts directory. (This location may vary depending on your installation of Internet Information Server).
  5. Type the following commands with the following syntax:
  6. Copy the .vbs script file to a virtual directory on the server that has execute/script permissions. By default, the Scripts directory has the necessary permissions.
  7. You can test the configuration by creating the following script:

       Option Explicit
       WScript.Echo
       WScript.Echo "If you see this, it worked." 

    Save the above script in the Scripts directory as Test.vbs, and then invoke the script using any browser with the following URL:

       http://server/scripts/test.vbs. 

NOTE: Similar limitations apply to all situations where a Cscript.exe script is started 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.

Additional query words: Windows 2000 iis 5

Keywords : kbOSWin2000
Issue type : kbprb
Technology : kbiisSearch kbiis500


Last Reviewed: May 28, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.