https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a50994178678336e7e2ca…
commit a50994178678336e7e2ca324ed41c507ad2bd719
Author: Whindmar Saksit <whindsaks(a)proton.me>
AuthorDate: Fri Sep 6 14:31:24 2024 +0200
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Sep 6 14:31:24 2024 +0200
[SHELL32] Pass and expand .lnk working directory (#7314)
---
dll/win32/shell32/CShellLink.cpp | 11 +++++++++--
dll/win32/shell32/shlexec.cpp | 5 ++++-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/dll/win32/shell32/CShellLink.cpp b/dll/win32/shell32/CShellLink.cpp
index 41099e0f550..ca1f6b1a3ef 100644
--- a/dll/win32/shell32/CShellLink.cpp
+++ b/dll/win32/shell32/CShellLink.cpp
@@ -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);
}
diff --git a/dll/win32/shell32/shlexec.cpp b/dll/win32/shell32/shlexec.cpp
index 00b29dc27b7..087bce23a18 100644
--- a/dll/win32/shell32/shlexec.cpp
+++ b/dll/win32/shell32/shlexec.cpp
@@ -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(¶meters, 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))