Problems programming to the registry using RegEnumKey

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I am experiencing problems trying to do something with the registry and
would really appreciate any help that you guys can provide.

Essentially I am writing an add-in for exclusive use within my department
at work, and as the add-in gets re-released an extra item appears in the
Add-Ins dialog box in Excel. I am trying to delete the old unused items
automatically (I know that they can be deleted by hand by looking in
Software\Microsoft\office\11.0\Excel\Add-In Manager).

What I would like to do is enumerate all add-ins listed in the Add-In
Manager section in the registry, and where the add-in matches a previous
version of my Add-In and would like to delete the item from the registry so
that it doesn't appear in the Add-In dialog box anymore. I have all of the
API information that I know I will need by looking at other posts in the
newsgroups, but I can't get the RegEnumKey to work so that it provides a
list of all add-ins in the section.

The code I am trying to use to achieve this is as follows (I haven't got to
the deleting part).

Public Sub GetKeys()
Dim x, strSection As String

strSection = "Software\Microsoft\Office\" & Application.Version & "\Excel\
Add-In manager\"

x = EnumerateValues(HKEY_CURRENT_USER, strSection)
MsgBox UBound(x)
End Sub

Public Function EnumerateKeys(ByVal HKey As Long, ByVal hSubKey As String)
Dim Result As Long
Dim OpenKey As Long
Dim KeyName As String
Dim KeyNames() As String
Dim KeyCount As Long
ReDim KeyNames(0) As String

KeyCount = 0

Result = RegOpenKey(HKey, hSubKey, OpenKey)

Do Until Result <> 0
KeyName = Space(255)
Result = RegEnumKey(OpenKey, KeyCount, KeyName, 255)

If Result = 0 Then
KeyNames(UBound(KeyNames)) = Left(KeyName, Len(Trim(KeyName)) - 1)
ReDim Preserve KeyNames(UBound(KeyNames) + 1) As String
KeyCount = KeyCount + 1
End If
Loop


If UBound(KeyNames) > 0 Then ReDim Preserve KeyNames(UBound(KeyNames) - 1)
As String
KeyCount = KeyCount - 1

RegCloseKey OpenKey

End Function


If anyone can help with this I will be extremely grateful.
Many thanks,
Simon Livings.

--
Message posted via http://www.officekb.com
.



Relevant Pages

  • Re: Open a pdf file from Excel VB
    ... ' Registry value type definitions ... ' handles string, ... Dim lKeyValue As Long ... ' Launch Acrobat and required file ...
    (microsoft.public.excel.programming)
  • Re: Registry enigma - please help!
    ... Popular opinion seems to be against using the registry now a days. ... Dim vc2Count As Integer = keyNSX.ValueCount ... For Each valueName As String In keyNS.GetValueNames ... ' Create data for the NSNST subkey. ...
    (microsoft.public.dotnet.languages.vb)
  • Addin Issues
    ... Delete the current 'add-in' in the XLStart folder ... Private Function Delete_XLSTART_XLA ... Dim x As String, MyName As String ...
    (microsoft.public.excel.programming)
  • Re: Save versions
    ... Put the code in a new module located either in normal.dot or in a template ... An add-in is a more professional approach if others will ... > Dim theRecSet As ADODB.Recordset ... > Dim strDataLocation As String ...
    (microsoft.public.word.vba.general)
  • Re: An event raise twice when click the button.
    ... I wrote that the add-in work good in one machine but in another I have the ... Private Sub AddinInstance_OnAddInsUpdateAs Variant) ... Private strProgId As String ... Dim tempMailItem As Outlook.MailItem ...
    (microsoft.public.office.developer.outlook.vba)