Editor's Note: Each month, this column discusses various aspects of e-commerce with Microsoft Site Server 3.0. This month's column examines automating some of the advanced features of Site Server's Personalization and Membership (P&M) feature with Windows Scripting Host (WSH) technology.

In my previous articles, I showed you some advanced configurations of Site Server and its P&M features. I've shown you how to build a Membership server and use it on your e-commerce site to deliver secure and personalized content. Almost everything I've shown you so far has required significant time and config-uration in the Site Server Service Admin Microsoft Management Console (MMC) snap-in. This month, you'll build a Membership server, map it to a Web server, and then apply an authentication method to it—and you'll completely automate the process in a WSH script. (WSH is a language-independent scripting host for ActiveX scripting engines on 32-bit Windows platforms. I use the Command Line Scripting utility—cscript.exe—to execute a WSH script from the command line.)

Here's the scenario: Any company with a Web farm has to have an automated process for bringing up new Web servers. With the added complexity of a Directory Service (DS), building and configuring those Web servers manually would take too long to get them into production. How great would it be if you could completely automate the process for bringing new servers into production?

I originally wrote the script CreateDS.vbs to automate the process of creating and configuring Web servers for a client. I adapted the code from an example I saw in Robert Howard, Site Server 3.0 Personalization and Membership (Wrox Press, 1998), then adapted the code again in June 1999 so that it could ship with the Windows Media Pay-Per-View sample site. I encourage you to download the code from This URL is for the German version (de) of the Microsoft site because at press time, the URL to the English version (en) had a bug that redirected me to the wrong place. The script helps automate the creation of the sample site through a Win32 wizard and creates the Membership server as one of the first tasks of the sample-site installation. I've improved the script by removing everything that was hard-coded, so it's generic enough for building your sites.

Examining How the Script Works
Let's take a look at how CreateDS.vbs works before I show you how to run it. (CreateDS.vbs is too long to print here, so I'll just include excerpts in this column. You can find the entire script in the Code Library of the IIS Administrator Web site at

CreateDS.vbs is a wrapper to the Site Server script PMAdmin.vbs. (For a brief discussion of wrapping, see the sidebar "Wrapping Functionality to Avoid Redundant Coding," page 10.) PMAdmin.vbs installs when you install Site Server. This extremely robust WSH script includes much more functionality than the actual Site Server Admin MMC snap-in. PMAdmin.vbs builds a Membership server, maps it to a Web server, and sets authentication. All of the script's functionality is available from the command line.

Because I'm wrapping the functionality of PMAdmin.vbs in CreateDS.vbs, CreateDS.vbs first needs to make sure that PMAdmin.vbs exists. To verify that PMAdmin.vbs exists, CreateDS.vbs must access the Registry. The Microsoft Commerce Team wrote some great COM objects in the Site Server 3.0 product, the APIs of which are available for use. Two of those objects—Commerce.AdminRegistry and Commerce.AdminFiles—allow Registry access. I instantiate these two COM objects with the code

Dim Reg
Set Reg = CreateObject


Dim AdminFiles
Set AdminFiles = CreateObject ("Commerce.AdminFiles")

After I instantiate these objects, I can use their methods and properties. For example, I use the Commerce.AdminRegistry object's GetValue method to retrieve the location of the P&M directory. Later in the script, I use this object's DeleteValue method to delete a Registry key.

When users run CreateDS.vbs, they need to supply nine parameters. Thus, after verifying the existence of PMAdmin.vbs, I include the following code to make sure the users include all nine parameters:

If Wscript.Arguments.Count <> 9 then DisplayHelp( )
End if

If a parameter is missing, the DisplayHelp function alerts the user to the problem and provides the proper syntax and format for each parameter that CreateDS.vbs requires. Next, I instantiate the Wscript.Shell object with the code

Set IWshShell =

I use the IWshShell object's Run method to create a new process that executes PMAdmin.vbs in a separate, nonvisible command window. The Run method of the Wscript.Shell object executes three times in CreateDS.vbs. First, the Run method creates the Membership Server instance, as the excerpt in Listing 1 shows. If the Run command is successful, the Run method maps the Membership Server instance to the Web site, as the excerpt in Listing 2 shows. If the mapping is successful, the Run method sets the authentication on the Web server, as the excerpt in Listing 3 shows.

Running CreateDS.vbs
Before you can run CreateDS.vbs, you need to create a blank Microsoft SQL Server database with 20MB of space. This database will house the DS data. Create the database from SQL Server 7.0 Enterprise Manager, call it MembershipDB, and give it 20MB of initial space. I used SQL Server 7.0 for testing the CreateDS.vbs script. SQL Server 7.0 has a feature that grows the database by default as data accumulates. The SQL Server Database in which MembershipDB houses its data requires 20MB of available space before you can create it, so I changed the 1MB initial database size to 20MB.

When you run CreateDS.vbs, the script will use the Wscript.Echo command to output results to the command console window. Additionally, the script uses the DisplayHelp function to display the output in the command console window. If you run CreateDS.vbs with the default of 25 lines per screen, the number of lines of output will exceed the number of lines the console window displays (25), so the initial lines of output scroll off the screen, never to be seen again. If you want to prevent the CreateDS.vbs script from spilling its output off the screen, you can extend the size of your command console window. Go to the Control Panel Console applet, and click the Layout tab. Change the height in the Screen Buffer Size to at least 50. This new screen buffer size forces the command prompt to remember 50 lines, even if they've scrolled by. Change the height in the Window Size to 50 as well if your screen resolution supports it. This new window size effectively doubles the size of the command prompt window. Click OK to save the changes.

Download CreateDS.vbs, and place the script in the \microsoft site server\bin\p&m directory on your Site Server. Run a command prompt (in Windows 2000—Win2K—choose Start, Programs, Accessories, Command Prompt), and change to that directory. (Hint: Use double quotes when using the CD command with a directory that has strange characters such as an ampersand—&—in it.) Now, you're ready to run the script. Here's the syntax:

script CreateDS.vbs <web-instance-number> <root-name>
   <port-number> <SQL-server-name> <database-name>
   <DS-Password> <Authentication-Method> <DB-UserName>

I used the format below on my server:

Cscript createds.vbs 1
 InterKnowlogy 1004 timhuck
 membershipdb password 18 SA ""


  • 1 refers to the Default Web Site (or the first instance of a Web server). You can determine the instance number of a Web server or a Membership server by opening the Site Server Service Admin MMC snap-in and counting the instances starting from the top and moving down. For example, Default Web Site is the first Web server on Site Server. Beneath Default Web Site is the Administration Web site, which is the second instance of a Web server. The same goes for Membership servers. If you look under the Personalization and Membership snap-in, you'll see the Intranet (Windows NT 4.0 authentication) Membership server, which is the first instance of a Membership server. If you create another Membership server, as you will for the CreateDS.vbs script in this article, it will be the second instance and will appear directly under the Intranet Membership server.
  • InterKnowlogy is the root distinguished name (DN) for the Membership directory that you're creating. (Remember from my previous articles that the DN is the realm- or highest-level name of the DS. If you forget the DN of your DS, you can quickly obtain it by right-clicking the Membership Directory Manager snap-in of the Site Server Service Admin MMC snap-in connected to your Membership server, then selecting Properties.)
  • 1004 is the available Lightweight Directory Access Protocol (LDAP) port number for the Membership Server instance to use. When you manually built the Membership server that you used in the previous articles, the wizard automatically took the next available LDAP port, which was 1003.
  • timhuck is the name of the SQL Server machine on which you'll save the persistent DS data.
  • membershipdb is the name of the SQL Server database in which you'll save the persistent DS data.
  • password is the Administrative password of the new Membership server. (This password isn't the NT Administrator's password, but the password for the Administrator of the DS that you're creating.)
  • 18 is the value for the authentication method you're applying to the Web server. In the previous articles, you used HTML Forms authentication. Use the information in Table 1 to obtain the value of the authentication method you want to use.
  • SA is the SQL account with rights to the SQL Server database.
  • "" is the SQL account password with rights to the SQL Server database.

Modify the parameters to conform to your server, and execute CreateDS.vbs. It took 1 minute and 15 seconds for the script to run on my notebook, on which Site Server and SQL Server 7.0 are running. The creation of the Membership server consumed the bulk of the time. Mapping and authentication setting happened almost instantly. I included some simple screen I/O in the code so that you can monitor what's happening.

Now, let's examine what the script did. Access the Site Server Service Admin MMC snap-in by choosing Start, Programs, Microsoft Site Server, Administration. Click the Personalization and Membership snap-in, then click your server name. You'll see the Membership Server instance you just created, which looks similar to Screen 1. Now, click the Internet Information Server snap-in. Right-click Default Web Site, select Properties, then click the Membership Authentication tab. Notice the Membership Server Mapping and the Authentication Method that you've applied, which looks similar to Screen 2.

Next Month
In this article, you've seen how to automate the creation, mapping, and authentication of Site Server 3.0 P&M. Next month, I'll show you how to automate creation of custom attributes and Membership groups in the DS with the WSH script.