Skip to content

Commit 90d1037

Browse files
gh-115049: Fix py.exe failing when user has no LocalAppData. (GH-115185)
Also ensure we always display a debug message or error for RC_INTERNAL_ERROR (cherry picked from commit c39272e) Co-authored-by: Steve Dower <[email protected]>
1 parent 5ec271d commit 90d1037

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes ``py.exe`` launcher failing when run as users without user profiles.

PC/launcher2.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ _registryReadLegacyEnvironment(const SearchInfo *search, HKEY root, EnvironmentI
15761576

15771577
int count = swprintf_s(realTag, tagLength + 4, L"%s-32", env->tag);
15781578
if (count == -1) {
1579+
debug(L"# Failed to generate 32bit tag\n");
15791580
free(realTag);
15801581
return RC_INTERNAL_ERROR;
15811582
}
@@ -1731,10 +1732,18 @@ appxSearch(const SearchInfo *search, EnvironmentInfo **result, const wchar_t *pa
17311732
exeName = search->windowed ? L"pythonw.exe" : L"python.exe";
17321733
}
17331734

1734-
if (FAILED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, buffer)) ||
1735-
!join(buffer, MAXLEN, L"Microsoft\\WindowsApps") ||
1735+
// Failure to get LocalAppData may just mean we're running as a user who
1736+
// doesn't have a profile directory.
1737+
// In this case, return "not found", but don't fail.
1738+
// Chances are they can't launch Store installs anyway.
1739+
if (FAILED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, buffer))) {
1740+
return RC_NO_PYTHON;
1741+
}
1742+
1743+
if (!join(buffer, MAXLEN, L"Microsoft\\WindowsApps") ||
17361744
!join(buffer, MAXLEN, packageFamilyName) ||
17371745
!join(buffer, MAXLEN, exeName)) {
1746+
debug(L"# Failed to construct App Execution Alias path\n");
17381747
return RC_INTERNAL_ERROR;
17391748
}
17401749

@@ -1956,6 +1965,7 @@ collectEnvironments(const SearchInfo *search, EnvironmentInfo **result)
19561965
EnvironmentInfo *env = NULL;
19571966

19581967
if (!result) {
1968+
debug(L"# collectEnvironments() was passed a NULL result\n");
19591969
return RC_INTERNAL_ERROR;
19601970
}
19611971
*result = NULL;
@@ -2250,6 +2260,7 @@ int
22502260
selectEnvironment(const SearchInfo *search, EnvironmentInfo *root, EnvironmentInfo **best)
22512261
{
22522262
if (!best) {
2263+
debug(L"# selectEnvironment() was passed a NULL best\n");
22532264
return RC_INTERNAL_ERROR;
22542265
}
22552266
if (!root) {

0 commit comments

Comments
 (0)