Access Visual Studio 2017's private registry hive
Asked Answered
T

2

18

Visual Studio uses a private registry hive instead of "polluting" the system registry - typically found somewhere like this:

C:\Users\Abx\AppData\Local\Microsoft\VisualStudio\15.0_4b0ba1c0\privateregistry.bin

[In order to determine installed extensions we need to look at the following key: Software\Microsoft\VisualStudio\15.0_4b0ba1c0\ExtensionManager\EnabledExtensions]

What is the simplest way to load and access this file by key in C#?

Trilby answered 21/3, 2017 at 0:18 Comment(2)
I'm not sure if there's a managed solution. You might have to P/Invoke RegLoadAppKey. At least according to the "Change: Reduce registry impact" section on this page.Jacobi
Thank you for that information and the link to the "Changes in Visual Studio 2017 extensibility". I think that you are right: there appears to be no managed solution - the RegLoadAppKey method works well, however.Trilby
B
22

To manually review, you can use the regedit.exe application to load the privateregistry.bin file by doing the following:

  1. Launch RegEdit.exe
  2. Select the Computer\HKEY_LOCAL_MACHINE node in the left-hand pane
  3. Select the File | Load Hive... menu item, and load the privateregistry.bin
  4. When prompted for a key name, just type in something like "VSRegHive"
  5. This will load the data into a VSRegHive under the HKLM node
  6. When finished exploring, be sure to select the VSRegHive and select File | Unload Hive... , before exiting the RegEdit.exe utility, otherwise VS will fail to start. Keeping the hive loaded in regedit creates some sort of lock that prevents DevEnv.exe from launching.

To programmatically access the key RegLoadAppKey is indeed your best bet.

Bigeye answered 25/3, 2017 at 3:25 Comment(2)
Where is the VS2017, product key located?Christeenchristel
0. Close all Visual Studio instances that might be using the fileGradus
C
1

I just had a similar problem and found this SO posting. In my experience you have to use the x86 configuration for your project or else you will encounter an exception. I have adapted the code to your problem.

ExternalSettingsManager ext = ExternalSettingsManager.CreateForApplication(@"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe");
SettingsStore store = ext.GetReadOnlySettingsStore(SettingsScope.UserSettings);
var propNames = store.GetPropertyNames(@"ExtensionManager\EnabledExtensions");
store.GetString(...)

In addition to the above method, it seems to be possible to use the "normal" .Net methods for registry access after "CreateForApplication" has been called. Just use something like this:

Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VisualStudio\15.0\ExtensionManager\EnabledExtensions")
Concussion answered 13/2, 2018 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.