Problems programming to the registry using RegEnumKey
- From: "Simon Livings via OfficeKB.com" <forum@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 18 Apr 2005 09:24:45 GMT
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
.
- Follow-Ups:
- Re: Problems programming to the registry using RegEnumKey
- From: keepITcool
- Re: Problems programming to the registry using RegEnumKey
- From: Simon Livings via OfficeKB.com
- Re: Problems programming to the registry using RegEnumKey
- Prev by Date: How to get value of a excel-fields without open the workbook.
- Next by Date: Re: Problems programming to the registry using RegEnumKey
- Previous by thread: How to get value of a excel-fields without open the workbook.
- Next by thread: Re: Problems programming to the registry using RegEnumKey
- Index(es):
Relevant Pages
|