Skip to content

Commit 6c7463f

Browse files
authored
Merge 655d728 into 8207a49
2 parents 8207a49 + 655d728 commit 6c7463f

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

source/COMRegistrationFixes/__init__.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2018-2020 NV Access Limited
2+
# Copyright (C) 2018-2021 NV Access Limited
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

@@ -36,22 +36,37 @@ def registerServer(fileName,wow64=False):
3636
else:
3737
log.debug("Registered %s"%fileName)
3838

39-
def applyRegistryPatch(fileName,wow64=False):
39+
def apply32bitRegistryPatch(fileName: str) -> None:
40+
"""Applies the registry patch with the given file name, using 32-bit regedit.
41+
@param fileName: the path to the .reg file
42+
@type fileName: str
4043
"""
41-
Applies the registry patch with the given file name
42-
using regedit.
44+
if not os.path.isfile(fileName):
45+
raise FileNotFoundError(f"Cannot apply 32-bit registry patch: {fileName} not found.")
46+
# On 32-bit systems, regedt32 is in System32. On 64-bit systems, SysWOW64 will redirect to the 32-bit version.
47+
regedit = os.path.join(systemRoot, "System32", "regedt32.exe")
48+
try:
49+
subprocess.check_call([regedit, "/s", fileName])
50+
except subprocess.CalledProcessError as e:
51+
log.error(f"Error applying 64-bit registry patch from {fileName} with {regedit}: {e}")
52+
else:
53+
log.debug(f"Applied 32-bit registry patch from {fileName}")
54+
55+
def apply64bitRegistryPatch(fileName: str) -> None:
56+
"""Applies the registry patch with the given file name, using 64-bit regedit.
4357
@param fileName: the path to the .reg file
4458
@type fileName: str
4559
"""
4660
if not os.path.isfile(fileName):
47-
raise FileNotFoundError(f"Cannot apply registry patch, {fileName} not found.")
48-
regedit=os.path.join(sysWow64 if wow64 else systemRoot,'regedit.exe')
61+
raise FileNotFoundError(f"Cannot apply 64-bit registry patch: {fileName} not found.")
62+
# On 64-bit systems, SysWOW64 provides 32-bit apps with a virtual directory to reach 64-bit executables.
63+
regedit = os.path.join(systemRoot, "Sysnative", "regedt32.exe")
4964
try:
50-
subprocess.check_call([regedit,'/s',fileName])
65+
subprocess.check_call([regedit, "/s", fileName])
5166
except subprocess.CalledProcessError as e:
52-
log.error("Error applying registry patch: %s with %s, %s"%(fileName,regedit,e))
67+
log.error(f"Error applying 64-bit registry patch from {fileName} with {regedit}: {e}")
5368
else:
54-
log.debug("Applied registry patch: %s with %s"%(fileName,regedit))
69+
log.debug(f"Applied 64-bit registry patch from {fileName}")
5570

5671

5772
OLEACC_REG_FILE_PATH = os.path.join(globalVars.appDir, "COMRegistrationFixes", "oleaccProxy.reg")
@@ -64,10 +79,11 @@ def fixCOMRegistrations():
6479
OSMajorMinor = (winVer.major, winVer.minor)
6580
log.debug("Fixing COM registration for Windows %s.%s, %s"%(OSMajorMinor[0],OSMajorMinor[1],"64 bit" if is64bit else "32 bit"))
6681
# Commands taken from NVDA issue #2807 comment https://github.com/nvaccess/nvda/issues/2807#issuecomment-320149243
82+
# And also the discussion in #9039 https://github.com/nvaccess/nvda/issues/9039
6783
# OLEACC (MSAA) proxies
68-
applyRegistryPatch(OLEACC_REG_FILE_PATH)
84+
apply32bitRegistryPatch(OLEACC_REG_FILE_PATH)
6985
if is64bit:
70-
applyRegistryPatch(OLEACC_REG_FILE_PATH, wow64=True)
86+
apply64bitRegistryPatch(OLEACC_REG_FILE_PATH)
7187
# IDispatch and other common OLE interfaces
7288
registerServer(os.path.join(system32,'oleaut32.dll'))
7389
registerServer(os.path.join(system32,'actxprxy.dll'))

0 commit comments

Comments
 (0)