How to set custom registry in VSTO Word Plugin project?

2

I am developing VSTO Word plugin project. When I build the project, it automatically creates 4 registry at HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\My.Registry location and those are as under.

Name             Type                 Data
--------------   --------------       ------------------------
(Default)        REG_SZ               (value not set)
Description      REG_SZ               My.Registry
FriendlyName     REG_SZ               My.Registry
LoadBehavior     REG_DWORD            0x00000003 (3)
Manifest         REG_SZ               file:///D:/LearningProject/My.Registry/bin/debug/My.Registry.vsto|vstolocal

Now I want to add anther registry at same path with different key value pair. I do not know how this registries are being generated. So that I cannot make my custom registry along with these existing registries.

Need guidance.

c#
registry
vsto
word-addins
asked on Stack Overflow May 9, 2019 by theDarthVader

1 Answer

1

Since you are building the projcect and it adds those values, maybe check under the prebuild/postbuild events in Visual studio

Visual studo build events

If that is not the case, you might need to do a simple registry entry on startup of the application

public static bool WriteRegistryValue<T>(RegistryHive hive, string key, string value, RegistryValueKind kind, T data)
        {
            bool success = false;

            using (RegistryKey baseKey = RegistryKey.OpenRemoteBaseKey(hive, String.Empty))
            {
                if (baseKey != null)
                {
                    using (RegistryKey registryKey = baseKey.OpenSubKey(key, RegistryKeyPermissionCheck.ReadWriteSubTree))
                    {
                        if (registryKey == null)
                        {
                            using (RegistryKey createdRegistryKey = baseKey.CreateSubKey(key, true))
                            {
                                registryKey.SetValue(value, data as string);
                            }
                        }
                        else
                        {
                            registryKey.SetValue(value, data as string);
                        }
                        success = true;

                    }
                }
            }
            return success;
        }
answered on Stack Overflow May 9, 2019 by mahlatse

User contributions licensed under CC BY-SA 3.0