Library code snippets
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
%>
Related articles
Related discussion
-
Header and Footer in Web page print
by fhajaj (4 replies)
-
help me to get simple requirement
by Slicksim (1 replies)
-
Gridview -> Template Field -> Button
by antti.simonen (1 replies)
-
Classic ASP : Page expires
by chezhian_in05 (0 replies)
-
ASP VS PHP
by paulfp (9 replies)
Related podcasts
-
ASP.NET Caching and Performance
Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Technical Support Engineer EMEA
in Reading (£50K-£50K per annum) -
Solutions Engineer
in Reading (£50K-£60K per annum)
This thread is for discussions of Determine programmatically whether a component is installed.