Home » Questions » Computers [ Ask a new question ]

How do I disable an add-in in Word?

How do I disable an add-in in Word?

Word has a disabled add-ins function (Help | About | Disabled Items).

Asked by: Guest | Views: 257
Total answers/comments: 2
bert [Entry]

"I was trying to figure out the binary format of the values in the DisabledItems key myself and your post here got me on the right track. I however think the format is a bit different from how you see it, at least in Office 2010.
As far as I can tell the format is like this:

The first four bytes are a 32-bit integer. It usually seems to have the value 1. I'm not sure what purpose it has.

The next four bytes are a 32-bit integer that tells us the length of the dll path in bytes, including the terminating character (null or 0x0000).

The next four bytes are a 32-bit integer that tells us the length of the friendly name in bytes, including the terminating character (null or 0x0000).

The next sequence of bytes is a null-terminated big-endian unicode string containing the path to the add-in dll. For some reason this path always seems to contain only lowercase characters.

The next sequence of bytes is a null-terminated big-endian unicode string containing the friendly name of the add-in.

I've been able to successfully hard-disable an add-in using the following C# code:
string path = ""<full path to add-in dll>"".ToLower();
string friendlyName = ""<add-in friendly name>"";

MemoryStream stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(1); // type of disabled item : 1 => Add in / 2 => Document / 3 => Task pane
writer.Write((path.Length * 2) + 2); // Path length, 2 bytes per character
writer.Write((friendlyName.Length * 2) + 2); // Friendly name length
writer.Write(Encoding.Unicode.GetBytes(path)); // Path
writer.Write(Convert.ToInt16(0)); // null terminator
writer.Write(Encoding.Unicode.GetBytes(friendlyName)); // Friendly name
writer.Write(Convert.ToInt16(0)); // null terminator
writer.Close();

// Version numbers: 11.0 = Office 2003, 12.0 = Office 2007, 14.0 = Office 2010
RegistryKey key = Registry.CurrentUser.OpenSubKey(@""Software\Microsoft\Office\14.0\Word\Resiliency\DisabledItems"", true);
key.SetValue(""63CB962"", stream.ToArray(), RegistryValueKind.Binary);
key.Close();

A similar approach can be used to decode the dll path of an existing value like so:
// Let 'bytes' be a byte array containing the binary registry value
BinaryReader binaryReader = new BinaryReader(new MemoryStream(bytes));
binaryReader.ReadInt32(); // Read the first four bytes and ignore
int pathLength = binaryReader.ReadInt32(); // The next four bytes are the length of the path
binaryReader.Close();
if (bytes.Length >= 12 + pathLength)
{
string path = Encoding.Unicode.GetString(bytes, 12, pathLength - 2);
}"
bert [Entry]

"Note that Eirikur's code works only if the Resiliency\DisabledItems subkey is in place. It looks like Word will add/remove this entire subkey when it disables/enables. So, if you get an exception running the code, you probably need to add the subkey first.

(My post here should probably get moderated, it belongs as a comment but I don't have enough points! Bad start)"