logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Registry functions do not work with IIS

Posted on
2/18/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
All
Product:
N/A



GetSetting & SaveSetting methods don't work, while running under IIS.

This is a gotcha that usually drives developers nuts.  The code seems right, but GetSetting returns absolutely nothing, even though there is a value in the registry.  Well, what happens is that whenever your ActiveX DLL is running under IIS, it only has access to HKEY_LOCAL_MACHINE or HKEY_USERS branches.  Since the GetSetting and other similar registry access functions manage the HKEY_CURRENT_USER\Software\VB and VBA Program Settings branch, you are out of luck

This is alluded to in Microsoft Knowledge Base article Q248348.  The article then suggests a half-baked solution that involves the use of yet another external library (Windows Scripting Host).  This solution sets you up for more distribution headaches because there is a new version of Windows Scripting Host everytime new Internet Explorer or OS ships.

We suggest that you download the most complete Registry access class, we've seen to date from vbAccelerator.comExcept that if you are going to use this class over the network, you should add the following two methods to reduce the number of round trips and to be able to get the data in one shot.


Public Function ReadKey(Optional ValueKey As String = "", _
                        Optional SectionKey As String = "", _
                        Optional ClassKey As ERegistryClassConstants = 0, _
                        Optional Default As Variant) As Variant

    Dim sValueKey As String
    Dim sSectionKey As String
    Dim eClassKey As ERegistryClassConstants
    Dim vDefault As Variant
    
    'temporarily replace the property values with the passed in ones
    If Len(ValueKey) > 0 Then
        sValueKey = Me.ValueKey
        Me.ValueKey = ValueKey
    End If
    
    If Len(SectionKey) > 0 Then
        sSectionKey = Me.SectionKey
        Me.SectionKey = SectionKey
    End If
    
    If ClassKey <> 0 Then
        eClassKey = Me.ClassKey
        Me.ClassKey = ClassKey
    End If
    
    If Not IsMissing(Default) Then
        vDefault = Me.Default
        Me.Default = Default
    End If
    
    ReadKey = Me.Value
    
    'reset the property values to its original
    If Len(ValueKey) > 0 Then Me.ValueKey = sValueKey    
    If Len(SectionKey) > 0 Then Me.SectionKey =  sSectionKey  
    If ClassKey > 0 Then Me.ClassKey =  eClassKey 
    If Not IsMissing(Default) > 0 Then Me.Default =  vDefault  
End Function  

Public Sub WriteKey(Value As Variant,  _ 
                        Optional ValueKey As String = "",  
                        Optional SectionKey As String = "", _ 
                        Optional ClassKey As ERegistryClassConstants = 0)
    
    Dim vValue As Variant    
    Dim sValueKey As String 
    Dim sSectionKey As String 
    Dim eClassKey As ERegistryClassConstants  
    
    'temporarily replace the  property values with the passed in  ones 
    If Len(ValueKey) > 0 Then 
        sValueKey = Me.ValueKey 
        Me.ValueKey = ValueKey 
    End If  
	
    If Len(SectionKey) > 0 Then 
        sSectionKey = Me.SectionKey 
        Me.SectionKey = SectionKey 
    End If 
	
    If ClassKey <> 0  Then
        eClassKey = Me.ClassKey 
        Me.ClassKey =  ClassKey
    End If
    
    Me.Value = Value
	
    'reset the property values  to its original  
    If Len(ValueKey) > 0 Then Me.ValueKey = sValueKey  
    If Len(SectionKey) > 0 Then Me.SectionKey = sSectionKey  
    If ClassKey > 0 Then Me.ClassKey = eClassKey

End Sub

P.S.  DeleteSetting or GetAllSettings methods don't work under these conditions either, so don't try it.

 


Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word: