Can't read Registry HKLM\SOFTWARE\Microsoft\Office

RDH

New member
Local time
Today, 01:41
Joined
Dec 5, 2024
Messages
3
I can read from other entries within HKLM\SOFTWARE\Microsoft with no problem, but if I go into Office or go deeper (using code) I receive an error.

Run-time error '-2147024894 (80070002)';
Unable to open registry key "HKLM\SOFTWARE\Microsoft\Office" for reading.

Does Microsoft have this blocked so I can not be read using VBA ???

Basically ... this is what I'm using.
Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
MsgBox WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Office")
Set WshShell = Nothing

Thanks for any help on this,
RDH
 
Have you checked that path exists?

Edit: Seems to have to include a full path?

Code:
Public Function ReadReg()
Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
MSGBOX WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Office\16.0\Common\FileIO\OfficeCollaborationSyncIntegrationEnabled")
Set WshShell = Nothing
End Function
MSGBOX returned 2

1733423097221.png
 

Attachments

  • 1733423062259.png
    1733423062259.png
    9.5 KB · Views: 40
Last edited:
More times than i have fingers ....
I can go into the registry editor and manually navigate to the any entry within HKLM\SOFTWARE\Microsoft\Office or deeper, copy the path as text and paste it into the code to be assured i have no typos.

An example would be:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\Configuration\InstallID

I can navigate to it manually to veiw the value of: 476FE0B9-5BD6-4459-AD9C-05183875E11A
But i receive the error i decscribed in my initial post if I use the code I posted ....

RDH
 
See if this works for you?

Try using the FULL path all the way down to a key.
I think I have proved that that folder is NOT blocked?
FWIW I had the same error with the code from your first post.
 
Have you tried to return a value from the "ClickToRun" location ... as in the last example I posted ?
The entry you posted works for me "HKLM\SOFTWARE\Microsoft\Office\16.0\Common\FileIO\OfficeCollaborationSyncIntegrationEnabled"
But anything from within "HKLM\SOFTWARE\Microsoft\Office\ClickToRun" returns the error I posted.

Thanks,
RDH
 
Last edited:
You should be able to read HKLM without problems, but will need elevated privileges if you want to edit it.

I can read the specific key you mentioned with no issues:

1733440008643.png


Hopefully the code below includes everything needed:

Code:
Option Compare Database
Option Explicit

'This module is used to grab registry settings through VBA using WMI

Public Enum hive
  HKEY_CLASSES_ROOT
  HKEY_CURRENT_USER
  HKEY_LOCAL_MACHINE
  HKEY_USERS
  HKEY_CURRENT_CONFIG
End Enum

'#######################################
Public Function GetHive(hivetype As hive) As Variant
' return enumerated value depending on the hive chosen
  Select Case hivetype
    Case 0
      GetHive = &H80000000  ' HKEY_CLASSES_ROOT
    Case 1
      GetHive = &H80000001  ' HKEY_CURRENT_USER
    Case 2
      GetHive = &H80000002  ' HKEY_LOCAL_MACHINE
    Case 3
      GetHive = &H80000003  ' HKEY_USERS
    Case 4
      GetHive = &H80000005  ' HKEY_CURRENT_CONFIG
  End Select
End Function

Public Function GetStringValFromRegistry(hivetype As hive, registryKey As String, _
    keyValue As String) As String
   
On Error GoTo ErrHandler:
   
'Checks Any String Value from the Registry
'The function GetStringValFromRegistry takes our custom hive type,
'the registry key to retrieve, and the name of the entry whose value we want to retrieve.
'It also includes another function, GetStdRegProv, which calls the WMI service and returns the appropriate object.

Dim objReg As Object
Dim strKeyPath As String
Dim ValueName As String
Dim strValue As String
 
  Set objReg = GetStdRegProv
 
  strKeyPath = registryKey
  ValueName = keyValue
 
  ' put key value into strValue variable
  objReg.GetStringValue GetHive(hivetype), strKeyPath, ValueName, strValue
  GetStringValFromRegistry = strValue
 
Exit_ErrHandler:
    On Error Resume Next
    Exit Function
   
ErrHandler:
    If Err.number >= 0 Then
        MsgBox "Error " & Err.number & ": " & Err.description, vbOKOnly + vbCritical
    End If
    Resume Exit_ErrHandler
 
End Function

Public Function GetStdRegProv() As Object
' http://msdn.microsoft.com/en-us/library/aa394600(VS.85).aspx

Dim strComputer As String
 
  strComputer = "."
 
  Set GetStdRegProv = GetObject("winmgmts:" _
                              & "{impersonationLevel=impersonate}!\\" _
                              & strComputer & "\root\default:StdRegProv")
                             
                             
End Function
 

Attachments

  • 1733439995694.png
    1733439995694.png
    21.6 KB · Views: 43
On researching errors that end with "0002" I find that Windows thinks something is wrong with a file - like a file is missing or damaged.


If you look up code ....0002, it is basically "File Not Found" and of the articles I found, most of them suggest either corruption or an install error for something involved in the registry-related utilities. Try (if you can) doing a Windows Repair.

EDIT: Might also help to verify that Windows Scripting is checked in the references since Access would use that to execute the code you showed us.
 
Does Microsoft have this blocked so I can not be read using VBA ???
You just didn't pay attention to the documentation of RegRead (the link points to a 3rd-party site because I was unable to find the original docs right away.):
You can specify a key-name by ending strName with a final backslash. Do not include a final backslash to specify a value-name.

You are trying to read HKLM\SOFTWARE\Microsoft\Office, which is a key! So, you must append a backslash to the path.
@Gasman's example is working without a trailing backslash, because he is reading a value.
 

Users who are viewing this thread

Back
Top Bottom