Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 17,002 times

Related Categories

Determine programmatically whether a component is installed

Sometimes you may need to check at runtime whether a particular component is installed. For example, you might have written a common code library that sends email in certain circumstances. But rather than allow it to break if you attempt to use it from a new server, you might wish to check for the CDONTS NewMail object programmatically first, and then send the email message if and only if the component is present. You can use the following function to make this determination. Simply pass the ProgId (the string you'd normally pass as the argument of the CreateObject method) to the IsComponentInstalled function and the Boolean return value will indicate whether the component is available for your use.

<% Option Explicit

Function IsComponentInstalled(ProgId)
    Dim tmpObject

    On Error Resume Next

    Set tmpObject = Server.CreateObject(ProgId)
    If Err.Number = 0 Then
        IsComponentInstalled = True
    Else
        IsComponentInstalled = False
    End If
    Set tmpObject = Nothing
End Function

If IsComponentInstalled("CDONTS.NewMail") Then
    Response.Write "We'll send the email message now ..."
    '...
Else
    Response.Write "We'll *not* send the email message ..."
    '...
End If
%>

© 2001 Element K Journals, a division of Element K Press LLC ("Element K"). Element K and the Element K logo are trademarks of Element K LLC

Comments