[SHELL32] Pass and expand .lnk working directory (#7314)

This commit is contained in:
Whindmar Saksit 2024-09-06 14:31:24 +02:00 committed by GitHub
parent 0707475f69
commit a509941786
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View file

@ -2617,9 +2617,11 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
}
}
WCHAR dir[MAX_PATH];
SHELLEXECUTEINFOW sei = { sizeof(sei) };
sei.fMask = SEE_MASK_HASLINKNAME | SEE_MASK_UNICODE |
sei.fMask = SEE_MASK_HASLINKNAME | SEE_MASK_UNICODE | SEE_MASK_DOENVSUBST |
(lpici->fMask & (SEE_MASK_NOASYNC | SEE_MASK_ASYNCOK | SEE_MASK_FLAG_NO_UI));
sei.lpDirectory = m_sWorkDir;
if (m_pPidl)
{
sei.lpIDList = m_pPidl;
@ -2628,13 +2630,18 @@ HRESULT CShellLink::DoOpen(LPCMINVOKECOMMANDINFO lpici)
else
{
sei.lpFile = m_sPath;
if (!(m_Header.dwFlags & SLDF_HAS_EXP_SZ))
{
sei.fMask &= ~SEE_MASK_DOENVSUBST; // The link does not want to expand lpFile
if (m_sWorkDir && ExpandEnvironmentStringsW(m_sWorkDir, dir, _countof(dir)) <= _countof(dir))
sei.lpDirectory = dir;
}
}
sei.lpParameters = args;
sei.lpClass = m_sLinkPath;
sei.nShow = m_Header.nShowCommand;
if (lpici->nShow != SW_SHOWNORMAL && lpici->nShow != SW_SHOW)
sei.nShow = lpici->nShow; // Allow invoker to override .lnk show mode
sei.lpDirectory = m_sWorkDir;
return (ShellExecuteExW(&sei) ? S_OK : E_FAIL);
}

View file

@ -1555,9 +1555,10 @@ static HRESULT ShellExecute_ContextMenuVerb(LPSHELLEXECUTEINFOW sei)
if (FAILED_UNEXPECTEDLY(hr))
return hr;
CComHeapPtr<char> verb, parameters;
CComHeapPtr<char> verb, parameters, dir;
__SHCloneStrWtoA(&verb, sei->lpVerb);
__SHCloneStrWtoA(&parameters, sei->lpParameters);
__SHCloneStrWtoA(&dir, sei->lpDirectory);
BOOL fDefault = StrIsNullOrEmpty(sei->lpVerb);
CMINVOKECOMMANDINFOEX ici = { sizeof(ici) };
@ -1571,6 +1572,8 @@ static HRESULT ShellExecute_ContextMenuVerb(LPSHELLEXECUTEINFOW sei)
ici.hwnd = sei->hwnd;
ici.lpParameters = parameters;
ici.lpParametersW = sei->lpParameters;
ici.lpDirectory = dir;
ici.lpDirectoryW = sei->lpDirectory;
ici.dwHotKey = sei->dwHotKey;
ici.hIcon = sei->hIcon;
if (ici.fMask & (CMIC_MASK_HASLINKNAME | CMIC_MASK_HASTITLE))