none
Accessing registry keys RRS feed

  • Question

  • I have a problem with VSTO, 

    I use this in all my desktop and ASP development usually I open a registry key that is always the same pattern: 

    HKLM\Software\<our company name>\,Application>.

    This is the first time I try to access the registry from a VSTO project and I noticed that in the code below registry is null. i verified and if I try just openeing "Software" it is OK but if I add more, like the comapny name, it becomes null.

     Microsoft.Win32.RegistryKey registry = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Blah\\Blah");

    Is that something related to VSTO ?

    VS 2015, .net 4.5.2

    Thanks

     
    Friday, March 31, 2017 7:16 PM

All replies

  • Hello Johnny,

    Please visit Registry Entries for VSTO Add-ins:

    The required VSTO Add-in registry entries are located under the following registry key for all applications except Visio, where Root is HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE.

    All applications except for Visio

    Office version

    Configuration Path

    32-bit

    Root\Software\Microsoft\Office\application name\Addins\add-in ID

    64-bit

    Root\Software\Wow6432Node\Microsoft\Office\application name\Addins\add-in ID

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 3, 2017 2:38 AM
    Moderator
  • Obviously the question was not clear, I will rephrase it:

    Within a VSTO can you or can you not read registry keys other than the add-in keys ?

    Wednesday, May 31, 2017 12:39 PM
  • Hello,

    Sorry to misunderstand the issue.

    According to my test result, we could only access registry keys for current users.

    Access is denied when accessing registry under local machine.

    I am using the following code in the ThisAddIn_Startup and test ClickOnce deployment for current user and MSI deployment for AllUsers.

                Microsoft.Win32.RegistryKey key1 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Office", true);
                if (key1 == null)
                {
                    System.Windows.Forms.MessageBox.Show("CurrentUser No Success");
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("CurrentUser Success");
                }
                try
                {
                    Microsoft.Win32.RegistryKey key2 = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Office", true);
                    if (key2 == null)
                    {
                        System.Windows.Forms.MessageBox.Show("LocalMachine No Success");
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("LocalMachine Success");
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.ToString());
                }

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 1, 2017 2:51 AM
    Moderator