[PATCH] wshom.ocx: Expand environment string before executing command through CreateProcessW

Porot Mo porotmjp at gmail.com
Tue Jun 16 03:20:46 CDT 2020


Signed-off-by: Porot Mo <porotmjp at gmail.com>
---
 dlls/wshom.ocx/shell.c       | 11 ++++++++++-
 dlls/wshom.ocx/tests/wshom.c | 10 ++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
-------------- next part --------------
diff --git a/dlls/wshom.ocx/shell.c b/dlls/wshom.ocx/shell.c
index f05ce31..e8fcba7 100644
--- a/dlls/wshom.ocx/shell.c
+++ b/dlls/wshom.ocx/shell.c
@@ -1714,6 +1714,9 @@ static HRESULT WINAPI WshShell3_SendKeys(IWshShell3 *iface, BSTR Keys, VARIANT *
 
 static HRESULT WINAPI WshShell3_Exec(IWshShell3 *iface, BSTR command, IWshExec **ret)
 {
+    BSTR expandedcmd;
+    HRESULT hr;
+
     TRACE("(%s %p)\n", debugstr_w(command), ret);
 
     if (!ret)
@@ -1722,7 +1725,13 @@ static HRESULT WINAPI WshShell3_Exec(IWshShell3 *iface, BSTR command, IWshExec *
     if (!command)
         return DISP_E_EXCEPTION;
 
-    return WshExec_create(command, ret);
+    hr = WshShell3_ExpandEnvironmentStrings(iface, command, &expandedcmd);
+    if (FAILED(hr))
+        return hr;
+
+    hr = WshExec_create(expandedcmd, ret);
+    SysFreeString(expandedcmd);
+    return hr;
 }
 
 static HRESULT WINAPI WshShell3_get_CurrentDirectory(IWshShell3 *iface, BSTR *dir)
diff --git a/dlls/wshom.ocx/tests/wshom.c b/dlls/wshom.ocx/tests/wshom.c
index bc913de..c5e56c8 100644
--- a/dlls/wshom.ocx/tests/wshom.c
+++ b/dlls/wshom.ocx/tests/wshom.c
@@ -327,6 +327,16 @@ static void test_wshshell(void)
     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
     SysFreeString(str);
 
+    str = SysAllocString(L"%deadbeaf% /c echo test");
+    hr = IWshShell3_Exec(sh3, str, &shexec);
+    ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
+    SysFreeString(str);
+
+    str = SysAllocString(L"%ComSpec% /c echo test");
+    hr = IWshShell3_Exec(sh3, str, &shexec);
+    ok(hr == HRESULT_FROM_WIN32(ERROR_SUCCESS), "got 0x%08x\n", hr);
+    SysFreeString(str);
+
     IWshCollection_Release(coll);
     IDispatch_Release(disp);
     IWshShell3_Release(sh3);


More information about the wine-devel mailing list