diff --git a/dll/win32/shell32/shlexec.cpp b/dll/win32/shell32/shlexec.cpp index 3feab9c2ff6..3514c9c380a 100644 --- a/dll/win32/shell32/shlexec.cpp +++ b/dll/win32/shell32/shlexec.cpp @@ -2457,12 +2457,26 @@ HRESULT WINAPI ShellExecCmdLine( { PathAddBackslashW(szFile); } - if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) + + WCHAR szCurDir[MAX_PATH]; + GetCurrentDirectoryW(_countof(szCurDir), szCurDir); + if (pwszStartDir) + { + SetCurrentDirectoryW(pwszStartDir); + } + + if (PathIsRelativeW(szFile) && + GetFullPathNameW(szFile, _countof(szFile2), szFile2, NULL) && + PathFileExistsW(szFile2)) + { + StringCchCopyW(szFile, _countof(szFile), szFile2); + } + else if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) { StringCchCopyW(szFile, _countof(szFile), szFile2); } @@ -2477,6 +2491,11 @@ HRESULT WINAPI ShellExecCmdLine( pchParams = NULL; } + if (pwszStartDir) + { + SetCurrentDirectoryW(szCurDir); + } + if (!(dwSeclFlags & SECL_ALLOW_NONEXE)) { if (!GetBinaryTypeW(szFile, &dwType)) diff --git a/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp b/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp index 1f2007a35e0..770c71c365f 100644 --- a/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp +++ b/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp @@ -133,12 +133,31 @@ HRESULT WINAPI ShellExecCmdLine( else { pchParams = SplitParams(lpCommand, szFile, _countof(szFile)); - if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) + if (szFile[0] != UNICODE_NULL && szFile[1] == L':' && + szFile[2] == UNICODE_NULL) + { + PathAddBackslashW(szFile); + } + + WCHAR szCurDir[MAX_PATH]; + GetCurrentDirectoryW(_countof(szCurDir), szCurDir); + if (pwszStartDir) + { + SetCurrentDirectoryW(pwszStartDir); + } + + if (PathIsRelativeW(szFile) && + GetFullPathNameW(szFile, _countof(szFile2), szFile2, NULL) && + PathFileExistsW(szFile2)) + { + StringCchCopyW(szFile, _countof(szFile), szFile2); + } + else if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) { StringCchCopyW(szFile, _countof(szFile), szFile2); } @@ -153,6 +172,11 @@ HRESULT WINAPI ShellExecCmdLine( pchParams = NULL; } + if (pwszStartDir) + { + SetCurrentDirectoryW(szCurDir); + } + if (!(dwSeclFlags & SECL_ALLOW_NONEXE)) { if (!GetBinaryTypeW(szFile, &dwType))