Skip to content

Commit c39272e

Browse files
authored
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
1 parent 91bf01d commit c39272e

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
@@ -1594,6 +1594,7 @@ _registryReadLegacyEnvironment(const SearchInfo *search, HKEY root, EnvironmentI
15941594

15951595
int count = swprintf_s(realTag, tagLength + 4, L"%s-32", env->tag);
15961596
if (count == -1) {
1597+
debug(L"# Failed to generate 32bit tag\n");
15971598
free(realTag);
15981599
return RC_INTERNAL_ERROR;
15991600
}
@@ -1749,10 +1750,18 @@ appxSearch(const SearchInfo *search, EnvironmentInfo **result, const wchar_t *pa
17491750
exeName = search->windowed ? L"pythonw.exe" : L"python.exe";
17501751
}
17511752

1752-
if (FAILED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, buffer)) ||
1753-
!join(buffer, MAXLEN, L"Microsoft\\WindowsApps") ||
1753+
// Failure to get LocalAppData may just mean we're running as a user who
1754+
// doesn't have a profile directory.
1755+
// In this case, return "not found", but don't fail.
1756+
// Chances are they can't launch Store installs anyway.
1757+
if (FAILED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, buffer))) {
1758+
return RC_NO_PYTHON;
1759+
}
1760+
1761+
if (!join(buffer, MAXLEN, L"Microsoft\\WindowsApps") ||
17541762
!join(buffer, MAXLEN, packageFamilyName) ||
17551763
!join(buffer, MAXLEN, exeName)) {
1764+
debug(L"# Failed to construct App Execution Alias path\n");
17561765
return RC_INTERNAL_ERROR;
17571766
}
17581767

@@ -1982,6 +1991,7 @@ collectEnvironments(const SearchInfo *search, EnvironmentInfo **result)
19821991
EnvironmentInfo *env = NULL;
19831992

19841993
if (!result) {
1994+
debug(L"# collectEnvironments() was passed a NULL result\n");
19851995
return RC_INTERNAL_ERROR;
19861996
}
19871997
*result = NULL;
@@ -2276,6 +2286,7 @@ int
22762286
selectEnvironment(const SearchInfo *search, EnvironmentInfo *root, EnvironmentInfo **best)
22772287
{
22782288
if (!best) {
2289+
debug(L"# selectEnvironment() was passed a NULL best\n");
22792290
return RC_INTERNAL_ERROR;
22802291
}
22812292
if (!root) {

0 commit comments

Comments
 (0)