Repository: nvaccess/nvda

Issue:
UIA and consoles: product name and version retrieval fails because conhost does not exist in the named path
Hi,

I consider the following a huge regression from ongoing UIA console work:

### Steps to reproduce:

1. Enable UIA support for consoles.
2. From a console window, press NVDA+F1 to have NVDA record developer info.
3. Take a look at product name and version fields.

### Actual behavior:
The following exceptions are logged:

appModule: <'appModuleHandler' (appName 'conhost', process ID 8672) at address 710e0d0>
appModule.productName: exception: The file C:\Windows\System32\conhost.exe does not exist
appModule.productVersion: exception: The file C:\Windows\System32\conhost.exe does not exist

### Expected behavior:

The console app and its version should be announced as follows (done from WSL/Ubuntu):

appModule: <'appModuleHandler' (appName u'ubuntu', process ID 7308) at address 49647f0>
appModule.productName: u'CanonicalGroupLimited.UbuntuonWindows'
appModule.productVersion: u'1804.2019.521.0'

### System configuration
#### NVDA installed/portable/running from source:
Installed and portable

#### NVDA version:
Alpha.18420 and 2019.2

#### Windows version:
Windows 10 Version 1903

#### Name and version of other software in use when reproducing the issue:
WSL/Ubuntu 18.04 and other console apps

#### Other information about your system:
The log output is different from a stock installation due to Windows 10 App Essentials changes implemented.

### Other questions
#### Does the issue still occur after restarting your PC?
Yes

#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Expected behavior in NVDA 2019.1.1 or 2019.2 or later with console support set to legacy.

### Additional context:
Although users might be able to determine what kind of console app is in use through prompts, it is sometimes helpful to figure out exactly what is in use. This is important now that we have Windows Subsystem for Linux (WSL) and Windows Terminal Preview - Bash uses the same prompt character unless configured otherwise, and Windows Terminal will allow users to open different consoles as tabs.

Thanks.


Discussion:
CC @CodeOfDusk

Resolving patch:
diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py
--- a/source/NVDAObjects/UIA/__init__.py
+++ b/source/NVDAObjects/UIA/__init__.py
@@ -1410,6 +1410,15 @@ def _get_table(self):
 		raise NotImplementedError
 
 	def _get_processID(self):
+		if self.windowClassName == 'ConsoleWindowClass':
+			# #10115: The UIA implementation for Windows console windows exposes the process ID of conhost,
+			# not the actual app it is hosting.
+			# Therefore, to work around this, for console windows, we fallback to getting processID from the window
+			# rather than from UIA.
+			# Note that we can't do this hack in the WinConsoleUIA NVDAObject
+			# Because the appModule is already created and cached
+			# before the UIA NVDAObject is morphed into the specific WinConsoleUIA class.
+			return super().processID
 		return self.UIAElement.cachedProcessId
 
 	def _get_location(self):


Test patch: