February 28, 2021
Hot Topics:

Writing Active Server components in Visual Basic

  • By Thornton Rose
  • Send Email »
  • More Articles »

Active Server components are a feature of Microsoft Internet Information Server (IIS) that provide a framework for building compiled components that can be used within Web pages. Below are step-by-step instructions for building Active Server components in Visual Basic (VB) 5.0. The process involves Active Server Pages (ASP), another feature of IIS. ASP provides the ability to combine server-side scripting in the same file with HTML, allowing you to use Active Server components and create dynamic Web pages.


Here are the tools that you need to build Active Server components:

  • Windows NT Workstation 4.0
  • Visual Basic 5.0 Enterprise Edition
  • Internet Information Server 3.0 or later, or Peer Web Services (which is IIS for Windows NT Workstation)
  • duct tape (Just kidding.)

Note: You will want to install IIS on your workstation, because VB will need to reference some of the IIS libraries, and you may need to start and stop the Web server during testing.


Building an Active Server component is not hard. Here are the steps involved in the construction of a small component that performs some simple file IO operations and generates a little HTML:

  1. Create an ActiveX DLL project and set the name to "ASCExample"

  2. Add the following references:

    Microsoft Active Server Pages 1.0 Object Library

    Microsoft Scripting Runtime

  3. Add a new class to the project, and set the name to "FileIO". (Note: This name plus the project name will be used to identify your component in the registry, for example "ASCExample.FileIO").

  4. Add this code to the FileIO class.

  5. Save everything and compile. That's it.


Testing your Active Server component is easy (although debugging can get tedious). A few lines of VBScript or JavaScript in an ASP page is all that is required. Here's the test script:




   ASCExample Tester



ASCExample Tester

<% ' Create a FileIO object. set objFileIO = Server.CreateObject("ASCExample.FileIO") %>
<% ' Get some help from the FileIO object. objFileIO.help %>
<% ' Create a file for testing. strLogFileName = "c:\temp\test.log" objFileIO.appendLine strLogFileName, "This is line 1." %> strLogFileName = <%= strLogFileName %>
fileExists() => <%= CStr(objFileIO.fileExists(strLogFileName)) %>
fileSize() => <%= objFileIO.fileSize(strLogFileName) %> bytes <% ' Delete the file. objFileIO.deleteFile(strLogFileName) %>

File deleted.
fileExists() => <%= CStr(objFileIO.fileExists(strLogFileName)) %> [end]

(Note: The <% and %> are used to delimit the server-side scripting.)

To use the test script, do the following:

  • Save the script as a file called "ASCExampleTester.asp" in a Web directory that has execute permission.

  • Point your browser at
    , where the <dir> tag is the name of the Web directory where

When you run the test script, you should get the following output.

Implementation details

Basically, an Active Server component is just a VB class. What makes it different, though, is:

  • it is packaged into an ActiveX DLL.

  • it implements OnStartPage() and OneEndPage(), which are methods that are called by IIS.

OnStartPage() is called when the component is created and can be used to get references to objects that exist within the context of an ASP page. These objects can then be used for many purposes, such as writing HTML to the response that is sent to the client. This can be seen in the help() method.

OnEndPage() is called when the component is destroyed, which will happen when the current ASP page is completely processed. This method can be used to free resources, release object references (i.e., set them = Nothing), and do other clean up.

Additionally, you should notice that some of the members of the FileIO component are private and some are public. (There are no protected members, since VB does not support inheritance.) As you would expect, only the public members are visible to users of the component. Remember, though, that a good practice in OOP is to make all member variables private and implement public accessor methods for them (e.g., getFoo() and setFoo()).


Here are two tips that might be helpful when you build some of your own Active Server components:

  1. When you deploy your components to another server, you will have to copy the DLL to the IIS components directory (which is usually c:\winnt\system32\inetsrv\???) and register the components. You register them with the registration utility, regsvr32.exe (e.g. regsvr32 ASCExample.dll). You don't have to do this when developing, because VB registers the DLL for you at the end of compilation.

  2. When you use an Active Server component, IIS locks the DLL (don't ask me why) and keeps it locked even after the ASP page is processed. If you then try to update the DLL, you will get an "access denied" error. The only way to release the lock is to stop the Web server. So, during development you may be stopping and re-starting the Web server a lot.


Building Active Server components is not hard, but it does require a high-end development platform that includes Visual Basic 5.0 Enterprise Edition and Internet Information Server running on Windows NT 4.0. In general, construction involves creating classes, implementing a couple of IIS-specific methods, and compiling them into an ActiveX DLL. Additionally, when you have built your components, using them is easier than building them and requires just a few lines of server-side scripting in a Web page.

Related links

Thornton Rose currently works in the MIS department at AGCO Corporation, where he is a software developer and the Webmaster for the intranet. He can be reached via e-mail at trose@avana.net.

Page 1 of 3

This article was originally published on April 30, 1998

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date