From: Alistair Leslie-Hughes Subject: shell32: Supply a module name to CreateProcess (try 7) Message-Id: Date: Wed, 10 Dec 2014 16:19:08 +1100 Hi, All test pass. Changelog: shell32: Supply a module name to CreateProcess Best Regards Alistair Leslie-Hughes From ccb1c1b0928ed44433d83bf291b2f56237f4a600 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Sat, 22 Feb 2014 15:52:56 +1100 Subject: [PATCH] Supply a module name to CreateProcess --- dlls/shell32/shlexec.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c index 2d9690a..3ee9849 100644 --- a/dlls/shell32/shlexec.c +++ b/dlls/shell32/shlexec.c @@ -311,10 +311,11 @@ static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait, STARTUPINFOW startup; PROCESS_INFORMATION info; UINT_PTR retval = SE_ERR_NOASSOC; - UINT gcdret = 0; - WCHAR curdir[MAX_PATH]; DWORD dwCreationFlags; const WCHAR *lpDirectory = NULL; + WCHAR module_path[MAX_PATH] = {0}; + WCHAR *p = NULL; + DWORD attr; TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory)); @@ -322,17 +323,22 @@ static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait, * a bad working directory */ if (psei->lpDirectory && psei->lpDirectory[0]) { - DWORD attr = GetFileAttributesW(psei->lpDirectory); + attr = GetFileAttributesW(psei->lpDirectory); if (attr != INVALID_FILE_ATTRIBUTES && attr & FILE_ATTRIBUTE_DIRECTORY) lpDirectory = psei->lpDirectory; } - /* ShellExecute specifies the command from psei->lpDirectory - * if present. Not from the current dir as CreateProcess does */ - if( lpDirectory ) - if( ( gcdret = GetCurrentDirectoryW( MAX_PATH, curdir))) - if( !SetCurrentDirectoryW( lpDirectory)) - ERR("cannot set directory %s\n", debugstr_w(lpDirectory)); + if(lpDirectory) + { + attr = GetFileAttributesW(psei->lpFile); + if (attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY)) + { + HINSTANCE findexec = FindExecutableW(psei->lpFile, lpDirectory, module_path); + if(findexec) + p = module_path; + } + } + ZeroMemory(&startup,sizeof(STARTUPINFOW)); startup.cb = sizeof(STARTUPINFOW); startup.dwFlags = STARTF_USESHOWWINDOW; @@ -340,7 +346,7 @@ static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait, dwCreationFlags = CREATE_UNICODE_ENVIRONMENT; if (!(psei->fMask & SEE_MASK_NO_CONSOLE)) dwCreationFlags |= CREATE_NEW_CONSOLE; - if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env, + if (CreateProcessW(p, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env, lpDirectory, &startup, &info)) { /* Give 30 seconds to the app to come up, if desired. Probably only needed @@ -364,9 +370,6 @@ static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait, TRACE("returning %lu\n", retval); psei_out->hInstApp = (HINSTANCE)retval; - if( gcdret ) - if( !SetCurrentDirectoryW( curdir)) - ERR("cannot return to directory %s\n", debugstr_w(curdir)); return retval; } -- 2.1.3