From fac906f2476bba5f2d8a4739aae1d275f222a42a Mon Sep 17 00:00:00 2001 From: Ian O'Neill Date: Fri, 2 Jul 2021 08:26:32 +0100 Subject: [PATCH] Set working directory when invoked from shell extension --- src/cascadia/ShellExtension/OpenTerminalHere.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cascadia/ShellExtension/OpenTerminalHere.cpp b/src/cascadia/ShellExtension/OpenTerminalHere.cpp index a8f2c70acda..a92609e7058 100644 --- a/src/cascadia/ShellExtension/OpenTerminalHere.cpp +++ b/src/cascadia/ShellExtension/OpenTerminalHere.cpp @@ -56,16 +56,17 @@ HRESULT OpenTerminalHere::Invoke(IShellItemArray* psiItemArray, siEx.StartupInfo.cb = sizeof(STARTUPINFOEX); // Append a "\." to the given path, so that this will work in "C:\" - auto cmdline{ wil::str_printf(LR"-("%s" -d "%s\.")-", GetWtExePath().c_str(), pszName.get()) }; + auto path{ wil::str_printf(LR"-(%s\.)-", pszName.get()) }; + auto cmdline{ wil::str_printf(LR"-("%s" -d "%s")-", GetWtExePath().c_str(), path.c_str()) }; RETURN_IF_WIN32_BOOL_FALSE(CreateProcessW( - nullptr, + nullptr, // lpApplicationName cmdline.data(), nullptr, // lpProcessAttributes nullptr, // lpThreadAttributes false, // bInheritHandles EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT, // dwCreationFlags nullptr, // lpEnvironment - nullptr, + path.data(), &siEx.StartupInfo, // lpStartupInfo &_piClient // lpProcessInformation ));