I'm trying to do something incredibly simple, read one string value from the Windows Registry and am failing miserably.
I am trying to find the installation path of the ImageMagick software suite which is installed on my test PC.
I can read and write to the corresponding registry setting in regedit.exe here:
So, I decided to use the simplest method in VBA to read a registry value, WScript. Here is the code:
Function GetImageMagickInstallPath() As String
Dim oWScript As Object
Set oWScript = CreateObject("WScript.Shell")
GetImageMagickInstallPath = oWScript.RegRead("HKLM\SOFTWARE\ImageMagick\Current\BinPath")
But this fails with the following error message:
Run-time error ‘-2147024894 (80070002)’:
Invalid root in registry key
This error appears to occur when the key path is misspelt but it isn't.
I then went on to try the more complex WinAPI method as documented here https://support.microsoft.com/en-us/kb/145679
in VBA and keep getting returned the error ERROR_BADKEY
With both methods, I can read settings in the HKCU hive, for example under HKEY_CURRENT_USER\Software
\VB and VBA Program Settings
Why can't I read from the HKLM hive?