Skip to content

Commit 4ed4fa8

Browse files
committed
Fix the Word addin getting disabled in a second place.
1 parent d8d1b76 commit 4ed4fa8

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

dictation_server.pyw

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from ctypes import wintypes
44
import natlink
55
import os
66
import rpyc
7+
import struct
78
import subprocess
89
import sys
910
import win32api
@@ -33,13 +34,37 @@ def fix_addin():
3334
# Sometimes Word disables the addin, so it is impossible to
3435
# dictate into Word. This is likely a bug in the addin, but I
3536
# don't have a choice but to work around it.
37+
addin_name = 'Dragon.Word2000Support.1'
3638
with _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
3739
r'Software\Microsoft\Office\Word\Addins',
3840
0, _winreg.KEY_ALL_ACCESS) as addins_key:
3941
try:
40-
_winreg.DeleteKey(addins_key, 'Dragon.Word2000Support.1')
42+
_winreg.DeleteKey(addins_key, addin_name)
43+
logging.info('Rescued Word addin from being disabled')
4144
except WindowsError:
4245
pass
46+
# Another location (http://superuser.com/questions/17557/)
47+
with _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
48+
r'Software\Microsoft\Office\15.0\Word' +
49+
r'\Resiliency\DisabledItems',
50+
0, _winreg.KEY_ALL_ACCESS) as disabled_key:
51+
index = 0
52+
while True:
53+
try:
54+
name, data, rtype = _winreg.EnumValue(disabled_key, index)
55+
format = '3I'
56+
_, dll_len, name_len = struct.unpack_from(format, buffer(data))
57+
format += '%ds%ds' % (dll_len, name_len)
58+
_, _, _, dll_path, dll_name = struct.unpack(format, data)
59+
dll_path = dll_path.decode('utf16').rstrip('\0')
60+
dll_name = dll_name.decode('utf16').rstrip('\0')
61+
if dll_name.lower() == addin_name.lower():
62+
_winreg.DeleteValue(disabled_key, name)
63+
logging.info('Rescued Word addin from Resiliency')
64+
break
65+
index += 1
66+
except WindowsError:
67+
break
4368

4469
def get_document_text(document):
4570
return document.Content.Text.replace('\r\n', '\n').replace('\r', '\n').rstrip()

0 commit comments

Comments
 (0)