Skip to content

Commit 3cb9d41

Browse files
Fix: Improve hardcoded "Program Files" string
This should solve issues with non-english Wine prefixes and custom program files locations, as it resolves to environment variables instead.
1 parent 4231823 commit 3cb9d41

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/wrapper.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ static inline wchar_t *replace_smart(wchar_t *str, wchar_t *sub, wchar_t *rep) {
4646
return b ? b : buf;
4747
}
4848

49+
// Function to check if the process is running under WOW64 (32-bit process on 64-bit Windows)
50+
BOOL is_wow64() {
51+
BOOL bIsWow64 = FALSE;
52+
IsWow64Process(GetCurrentProcess(), &bIsWow64);
53+
return bIsWow64;
54+
}
55+
56+
// Function to get the correct Program Files path
57+
void get_program_files_path(wchar_t *path, size_t size) {
58+
if (is_wow64()) {
59+
ExpandEnvironmentStringsW(L"%ProgramW6432%\\PowerShell\\7\\pwsh.exe", path, (DWORD)size);
60+
} else {
61+
ExpandEnvironmentStringsW(L"%ProgramFiles%\\PowerShell\\7\\pwsh.exe", path, (DWORD)size);
62+
}
63+
}
64+
4965
__attribute__((externally_visible)) // for -fwhole-program
5066
int mainCRTStartup(void) {
5167
BOOL read_from_stdin = FALSE;
@@ -56,7 +72,9 @@ int mainCRTStartup(void) {
5672
int i, j, argc;
5773

5874
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
59-
ExpandEnvironmentStringsW(L"%SystemDrive%\\Program Files\\PowerShell\\7\\pwsh.exe", pwsh_pathW, MAX_PATH + 1);
75+
76+
// Get the correct Program Files path based on the process architecture
77+
get_program_files_path(pwsh_pathW, MAX_PATH + 1);
6078

6179
// Set environment variable to disable color rendering output
6280
_wputenv_s(L"NO_COLOR", L"1");

0 commit comments

Comments
 (0)