[Python-checkins] bpo-38359: Ensures pyw.exe launcher reads correct registry key (GH-16561)

Steve Dower webhook-mailer at python.org
Thu Oct 3 11:31:25 EDT 2019


https://github.com/python/cpython/commit/353fb1ecbfd58752dabae115c4964095e1e35e5f
commit: 353fb1ecbfd58752dabae115c4964095e1e35e5f
branch: master
author: Steve Dower <steve.dower at python.org>
committer: GitHub <noreply at github.com>
date: 2019-10-03T08:31:21-07:00
summary:

bpo-38359: Ensures pyw.exe launcher reads correct registry key (GH-16561)

files:
A Misc/NEWS.d/next/Windows/2019-10-03-08-04-14.bpo-38359.wzwsl_.rst
M PC/launcher.c

diff --git a/Misc/NEWS.d/next/Windows/2019-10-03-08-04-14.bpo-38359.wzwsl_.rst b/Misc/NEWS.d/next/Windows/2019-10-03-08-04-14.bpo-38359.wzwsl_.rst
new file mode 100644
index 0000000000000..ab6f29baf5358
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2019-10-03-08-04-14.bpo-38359.wzwsl_.rst
@@ -0,0 +1 @@
+Ensures ``pyw.exe`` launcher reads correct registry key.
diff --git a/PC/launcher.c b/PC/launcher.c
index a260860f3c27a..2749a4e705467 100644
--- a/PC/launcher.c
+++ b/PC/launcher.c
@@ -141,6 +141,8 @@ static wchar_t * get_env(wchar_t * key)
 }
 
 #if defined(_DEBUG)
+/* Do not define EXECUTABLEPATH_VALUE in debug builds as it'll
+   never point to the debug build. */
 #if defined(_WINDOWS)
 
 #define PYTHON_EXECUTABLE L"pythonw_d.exe"
@@ -154,10 +156,12 @@ static wchar_t * get_env(wchar_t * key)
 #if defined(_WINDOWS)
 
 #define PYTHON_EXECUTABLE L"pythonw.exe"
+#define EXECUTABLEPATH_VALUE L"WindowedExecutablePath"
 
 #else
 
 #define PYTHON_EXECUTABLE L"python.exe"
+#define EXECUTABLEPATH_VALUE L"ExecutablePath"
 
 #endif
 #endif
@@ -297,8 +301,12 @@ _locate_pythons_for_key(HKEY root, LPCWSTR subkey, REGSAM flags, int bits,
                 }
                 data_size = sizeof(ip->executable) - 1;
                 append_name = FALSE;
-                status = RegQueryValueExW(ip_key, L"ExecutablePath", NULL, &type,
+#ifdef EXECUTABLEPATH_VALUE
+                status = RegQueryValueExW(ip_key, EXECUTABLEPATH_VALUE, NULL, &type,
                                           (LPBYTE)ip->executable, &data_size);
+#else
+                status = ERROR_FILE_NOT_FOUND; /* actual error doesn't matter */
+#endif
                 if (status != ERROR_SUCCESS || type != REG_SZ || !data_size) {
                     append_name = TRUE;
                     data_size = sizeof(ip->executable) - 1;



More information about the Python-checkins mailing list