mirror of
https://github.com/reactos/reactos.git
synced 2025-04-30 02:58:48 +00:00
[SHELL32] Improve FindExecutableW (#6635)
Follow-up to #6656. An approach to implement ShellExecuteEx correctly. JIRA issue: CORE-19493 - Rewrite code by using AssocQueryStringW and PathResolveW functions.
This commit is contained in:
parent
00c4b3d99f
commit
f9a5585870
1 changed files with 38 additions and 15 deletions
|
@ -1256,28 +1256,51 @@ HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResu
|
||||||
*/
|
*/
|
||||||
HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
|
HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
|
||||||
{
|
{
|
||||||
UINT_PTR retval = SE_ERR_NOASSOC;
|
UINT_PTR retval;
|
||||||
WCHAR old_dir[1024];
|
WCHAR old_dir[MAX_PATH], res[MAX_PATH];
|
||||||
WCHAR res[MAX_PATH];
|
DWORD cch = _countof(res);
|
||||||
|
LPCWSTR dirs[2];
|
||||||
|
|
||||||
TRACE("File %s, Dir %s\n", debugstr_w(lpFile), debugstr_w(lpDirectory));
|
TRACE("File %s, Dir %s\n", debugstr_w(lpFile), debugstr_w(lpDirectory));
|
||||||
|
|
||||||
lpResult[0] = '\0'; /* Start off with an empty return string */
|
*lpResult = UNICODE_NULL;
|
||||||
if (lpFile == NULL)
|
|
||||||
return (HINSTANCE)SE_ERR_FNF;
|
|
||||||
|
|
||||||
if (lpDirectory)
|
GetCurrentDirectoryW(_countof(old_dir), old_dir);
|
||||||
|
|
||||||
|
if (lpDirectory && *lpDirectory)
|
||||||
{
|
{
|
||||||
GetCurrentDirectoryW(ARRAY_SIZE(old_dir), old_dir);
|
|
||||||
SetCurrentDirectoryW(lpDirectory);
|
SetCurrentDirectoryW(lpDirectory);
|
||||||
|
dirs[0] = lpDirectory;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dirs[0] = old_dir;
|
||||||
|
}
|
||||||
|
dirs[1] = NULL;
|
||||||
|
|
||||||
|
if (!GetShortPathNameW(lpFile, res, _countof(res)))
|
||||||
|
StringCchCopyW(res, _countof(res), lpFile);
|
||||||
|
|
||||||
|
if (PathResolveW(res, dirs, PRF_TRYPROGRAMEXTENSIONS))
|
||||||
|
{
|
||||||
|
// NOTE: The last parameter of this AssocQueryStringW call is "strange" in Windows.
|
||||||
|
if (PathIsExeW(res) ||
|
||||||
|
SUCCEEDED(AssocQueryStringW(ASSOCF_NONE, ASSOCSTR_EXECUTABLE, res, NULL, res, &cch)))
|
||||||
|
{
|
||||||
|
StringCchCopyW(lpResult, MAX_PATH, res);
|
||||||
|
retval = 42;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retval = SE_ERR_NOASSOC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retval = SE_ERR_FNF;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = SHELL_FindExecutable(lpDirectory, lpFile, L"open", res, MAX_PATH, NULL, NULL, NULL, NULL);
|
|
||||||
if (retval > 32)
|
|
||||||
strcpyW(lpResult, res);
|
|
||||||
|
|
||||||
TRACE("returning %s\n", debugstr_w(lpResult));
|
TRACE("returning %s\n", debugstr_w(lpResult));
|
||||||
if (lpDirectory)
|
|
||||||
SetCurrentDirectoryW(old_dir);
|
SetCurrentDirectoryW(old_dir);
|
||||||
return (HINSTANCE)retval;
|
return (HINSTANCE)retval;
|
||||||
}
|
}
|
||||||
|
@ -2550,7 +2573,7 @@ HRESULT WINAPI ShellExecCmdLine(
|
||||||
if (dwSeclFlags & SECL_RUNAS)
|
if (dwSeclFlags & SECL_RUNAS)
|
||||||
{
|
{
|
||||||
dwSize = 0;
|
dwSize = 0;
|
||||||
hr = AssocQueryStringW(0, ASSOCSTR_COMMAND, lpCommand, L"RunAs", NULL, &dwSize);
|
hr = AssocQueryStringW(ASSOCF_NONE, ASSOCSTR_COMMAND, lpCommand, L"RunAs", NULL, &dwSize);
|
||||||
if (SUCCEEDED(hr) && dwSize != 0)
|
if (SUCCEEDED(hr) && dwSize != 0)
|
||||||
{
|
{
|
||||||
pszVerb = L"runas";
|
pszVerb = L"runas";
|
||||||
|
|
Loading…
Reference in a new issue