PDA

View Full Version : Detecting where in the registry a value came from



neilt17
03-09-2018, 12:21 PM
I have an MSI installer for my add-in which loads some values into the registry for my add-in to read later. For example it stores an install path (where files used with my add-in are put), specified with Name="path", Root="HKLM", and Key="SOFTWARE\my-company\my-addin-name".

These entries end up stored here: "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\my-company\my-addin-name"

When I try to retrieve these values (using Chip Pearson's functions (http://www.cpearson.com/excel/Registry.htm) - which use the advapi32 library, or the WScript functions (https://msdn.microsoft.com/en-us/library/x05fawxd(v=vs.84).aspx)), all works fine and I retrieve the values correctly:


Dim oWS As Object
Dim WSValue as string
Set oWS = CreateObject("WScript.Shell")
WSValue = oWS.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\my-company\my-addin-name\path")

Unfortunately if at any point the VBA add-in writes something to HKLM using this same path, for example:


oWS.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\my-company\my-addin-name\customer", "Fred Blogs", "REG_SZ"

and then tries to retrieve the value stored at "HKEY_LOCAL_MACHINE\SOFTWARE\my-company\my-addin-name\path", that value is no longer found. On inspection of the registry, it turns out that the new values have been stored in "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\M ACHINE\Software\Wow6432Node\my-company\my-addin-name" - and since there is now something for my-addin-name in that part of the registry anything stored in the original location is ignored - whether I use the abbreviated location or full path to the location ("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\my-company\my-addin-name").

In normal use, the add-in should never write to the HKLM registry hive - it's only happening in testing where I need the add-in to change some values stored in there. Still, it's worrying that this can happen - and so far I've found no way for the add-in to detect this.

My questions are: is there any way to find out what the full path to the registry location was when a key was retrieved using the abbreviated path to the location, and is there any way at all that I can access any values that are stored in the original registry location once office has created a click-to-run entry?