Fix double-clicking control panel items
[reactos.git] / reactos / lib / shell32 / shlexec.c
index 8ff591f..65c0d50 100644 (file)
 #include <ctype.h>
 #include <assert.h>
 
+#define COBJMACROS
+
 #include "windef.h"
 #include "winbase.h"
 #include "winerror.h"
 #include "winreg.h"
-#include "wownt32.h"
-#include "heap.h"
-#include "shellapi.h"
-#include "wingdi.h"
 #include "winuser.h"
-#include "shlobj.h"
 #include "shlwapi.h"
 #include "ddeml.h"
 
 #include "wine/winbase16.h"
 #include "shell32_main.h"
-#include "undocshell.h"
+#include "pidl.h"
 
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(exec);
 
+static const WCHAR wszOpen[] = {'o','p','e','n',0};
+static const WCHAR wszExe[] = {'.','e','x','e',0};
+static const WCHAR wszILPtr[] = {':','%','p',0};
+static const WCHAR wszShell[] = {'\\','s','h','e','l','l','\\',0};
+static const WCHAR wszFolder[] = {'F','o','l','d','e','r',0};
+static const WCHAR wszEmpty[] = {0};
+
+#define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
+
+
 /***********************************************************************
+ *     SHELL_ArgifyW [Internal]
+ *
  * this function is supposed to expand the escape sequences found in the registry
  * some diving reported that the following were used:
  * + %1, %2...  seem to report to parameter of index N in ShellExecute pmts
@@ -65,14 +74,21 @@ WINE_DEFAULT_DEBUG_CHANNEL(exec);
  * %L seems to be %1 as long filename followed by the 8+3 variation
  * %S ???
  * %* all following parameters (see batfile)
+ *
+ * FIXME: use 'len'
+ * FIXME: Careful of going over string boundaries. No checking is done to 'res'...
  */
-static BOOL argify(char* out, int len, const char* fmt, const char* lpFile, LPITEMIDLIST pidl, LPCSTR args)
+static BOOL SHELL_ArgifyW(WCHAR* out, int len, const WCHAR* fmt, const WCHAR* lpFile, LPITEMIDLIST pidl, LPCWSTR args)
 {
-    char    xlpFile[1024];
+    WCHAR   xlpFile[1024];
     BOOL    done = FALSE;
+    BOOL    found_p1 = FALSE;
+    PWSTR   res = out;
+    PCWSTR  cmd;
     LPVOID  pv;
-    char    *res = out;
-    const char *cmd;
+
+    TRACE("%p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
+          debugstr_w(lpFile), pidl, args);
 
     while (*fmt)
     {
@@ -80,109 +96,181 @@ static BOOL argify(char* out, int len, const char* fmt, const char* lpFile, LPIT
         {
             switch (*++fmt)
             {
-              case '\0':
-              case '%':
+            case '\0':
+            case '%':
                 *res++ = '%';
                 break;
 
-              case '2':
-              case '3':
-             case '4':
-             case '5':
-              case '6':
-              case '7':
-             case '8':
-             case '9':
-             case '0':
-              case '*':
-               if (args)
-               {
-                   if (*fmt == '*')
-                   {
-                       *res++ = '"';
-                       while(*args)
-                           *res++ = *args++;
-                       *res++ = '"';
-                   }
-                   else
-                   {
-                       *res++ = '"';
-                       while(*args && !isspace(*args))
-                           *res++ = *args++;
-                       *res++ = '"';
-
-                       while(isspace(*args))
-                           ++args;
-                   }
-               }
-               else
-               {
-              case '1':
-                   if (!done || (*fmt == '1'))
-                   {
-                       /*FIXME Is SearchPath() really needed? We already have separated out the parameter string in args. */
-                       if (SearchPathA(NULL, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
-                           cmd = xlpFile;
-                       else
-                           cmd = lpFile;
-
-                       /* Add double quotation marks unless we already have them (e.g.: "%1" %* for exefile) */
-                       if (res != out && *(res - 1) == '"')
-                       {
-                           strcpy(res, cmd);
-                           res += strlen(cmd);
-                       }
-                       else
-                       {
-                           *res++ = '"';
-                           strcpy(res, cmd);
-                           res += strlen(cmd);
-                           *res++ = '"';
-                       }
-                   }
-               }
+            case '2':
+            case '3':
+            case '4':
+            case '5':
+            case '6':
+            case '7':
+            case '8':
+            case '9':
+            case '0':
+            case '*':
+                if (args)
+                {
+                    if (*fmt == '*')
+                    {
+                        *res++ = '"';
+                        while(*args)
+                            *res++ = *args++;
+                        *res++ = '"';
+                    }
+                    else
+                    {
+                        while(*args && !isspace(*args))
+                            *res++ = *args++;
+
+                        while(isspace(*args))
+                            ++args;
+                    }
+                    break;
+                }
+                /* else fall through */
+            case '1':
+                if (!done || (*fmt == '1'))
+                {
+                    /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
+                    if (SearchPathW(NULL, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
+                        cmd = xlpFile;
+                    else
+                        cmd = lpFile;
+
+                    /* Add double quotation marks unless we already have them
+                       (e.g.: "file://%1" %* for exefile) or unless the arg is already
+                       enclosed in double quotation marks */
+                    if ((res == out || *(fmt + 1) != '"') && *cmd != '"')
+                    {
+                        *res++ = '"';
+                        strcpyW(res, cmd);
+                        res += strlenW(cmd);
+                        *res++ = '"';
+                    }
+                    else
+                    {
+                        strcpyW(res, cmd);
+                        res += strlenW(cmd);
+                    }
+                }
+                found_p1 = TRUE;
                 break;
 
-              /*
-               * IE uses this alot for activating things such as windows media
-               * player. This is not verified to be fully correct but it appears
-               * to work just fine.
-               */
-              case 'l':
-              case 'L':
+            /*
+             * IE uses this a lot for activating things such as windows media
+             * player. This is not verified to be fully correct but it appears
+             * to work just fine.
+             */
+            case 'l':
+            case 'L':
                if (lpFile) {
-                   strcpy(res, lpFile);
-                   res += strlen(lpFile);
+                   strcpyW(res, lpFile);
+                   res += strlenW(lpFile);
                }
+                found_p1 = TRUE;
                 break;
 
-              case 'i':
-              case 'I':
+            case 'i':
+            case 'I':
                if (pidl) {
                    HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
                    pv = SHLockShared(hmem, 0);
-                   res += sprintf(res, ":%p", pv);
+                   res += sprintfW(res, wszILPtr, pv);
                    SHUnlockShared(pv);
                }
+                found_p1 = TRUE;
                 break;
 
-            default: FIXME("Unknown escape sequence %%%c\n", *fmt);
+           default:
+                /*
+                 * Check if this is an env-variable here...
+                 */
+
+                /* Make sure that we have at least one more %.*/
+                if (strchrW(fmt, '%'))
+                {
+                    WCHAR   tmpBuffer[1024];
+                    PWSTR   tmpB = tmpBuffer;
+                    WCHAR   tmpEnvBuff[MAX_PATH];
+                    DWORD   envRet;
+
+                    while (*fmt != '%')
+                        *tmpB++ = *fmt++;
+                    *tmpB++ = 0;
+
+                    TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer));
+
+                    envRet = GetEnvironmentVariableW(tmpBuffer, tmpEnvBuff, MAX_PATH);
+                    if (envRet == 0 || envRet > MAX_PATH)
+                        strcpyW( res, tmpBuffer );
+                    else
+                        strcpyW( res, tmpEnvBuff );
+                    res += strlenW(res);
+                }
+                done = TRUE;
+                break;
+            }
+            /* Don't skip past terminator (catch a single '%' at the end) */
+            if (*fmt != '\0')
+            {
+                fmt++;
             }
-            fmt++;
-            done = TRUE;
         }
         else
             *res++ = *fmt++;
     }
+
     *res = '\0';
-    return done;
+
+    return found_p1;
+}
+
+HRESULT SHELL_GetPathFromIDListForExecuteA(LPCITEMIDLIST pidl, LPSTR pszPath, UINT uOutSize)
+{
+    STRRET strret;
+    IShellFolder* desktop;
+
+    HRESULT hr = SHGetDesktopFolder(&desktop);
+
+    if (SUCCEEDED(hr)) {
+       hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
+
+       if (SUCCEEDED(hr))
+           StrRetToStrNA(pszPath, uOutSize, &strret, pidl);
+
+       IShellFolder_Release(desktop);
+    }
+
+    return hr;
+}
+
+HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
+{
+    STRRET strret;
+    IShellFolder* desktop;
+
+    HRESULT hr = SHGetDesktopFolder(&desktop);
+
+    if (SUCCEEDED(hr)) {
+       hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
+
+       if (SUCCEEDED(hr))
+           StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
+
+       IShellFolder_Release(desktop);
+    }
+
+    return hr;
 }
 
 /*************************************************************************
- *     _ResolveShortCut [Internal]
- *
+ *     SHELL_ResolveShortCutW [Internal]
+ *     read shortcut file at 'wcmd'
  */
-static HRESULT _ResolveShortCut(LPWSTR path, LPWSTR wdir, LPWSTR args, HWND hwnd, int* pshowcmd, LPITEMIDLIST* ppidl)
+static HRESULT SHELL_ResolveShortCutW(LPWSTR wcmd, LPWSTR wargs, LPWSTR wdir, HWND hwnd, LPCWSTR lpVerb, int* pshowcmd, LPITEMIDLIST* ppidl)
 {
     IShellFolder* psf;
 
@@ -194,7 +282,7 @@ static HRESULT _ResolveShortCut(LPWSTR path, LPWSTR wdir, LPWSTR args, HWND hwnd
        LPITEMIDLIST pidl;
        ULONG l;
 
-       hr = IShellFolder_ParseDisplayName(psf, 0, 0, path, &l, &pidl, 0);
+       hr = IShellFolder_ParseDisplayName(psf, 0, 0, wcmd, &l, &pidl, 0);
 
        if (SUCCEEDED(hr)) {
            IShellLinkW* psl;
@@ -202,20 +290,29 @@ static HRESULT _ResolveShortCut(LPWSTR path, LPWSTR wdir, LPWSTR args, HWND hwnd
            hr = IShellFolder_GetUIObjectOf(psf, NULL, 1, (LPCITEMIDLIST*)&pidl, &IID_IShellLinkW, NULL, (LPVOID*)&psl);
 
            if (SUCCEEDED(hr)) {
-               hr = IShellLinkW_Resolve(psl, hwnd, SLR_NO_UI);
+               hr = IShellLinkW_Resolve(psl, hwnd, 0);
 
                if (SUCCEEDED(hr)) {
-                   hr = IShellLinkW_GetPath(psl, path, MAX_PATH, NULL, SLGP_UNCPRIORITY);
+                   hr = IShellLinkW_GetPath(psl, wcmd, MAX_PATH, NULL, SLGP_UNCPRIORITY);
 
                    if (SUCCEEDED(hr)) {
-                       if (!*path)
+                       if (!*wcmd) {
                            /* We could not translate the PIDL in the shell link into a valid file system path - so return the PIDL instead. */
                            hr = IShellLinkW_GetIDList(psl, ppidl);
 
+                           if (SUCCEEDED(hr) && *ppidl) {
+                               /* We got a PIDL instead of a file system path - try to translate it. */
+                               if (SHGetPathFromIDListW(*ppidl, wcmd)) {
+                                   SHFree(*ppidl);
+                                   *ppidl = NULL;
+                               }
+                           }
+                       }
+
                        if (SUCCEEDED(hr)) {
-                           /* get command line arguments and display mode if available */
+                           /* get command line arguments, working directory and display mode if available */
                            IShellLinkW_GetWorkingDirectory(psl, wdir, MAX_PATH);
-                           IShellLinkW_GetArguments(psl, args, MAX_PATH);
+                           IShellLinkW_GetArguments(psl, wargs, MAX_PATH);
                            IShellLinkW_GetShowCmd(psl, pshowcmd);
                        }
                    }
@@ -234,134 +331,154 @@ static HRESULT _ResolveShortCut(LPWSTR path, LPWSTR wdir, LPWSTR args, HWND hwnd
 }
 
 /*************************************************************************
- *     SHELL_ExecuteA [Internal]
+ *     SHELL_ExecuteW [Internal]
  *
  */
-static UINT SHELL_ExecuteA(char *lpCmd, void *env, const char* lpDir, LPSHELLEXECUTEINFOA sei, BOOL shWait)
+static UINT SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
+                           LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
 {
-    STARTUPINFOA  startup;
+    STARTUPINFOW  startup;
     PROCESS_INFORMATION info;
     UINT retval = 31;
-
-    TRACE("Execute %s from directory %s\n", lpCmd, lpDir);
-    ZeroMemory(&startup,sizeof(STARTUPINFOA));
-    startup.cb = sizeof(STARTUPINFOA);
+    UINT gcdret = 0;
+    WCHAR curdir[MAX_PATH];
+
+    TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
+    /* ShellExecute specifies the command from psei->lpDirectory
+     * if present. Not from the current dir as CreateProcess does */
+    if( psei->lpDirectory && psei->lpDirectory[0] )
+        if( ( gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
+            if( !SetCurrentDirectoryW( psei->lpDirectory))
+                ERR("cannot set directory %s\n", debugstr_w(psei->lpDirectory));
+    ZeroMemory(&startup,sizeof(STARTUPINFOW));
+    startup.cb = sizeof(STARTUPINFOW);
     startup.dwFlags = STARTF_USESHOWWINDOW;
-    startup.wShowWindow = sei->nShow;
-    if (CreateProcessA(NULL, lpCmd, NULL, NULL, FALSE, 0,
-                       env, lpDir, &startup, &info))
+    startup.wShowWindow = psei->nShow;
+    if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT,
+                       env, *psei->lpDirectory? psei->lpDirectory: NULL, &startup, &info))
     {
         /* Give 30 seconds to the app to come up, if desired. Probably only needed
            when starting app immediately before making a DDE connection. */
         if (shWait)
-            if (WaitForInputIdle( info.hProcess, 30000 ) == -1)
+            if (WaitForInputIdle( info.hProcess, 30000 ) == WAIT_FAILED)
                 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
         retval = 33;
-        if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
-            sei->hProcess = info.hProcess;
+        if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
+            psei_out->hProcess = info.hProcess;
         else
             CloseHandle( info.hProcess );
         CloseHandle( info.hThread );
     }
     else if ((retval = GetLastError()) >= 32)
     {
-        FIXME("Strange error set by CreateProcess: %d\n", retval);
+        TRACE("CreateProcess returned error %d\n", retval);
         retval = ERROR_BAD_FORMAT;
     }
 
-    sei->hInstApp = (HINSTANCE)retval;
+    TRACE("returning %u\n", retval);
+
+    psei_out->hInstApp = (HINSTANCE)retval;
+    if( gcdret )
+        if( !SetCurrentDirectoryW( curdir))
+            ERR("cannot return to directory %s\n", debugstr_w(curdir));
+
     return retval;
 }
 
 
 /***********************************************************************
- *           build_env
+ *           SHELL_BuildEnvW   [Internal]
  *
  * Build the environment for the new process, adding the specified
  * path to the PATH variable. Returned pointer must be freed by caller.
  */
-static void *build_env( const char *path )
+static void *SHELL_BuildEnvW( const WCHAR *path )
 {
-    char *strings, *new_env;
-    char *p, *p2;
-    int total = strlen(path) + 1;
+    static const WCHAR wPath[] = {'P','A','T','H','=',0};
+    WCHAR *strings, *new_env;
+    WCHAR *p, *p2;
+    int total = strlenW(path) + 1;
     BOOL got_path = FALSE;
 
-    if (!(strings = GetEnvironmentStringsA())) return NULL;
+    if (!(strings = GetEnvironmentStringsW())) return NULL;
     p = strings;
     while (*p)
     {
-        int len = strlen(p) + 1;
-        if (!strncasecmp( p, "PATH=", 5 )) got_path = TRUE;
+        int len = strlenW(p) + 1;
+        if (!strncmpiW( p, wPath, 5 )) got_path = TRUE;
         total += len;
         p += len;
     }
     if (!got_path) total += 5;  /* we need to create PATH */
     total++;  /* terminating null */
 
-    if (!(new_env = HeapAlloc( GetProcessHeap(), 0, total )))
+    if (!(new_env = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) )))
     {
-        FreeEnvironmentStringsA( strings );
+        FreeEnvironmentStringsW( strings );
         return NULL;
     }
     p = strings;
     p2 = new_env;
     while (*p)
     {
-        int len = strlen(p) + 1;
-        memcpy( p2, p, len );
-        if (!strncasecmp( p, "PATH=", 5 ))
+        int len = strlenW(p) + 1;
+        memcpy( p2, p, len * sizeof(WCHAR) );
+        if (!strncmpiW( p, wPath, 5 ))
         {
             p2[len - 1] = ';';
-            strcpy( p2 + len, path );
-            p2 += strlen(path) + 1;
+            strcpyW( p2 + len, path );
+            p2 += strlenW(path) + 1;
         }
         p += len;
         p2 += len;
     }
     if (!got_path)
     {
-        strcpy( p2, "PATH=" );
-        strcat( p2, path );
-        p2 += strlen(p2) + 1;
+        strcpyW( p2, wPath );
+        strcatW( p2, path );
+        p2 += strlenW(p2) + 1;
     }
     *p2 = 0;
-    FreeEnvironmentStringsA( strings );
+    FreeEnvironmentStringsW( strings );
     return new_env;
 }
 
 
 /***********************************************************************
- *           SHELL_TryAppPath
+ *           SHELL_TryAppPathW [Internal]
  *
  * Helper function for SHELL_FindExecutable
  * @param lpResult - pointer to a buffer of size MAX_PATH
  * On entry: szName is a filename (probably without path separators).
  * On exit: if szName found in "App Path", place full path in lpResult, and return true
  */
-static BOOL SHELL_TryAppPath( LPCSTR szName, LPSTR lpResult, void**env)
+static BOOL SHELL_TryAppPathW( LPCWSTR szName, LPWSTR lpResult, WCHAR **env)
 {
+    static const WCHAR wszKeyAppPaths[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',
+       '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','A','p','p',' ','P','a','t','h','s','\\',0};
+    static const WCHAR wPath[] = {'P','a','t','h',0};
     HKEY hkApp = 0;
-    char buffer[256];
+    WCHAR buffer[1024];
     LONG len;
     LONG res;
     BOOL found = FALSE;
 
     if (env) *env = NULL;
-    sprintf(buffer, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s", szName);
-    res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
+    strcpyW(buffer, wszKeyAppPaths);
+    strcatW(buffer, szName);
+    res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
     if (res) goto end;
 
-    len = MAX_PATH;
-    res = RegQueryValueA(hkApp, NULL, lpResult, &len);
+    len = MAX_PATH*sizeof(WCHAR);
+    res = RegQueryValueW(hkApp, NULL, lpResult, &len);
     if (res) goto end;
     found = TRUE;
 
     if (env)
     {
         DWORD count = sizeof(buffer);
-        if (!RegQueryValueExA(hkApp, "Path", NULL, NULL, buffer, &count) && buffer[0])
-            *env = build_env( buffer );
+        if (!RegQueryValueExW(hkApp, wPath, NULL, NULL, (LPBYTE)buffer, &count) && buffer[0])
+            *env = SHELL_BuildEnvW( buffer );
     }
 
 end:
@@ -369,22 +486,25 @@ end:
     return found;
 }
 
-static UINT _FindExecutableByOperation(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperation, LPSTR key, LPSTR filetype, LPSTR command)
+static UINT SHELL_FindExecutableByOperation(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation, LPWSTR key, LPWSTR filetype, LPWSTR command, LONG commandlen)
 {
-    LONG commandlen = 256;  /* This is the most DOS can handle :) */
+    static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
 
     /* Looking for ...buffer\shell\<verb>\command */
-    strcat(filetype, "\\shell\\");
-    strcat(filetype, lpOperation);
-    strcat(filetype, "\\command");
+    strcatW(filetype, wszShell);
+    strcatW(filetype, lpOperation);
+    strcatW(filetype, wCommand);
 
-    if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, command, &commandlen) == ERROR_SUCCESS)
+    if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, command,
+                       &commandlen) == ERROR_SUCCESS)
     {
-        if (key) strcpy(key, filetype);
+       commandlen /= sizeof(WCHAR);
+        if (key) strcpyW(key, filetype);
 #if 0
-        LPSTR tmp;
-        char param[256];
-       LONG paramlen = 256;
+        LPWSTR tmp;
+        WCHAR param[256];
+       LONG paramlen = sizeof(param);
+        static const WCHAR wSpace[] = {' ',0};
 
         /* FIXME: it seems all Windows version don't behave the same here.
          * the doc states that this ddeexec information can be found after
@@ -393,14 +513,15 @@ static UINT _FindExecutableByOperation(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOp
          */
        /* Get the parameters needed by the application
           from the associated ddeexec key */
-       tmp = strstr(filetype, "command");
+       tmp = strstrW(filetype, wCommand);
        tmp[0] = '\0';
-       strcat(filetype, "ddeexec");
-
-       if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, param, &paramlen) == ERROR_SUCCESS)
+       strcatW(filetype, wDdeexec);
+       if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, param,
+                                    &paramlen) == ERROR_SUCCESS)
        {
-            strcat(command, " ");
-            strcat(command, param);
+           paramlen /= sizeof(WCHAR);
+            strcatW(command, wSpace);
+            strcatW(command, param);
             commandlen += paramlen;
        }
 #endif
@@ -427,205 +548,215 @@ static UINT _FindExecutableByOperation(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOp
  *              command (it'll be used afterwards for more information
  *              on the operation)
  */
-UINT SHELL_FindExecutable(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperation,
-                          LPSTR lpResult, LPSTR key, void **env, LPITEMIDLIST pidl, LPCSTR args)
+UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation,
+                                 LPWSTR lpResult, int resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
 {
-    char *extension = NULL; /* pointer to file extension */
-    char tmpext[5];         /* local copy to munge as we please */
-    char filetype[256];     /* registry name for this filetype */
-    LONG filetypelen = 256; /* length of above */
-    char command[256];      /* command from registry */
-    char buffer[256];       /* Used to GetProfileString */
-    UINT retval = 31;      /* default - 'No association was found' */
-    char *tok;              /* token pointer */
-    char xlpFile[256] = ""; /* result of SearchPath */
-    DWORD attribs;         /* file attributes */
-
-    TRACE("%s\n", (lpFile != NULL) ? lpFile : "-");
-
+    static const WCHAR wWindows[] = {'w','i','n','d','o','w','s',0};
+    static const WCHAR wPrograms[] = {'p','r','o','g','r','a','m','s',0};
+    static const WCHAR wExtensions[] = {'e','x','e',' ','p','i','f',' ','b','a','t',' ','c','m','d',' ','c','o','m',0};
+    WCHAR *extension = NULL; /* pointer to file extension */
+    WCHAR filetype[256];     /* registry name for this filetype */
+    LONG  filetypelen = sizeof(filetype); /* length of above */
+    WCHAR command[1024];     /* command from registry */
+    WCHAR wBuffer[256];      /* Used to GetProfileString */
+    UINT  retval = 31;       /* default - 'No association was found' */
+    WCHAR *tok;              /* token pointer */
+    WCHAR xlpFile[256];      /* result of SearchPath */
+    DWORD attribs;           /* file attributes */
+
+    TRACE("%s\n", (lpFile != NULL) ? debugstr_w(lpFile) : "-");
+
+    xlpFile[0] = '\0';
     lpResult[0] = '\0'; /* Start off with an empty return string */
     if (key) *key = '\0';
 
     /* trap NULL parameters on entry */
-    if ((lpFile == NULL) || (lpResult == NULL))
+    if ((lpFile == NULL) || (lpResult == NULL) || (lpOperation == NULL))
     {
-        WARN("(lpFile=%s,lpResult=%s): NULL parameter\n", lpFile, lpResult);
+        WARN("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
+             debugstr_w(lpFile), debugstr_w(lpOperation), debugstr_w(lpResult));
         return 2; /* File not found. Close enough, I guess. */
     }
 
-    if (SHELL_TryAppPath( lpFile, lpResult, env ))
+    if (SHELL_TryAppPathW( lpFile, lpResult, env ))
     {
-        TRACE("found %s via App Paths\n", lpResult);
+        TRACE("found %s via App Paths\n", debugstr_w(lpResult));
         return 33;
     }
 
-    if (SearchPathA(lpPath, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
+    if (SearchPathW(lpPath, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
     {
-        TRACE("SearchPathA returned non-zero\n");
+        TRACE("SearchPathW returned non-zero\n");
         lpFile = xlpFile;
         /* Hey, isn't this value ignored?  Why make this call?  Shouldn't we return here?  --dank*/
     }
 
-    attribs = GetFileAttributesA(lpFile);
-
+    attribs = GetFileAttributesW(lpFile);
     if (attribs!=INVALID_FILE_ATTRIBUTES && (attribs&FILE_ATTRIBUTE_DIRECTORY))
     {
-       strcpy(filetype, "Folder");
-       filetypelen = 6;    /* strlen("Folder") */
+       strcpyW(filetype, wszFolder);
+       filetypelen = 6;    /* strlen("Folder") */
     }
     else
     {
-       /* First thing we need is the file's extension */
-       extension = PathFindExtensionA(xlpFile); /* Assume last "." is the one; */
-                                          /* File->Run in progman uses */
-                                          /* .\FILE.EXE :( */
-       TRACE("xlpFile=%s,extension=%s\n", xlpFile, extension);
-
-       if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
-       {
-           WARN("Returning 31 - No association\n");
-           return 31; /* no association */
-       }
+        /* First thing we need is the file's extension */
+        extension = strrchrW(xlpFile, '.'); /* Assume last "." is the one; */
+        /* File->Run in progman uses */
+        /* .\FILE.EXE :( */
+        TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile), debugstr_w(extension));
 
-       /* Make local copy & lowercase it for reg & 'programs=' lookup */
-       lstrcpynA(tmpext, extension, 5);
-       CharLowerA(tmpext);
-       TRACE("%s file\n", tmpext);
-
-       /* Three places to check: */
-       /* 1. win.ini, [windows], programs (NB no leading '.') */
-       /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
-       /* 3. win.ini, [extensions], extension (NB no leading '.' */
-       /* All I know of the order is that registry is checked before */
-       /* extensions; however, it'd make sense to check the programs */
-       /* section first, so that's what happens here. */
-
-       /* See if it's a program - if GetProfileString fails, we skip this
-        * section. Actually, if GetProfileString fails, we've probably
-        * got a lot more to worry about than running a program... */
-       if (GetProfileStringA("windows", "programs", "exe pif bat cmd com",
-                             buffer, sizeof(buffer)) > 0)
-       {
-           UINT i;
+        if (extension == NULL || extension[1]==0)
+        {
+            WARN("Returning 31 - No association\n");
+            return 31; /* no association */
+        }
 
-           for (i=0; i<strlen(buffer); i++) buffer[i] = tolower(buffer[i]);
+        /* Three places to check: */
+        /* 1. win.ini, [windows], programs (NB no leading '.') */
+        /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
+        /* 3. win.ini, [extensions], extension (NB no leading '.' */
+        /* All I know of the order is that registry is checked before */
+        /* extensions; however, it'd make sense to check the programs */
+        /* section first, so that's what happens here. */
+
+        /* See if it's a program - if GetProfileString fails, we skip this
+         * section. Actually, if GetProfileString fails, we've probably
+         * got a lot more to worry about than running a program... */
+        if (GetProfileStringW(wWindows, wPrograms, wExtensions, wBuffer, sizeof(wBuffer)/sizeof(WCHAR)) > 0)
+        {
+            CharLowerW(wBuffer);
+            tok = wBuffer;
+            while (*tok)
+            {
+                WCHAR *p = tok;
+                while (*p && *p != ' ' && *p != '\t') p++;
+                if (*p)
+                {
+                    *p++ = 0;
+                    while (*p == ' ' || *p == '\t') p++;
+                }
 
-           tok = strtok(buffer, " \t"); /* ? */
-           while (tok!= NULL)
-           {
-               if (strcmp(tok, &tmpext[1]) == 0) /* have to skip the leading "." */
-               {
-                   strcpy(lpResult, xlpFile);
-                   /* Need to perhaps check that the file has a path
-                    * attached */
-                   TRACE("found %s\n", lpResult);
-                   return 33;
-
-                   /* Greater than 32 to indicate success FIXME According to the
-                    * docs, I should be returning a handle for the
-                    * executable. Does this mean I'm supposed to open the
-                    * executable file or something? More RTFM, I guess... */
-               }
-               tok = strtok(NULL, " \t");
-           }
-       }
+                if (strcmpiW(tok, &extension[1]) == 0) /* have to skip the leading "." */
+                {
+                    strcpyW(lpResult, xlpFile);
+                    /* Need to perhaps check that the file has a path
+                     * attached */
+                    TRACE("found %s\n", debugstr_w(lpResult));
+                    return 33;
+
+                    /* Greater than 32 to indicate success FIXME According to the
+                     * docs, I should be returning a handle for the
+                     * executable. Does this mean I'm supposed to open the
+                     * executable file or something? More RTFM, I guess... */
+                }
+                tok = p;
+            }
+        }
 
-       /* Check registry */
-       if (RegQueryValueA(HKEY_CLASSES_ROOT, tmpext, filetype, &filetypelen) != ERROR_SUCCESS)
-           *filetype = '\0';
+        /* Check registry */
+        if (RegQueryValueW(HKEY_CLASSES_ROOT, extension, filetype,
+                           &filetypelen) == ERROR_SUCCESS)
+        {
+            filetypelen /= sizeof(WCHAR);
+            filetype[filetypelen] = '\0';
+            TRACE("File type: %s\n", debugstr_w(filetype));
+        }
     }
 
     if (*filetype)
     {
        if (lpOperation)
        {
-           /* pass the operation string to _FindExecutableByOperation() */
+           /* pass the operation string to SHELL_FindExecutableByOperation() */
            filetype[filetypelen] = '\0';
-           retval = _FindExecutableByOperation(lpPath, lpFile, lpOperation, key, filetype, command);
+           retval = SHELL_FindExecutableByOperation(lpPath, lpFile, lpOperation, key, filetype, command, sizeof(command));
        }
        else
        {
-           char operation[MAX_PATH];
+           WCHAR operation[MAX_PATH];
            HKEY hkey;
 
-           strcat(filetype, "\\shell");
+           /* Looking for ...buffer\shell\<operation>\command */
+           strcatW(filetype, wszShell);
 
            /* enumerate the operation subkeys in the registry and search for one with an associated command */
-           if (RegOpenKeyA(HKEY_CLASSES_ROOT, filetype, &hkey) == ERROR_SUCCESS)
+           if (RegOpenKeyW(HKEY_CLASSES_ROOT, filetype, &hkey) == ERROR_SUCCESS)
            {
                int idx = 0;
                for(;; ++idx)
                {
-                   if (RegEnumKeyA(hkey, idx, operation, MAX_PATH) != ERROR_SUCCESS)
+                   if (RegEnumKeyW(hkey, idx, operation, MAX_PATH) != ERROR_SUCCESS)
                        break;
 
                    filetype[filetypelen] = '\0';
-                   retval = _FindExecutableByOperation(lpPath, lpFile, operation, key, filetype, command);
+                   retval = SHELL_FindExecutableByOperation(lpPath, lpFile, operation, key, filetype, command, sizeof(command));
 
                    if (retval > 32)
                        break;
-               }
-
+           }
                RegCloseKey(hkey);
            }
        }
 
        if (retval > 32)
-        {
-            argify(lpResult, sizeof(lpResult), command, xlpFile, pidl, args);
+       {
+           SHELL_ArgifyW(lpResult, resultLen, command, xlpFile, pidl, args);
 
-            /* Remove double quotation marks */
-            if (*lpResult == '"')
-            {
-                char *p = lpResult;
-                while (*(p + 1) != '"' && *(p + 1) != ' ')
-                {
-                    *p = *(p + 1);
-                    p++;
-                }
-                *p = '\0';
-            }
-        }
+           /* Remove double quotation marks and command line arguments */
+           if (*lpResult == '"')
+           {
+               WCHAR *p = lpResult;
+               while (*(p + 1) != '"')
+               {
+                   *p = *(p + 1);
+                   p++;
+               }
+               *p = '\0';
+           }
+       }
     }
-    else if (extension) /* Check win.ini */
+    else /* Check win.ini */
     {
+       static const WCHAR wExtensions[] = {'e','x','t','e','n','s','i','o','n','s',0};
+
        /* Toss the leading dot */
        extension++;
-       if (GetProfileStringA("extensions", extension, "", command,
-                              sizeof(command)) > 0)
+       if (GetProfileStringW(wExtensions, extension, wszEmpty, command, sizeof(command)/sizeof(WCHAR)) > 0)
         {
-            if (strlen(command) != 0)
+            if (strlenW(command) != 0)
             {
-                strcpy(lpResult, command);
-                tok = strstr(lpResult, "^"); /* should be ^.extension? */
-
+                strcpyW(lpResult, command);
+                tok = strchrW(lpResult, '^'); /* should be ^.extension? */
                 if (tok != NULL)
                 {
                     tok[0] = '\0';
-                    strcat(lpResult, xlpFile); /* what if no dir in xlpFile? */
-                    tok = strstr(command, "^"); /* see above */
-                    if ((tok != NULL) && (strlen(tok)>5))
-                        strcat(lpResult, &tok[5]);
+                    strcatW(lpResult, xlpFile); /* what if no dir in xlpFile? */
+                    tok = strchrW(command, '^'); /* see above */
+                    if ((tok != NULL) && (strlenW(tok)>5))
+                    {
+                        strcatW(lpResult, &tok[5]);
+                    }
                 }
-
                 retval = 33; /* FIXME - see above */
             }
         }
     }
 
-    TRACE("returning %s\n", lpResult);
+    TRACE("returning %s\n", debugstr_w(lpResult));
     return retval;
 }
 
 /******************************************************************
  *             dde_cb
  *
- * callback for the DDE connection. not really usefull
+ * callback for the DDE connection. not really useful
  */
 static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
-                                HSZ hsz1, HSZ hsz2,
-                                HDDEDATA hData, DWORD dwData1, DWORD dwData2)
+                                HSZ hsz1, HSZ hsz2, HDDEDATA hData,
+                                ULONG_PTR dwData1, ULONG_PTR dwData2)
 {
+    TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
+           uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
     return NULL;
 }
 
@@ -638,50 +769,55 @@ static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
  * launching an application and trying (#2) to connect to it
  *
  */
-static unsigned dde_connect(char* key, char* start, char* ddeexec,
-                            const char* lpFile, const char* lpDir, void *env,
-                            LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc,
-                           LPCSTR szCommandline, LPITEMIDLIST pidl)
+static unsigned dde_connect(WCHAR* key, WCHAR* start, WCHAR* ddeexec,
+                            const WCHAR* lpFile, WCHAR *env,
+                           LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc,
+                           LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
 {
-    char*       endkey = key + strlen(key);
-    char        app[256], topic[256], ifexec[256];
+    static const WCHAR wApplication[] = {'\\','a','p','p','l','i','c','a','t','i','o','n',0};
+    static const WCHAR wTopic[] = {'\\','t','o','p','i','c',0};
+    WCHAR *     endkey = key + strlenW(key);
+    WCHAR       app[256], topic[256], ifexec[256], res[256];
     LONG        applen, topiclen, ifexeclen;
-    char*       exec;
+    WCHAR *     exec;
     DWORD       ddeInst = 0;
     DWORD       tid;
     HSZ         hszApp, hszTopic;
     HCONV       hConv;
+    HDDEDATA    hDdeData;
     unsigned    ret = 31;
 
-    strcpy(endkey, "\\application");
+    strcpyW(endkey, wApplication);
     applen = sizeof(app);
-    if (RegQueryValueA(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
+    if (RegQueryValueW(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
     {
-        FIXME("default app name NIY %s\n", key);
+        FIXME("default app name NIY %s\n", debugstr_w(key));
         return 2;
     }
 
-    strcpy(endkey, "\\topic");
+    strcpyW(endkey, wTopic);
     topiclen = sizeof(topic);
-    if (RegQueryValueA(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
+    if (RegQueryValueW(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
     {
-        strcpy(topic, "System");
+        static const WCHAR wSystem[] = {'S','y','s','t','e','m',0};
+        strcpyW(topic, wSystem);
     }
 
-    if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
+    if (DdeInitializeW(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
     {
         return 2;
     }
 
-    hszApp = DdeCreateStringHandleA(ddeInst, app, CP_WINANSI);
-    hszTopic = DdeCreateStringHandleA(ddeInst, topic, CP_WINANSI);
+    hszApp = DdeCreateStringHandleW(ddeInst, app, CP_WINUNICODE);
+    hszTopic = DdeCreateStringHandleW(ddeInst, topic, CP_WINUNICODE);
 
     hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
     exec = ddeexec;
     if (!hConv)
     {
-        TRACE("Launching '%s'\n", start);
-        ret = execfunc(start, env, lpDir, sei, TRUE);
+        static const WCHAR wIfexec[] = {'\\','i','f','e','x','e','c',0};
+        TRACE("Launching '%s'\n", debugstr_w(start));
+        ret = execfunc(start, env, TRUE, psei, psei_out);
         if (ret < 32)
         {
             TRACE("Couldn't launch\n");
@@ -691,69 +827,82 @@ static unsigned dde_connect(char* key, char* start, char* ddeexec,
         if (!hConv)
         {
             TRACE("Couldn't connect. ret=%d\n", ret);
-            ret = 30; /* whatever */
-            goto error;
+            DdeUninitialize(ddeInst);
+            SetLastError(ERROR_DDE_FAIL);
+            return 30; /* whatever */
         }
-        strcpy(endkey, "\\ifexec");
+        strcpyW(endkey, wIfexec);
         ifexeclen = sizeof(ifexec);
-        if (RegQueryValueA(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
+        if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
         {
             exec = ifexec;
         }
     }
 
-#if 0 /* argify has already been called. */
-    argify(res, sizeof(res), exec, lpFile, pidl, szCommandline);
-    TRACE("%s %s => %s\n", exec, lpFile, res);
-#endif
+    SHELL_ArgifyW(res, sizeof(res)/sizeof(WCHAR), exec, lpFile, pidl, szCommandline);
+    TRACE("%s %s => %s\n", debugstr_w(exec), debugstr_w(lpFile), debugstr_w(res));
+
+    /* It's documented in the KB 330337 that IE has a bug and returns
+     * error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
+     */
+    hDdeData = DdeClientTransaction((LPBYTE)res, (strlenW(res) + 1) * sizeof(WCHAR), hConv, 0L, 0,
+                                     XTYP_EXECUTE, 10000, &tid);
+    if (hDdeData)
+        DdeFreeDataHandle(hDdeData);
+    else
+        WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst));
+    ret = 33;
 
-    ret = (DdeClientTransaction((LPBYTE)szCommandline, strlen(szCommandline) + 1, hConv, 0L, 0,
-                                XTYP_EXECUTE, 10000, &tid) != DMLERR_NO_ERROR) ? 31 : 33;
     DdeDisconnect(hConv);
+
  error:
     DdeUninitialize(ddeInst);
+
     return ret;
 }
 
 /*************************************************************************
  *     execute_from_key [Internal]
  */
-static UINT execute_from_key(LPSTR key, LPCSTR lpFile, LPCSTR lpDir, void *env,
-                             LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc,
-                            LPCSTR szCommandline, LPITEMIDLIST pidl)
+static UINT execute_from_key(LPWSTR key, LPCWSTR lpFile, WCHAR *env, LPCWSTR szCommandline,
+                            SHELL_ExecuteW32 execfunc,
+                            LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
 {
-    char cmd[1024] = "";
+    WCHAR cmd[1024];
     LONG cmdlen = sizeof(cmd);
     UINT retval = 31;
 
+    cmd[0] = '\0';
+
     /* Get the application for the registry */
-    if (RegQueryValueA(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
+    if (RegQueryValueW(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
     {
-        LPSTR tmp;
-        char param[256] = "";
-        LONG paramlen = 256;
+       static const WCHAR wCommand[] = {'c','o','m','m','a','n','d',0};
+       static const WCHAR wDdeexec[] = {'d','d','e','e','x','e','c',0};
+        LPWSTR tmp;
+        WCHAR param[256];
+        LONG paramlen = sizeof(param);
+
+        param[0] = '\0';
 
         /* Get the parameters needed by the application
            from the associated ddeexec key */
-        tmp = strstr(key, "command");
+        tmp = strstrW(key, wCommand);
         assert(tmp);
-        strcpy(tmp, "ddeexec");
+        strcpyW(tmp, wDdeexec);
 
-        if (RegQueryValueA(HKEY_CLASSES_ROOT, key, param, &paramlen) == ERROR_SUCCESS)
+        if (RegQueryValueW(HKEY_CLASSES_ROOT, key, param, &paramlen) == ERROR_SUCCESS)
         {
-            TRACE("Got ddeexec %s => %s\n", key, param);
-            retval = dde_connect(key, cmd, param, lpFile, lpDir, env, sei, execfunc, szCommandline, pidl);
+            TRACE("Got ddeexec %s => %s\n", debugstr_w(key), debugstr_w(param));
+            retval = dde_connect(key, cmd, param, lpFile, env, szCommandline, psei->lpIDList, execfunc, psei, psei_out);
         }
         else
         {
-#if 0 /* argify() has already been called. */
             /* Is there a replace() function anywhere? */
+            cmdlen /= sizeof(WCHAR);
             cmd[cmdlen] = '\0';
-            argify(param, sizeof(param), cmd, lpFile, pidl, szCommandline);
-#else
-           strcpy(param, szCommandline);
-#endif
-            retval = execfunc(param, env, lpDir, sei, FALSE);
+            SHELL_ArgifyW(param, sizeof(param)/sizeof(WCHAR), cmd, lpFile, psei->lpIDList, szCommandline);
+            retval = execfunc(param, env, FALSE, psei, psei_out);
         }
     }
     else TRACE("ooch\n");
@@ -765,12 +914,33 @@ static UINT execute_from_key(LPSTR key, LPCSTR lpFile, LPCSTR lpDir, void *env,
  * FindExecutableA                     [SHELL32.@]
  */
 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
+{
+    HINSTANCE retval;
+    WCHAR *wFile = NULL, *wDirectory = NULL;
+    WCHAR wResult[MAX_PATH];
+
+    if (lpFile) __SHCloneStrAtoW(&wFile, lpFile);
+    if (lpDirectory) __SHCloneStrAtoW(&wDirectory, lpDirectory);
+
+    retval = FindExecutableW(wFile, wDirectory, wResult);
+    WideCharToMultiByte(CP_ACP, 0, wResult, -1, lpResult, MAX_PATH, NULL, NULL);
+    if (wFile) SHFree( wFile );
+    if (wDirectory) SHFree( wDirectory );
+
+    TRACE("returning %s\n", lpResult);
+    return (HINSTANCE)retval;
+}
+
+/*************************************************************************
+ * FindExecutableW                     [SHELL32.@]
+ */
+HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
 {
     UINT retval = 31;    /* default - 'No association was found' */
-    char old_dir[1024];
+    WCHAR old_dir[1024];
 
     TRACE("File %s, Dir %s\n",
-          (lpFile != NULL ? lpFile : "-"), (lpDirectory != NULL ? lpDirectory : "-"));
+          (lpFile != NULL ? debugstr_w(lpFile) : "-"), (lpDirectory != NULL ? debugstr_w(lpDirectory) : "-"));
 
     lpResult[0] = '\0'; /* Start off with an empty return string */
 
@@ -783,191 +953,261 @@ HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResu
 
     if (lpDirectory)
     {
-        GetCurrentDirectoryA(sizeof(old_dir), old_dir);
-        SetCurrentDirectoryA(lpDirectory);
+        GetCurrentDirectoryW(sizeof(old_dir)/sizeof(WCHAR), old_dir);
+        SetCurrentDirectoryW(lpDirectory);
     }
 
-    retval = SHELL_FindExecutable(lpDirectory, lpFile, "open", lpResult, NULL, NULL, NULL, NULL);
+    retval = SHELL_FindExecutable(lpDirectory, lpFile, wszOpen, lpResult, MAX_PATH, NULL, NULL, NULL, NULL);
 
-    TRACE("returning %s\n", lpResult);
+    TRACE("returning %s\n", debugstr_w(lpResult));
     if (lpDirectory)
-        SetCurrentDirectoryA(old_dir);
+        SetCurrentDirectoryW(old_dir);
     return (HINSTANCE)retval;
 }
 
 /*************************************************************************
- * FindExecutableW                     [SHELL32.@]
- */
-HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
-{
-    FIXME("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
-    return (HINSTANCE)31;    /* default - 'No association was found' */
-}
-
-/*************************************************************************
- *     ShellExecuteExA32 [Internal]
- *
- *  FIXME:  use PathResolveA() to search for the fully qualified executable path
- *         use PathProcessCommandA() to processes the command line string
+ *     ShellExecuteExW32 [Internal]
  */
-BOOL WINAPI ShellExecuteExA32 (LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc)
+BOOL WINAPI ShellExecuteExW32 (LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
 {
-    CHAR szApplicationName[MAX_PATH+2], szCommandline[MAX_PATH], fileName[MAX_PATH], dir[MAX_PATH];
-    char res[MAX_PATH];
-    void *env;
-    char lpstrProtocol[256];
-    LPCSTR lpFile;
+    static const WCHAR wQuote[] = {'"',0};
+    static const WCHAR wSpace[] = {' ',0};
+    static const WCHAR wWww[] = {'w','w','w',0};
+    static const WCHAR wFile[] = {'f','i','l','e',0};
+    static const WCHAR wHttp[] = {'h','t','t','p',':','/','/',0};
+    static const WCHAR wExtLnk[] = {'.','l','n','k',0};
+    static const WCHAR wExplorer[] = {'e','x','p','l','o','r','e','r','.','e','x','e',0};
+    static const DWORD unsupportedFlags =
+        SEE_MASK_INVOKEIDLIST  | SEE_MASK_ICON         | SEE_MASK_HOTKEY |
+        SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI |
+        SEE_MASK_UNICODE       | SEE_MASK_NO_CONSOLE   | SEE_MASK_ASYNCOK |
+        SEE_MASK_HMONITOR;
+
+    WCHAR wszApplicationName[MAX_PATH+2], wszParameters[1024], wszDir[MAX_PATH];
+    SHELLEXECUTEINFOW sei_tmp; /* modifiable copy of SHELLEXECUTEINFO struct */
+    WCHAR wfileName[MAX_PATH];
+    WCHAR *env;
+    WCHAR lpstrProtocol[256];
+    LPCWSTR lpFile;
     UINT retval = 31;
-    char cmd[1024];
-    const char* ext;
+    WCHAR wcmd[1024];
+    WCHAR buffer[MAX_PATH];
+    const WCHAR* ext;
     BOOL done;
 
-    LPITEMIDLIST pidl = sei->lpIDList;
-    LPITEMIDLIST tmpPidl = NULL;
+    /* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
+    memcpy(&sei_tmp, sei, sizeof(sei_tmp));
 
     TRACE("mask=0x%08lx hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
-            sei->fMask, sei->hwnd, debugstr_a(sei->lpVerb),
-            debugstr_a(sei->lpFile), debugstr_a(sei->lpParameters),
-            debugstr_a(sei->lpDirectory), sei->nShow,
-            (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei->lpClass) : "not used");
+            sei_tmp.fMask, sei_tmp.hwnd, debugstr_w(sei_tmp.lpVerb),
+            debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters),
+            debugstr_w(sei_tmp.lpDirectory), sei_tmp.nShow,
+            ((sei_tmp.fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME) ?
+                debugstr_w(sei_tmp.lpClass) : "not used");
 
     sei->hProcess = NULL;
 
-    if (sei->lpFile)
-        strcpy(szApplicationName, sei->lpFile);
+    /* make copies of all path/command strings */
+    if (!sei_tmp.lpFile)
+        *wszApplicationName = '\0';
+    else if (*sei_tmp.lpFile == '\"')
+    {
+        UINT l;
+        strcpyW(wszApplicationName, sei_tmp.lpFile+1);
+        l=lstrlenW(wszApplicationName);
+        if (wszApplicationName[l-1] == '\"')
+            wszApplicationName[l-1] = '\0';
+        TRACE("wszApplicationName=%s\n",debugstr_w(wszApplicationName));
+    }
     else
-       *szApplicationName = '\0';
+        strcpyW(wszApplicationName, sei_tmp.lpFile);
 
-    if (sei->lpParameters)
-        strcpy(szCommandline, sei->lpParameters);
+    if (sei_tmp.lpParameters)
+       strcpyW(wszParameters, sei_tmp.lpParameters);
     else
-       *szCommandline = '\0';
+       *wszParameters = '\0';
 
-    if (sei->lpDirectory)
-       strcpy(dir, sei->lpDirectory);
+    if (sei_tmp.lpDirectory)
+       strcpyW(wszDir, sei_tmp.lpDirectory);
     else
-       *dir = '\0';
+       *wszDir = '\0';
+
+    /* adjust string pointers to point to the new buffers */
+    sei_tmp.lpFile = wszApplicationName;
+    sei_tmp.lpParameters = wszParameters;
+    sei_tmp.lpDirectory = wszDir;
 
-    if (sei->fMask & (SEE_MASK_ICON | SEE_MASK_HOTKEY |
-        SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
-        SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
-        SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
+    if (sei_tmp.fMask & unsupportedFlags)
     {
-        FIXME("flags ignored: 0x%08lx\n", sei->fMask);
+        FIXME("flags ignored: 0x%08lx\n", sei_tmp.fMask & unsupportedFlags);
     }
 
     /* process the IDList */
-    if (sei->fMask & SEE_MASK_INVOKEIDLIST) /* 0x0c: includes SEE_MASK_IDLIST */
+    if (sei_tmp.fMask & SEE_MASK_IDLIST)
     {
-       IShellExecuteHookA* pSEH;
+       IShellExecuteHookW* pSEH;
 
-       HRESULT hr = SHBindToParent(pidl, &IID_IShellExecuteHookA, (LPVOID*)&pSEH, NULL);
+       HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookW, (LPVOID*)&pSEH, NULL);
 
-       if (SUCCEEDED(hr)) {
-           hr = IShellExecuteHookA_Execute(pSEH, sei);
+       if (SUCCEEDED(hr))
+       {
+           hr = IShellExecuteHookW_Execute(pSEH, sei);
 
-           IShellExecuteHookA_Release(pSEH);
+           IShellExecuteHookW_Release(pSEH);
 
            if (hr == S_OK)
                return TRUE;
        }
 
-        if (!SHGetPathFromIDListA(pidl, szApplicationName))
-            return FALSE;
-
-        TRACE("-- idlist=%p (%s)\n", pidl, szApplicationName);
+        wszApplicationName[0] = '"';
+        SHGetPathFromIDListW(sei_tmp.lpIDList, wszApplicationName+1);
+        strcatW(wszApplicationName, wQuote);
+        TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, debugstr_w(wszApplicationName));
     }
 
-    if (sei->fMask & (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY))
+    if (sei_tmp.fMask & SEE_MASK_CLASSALL)
     {
-        /* launch a document by fileclass like 'WordPad.Document.1' */
+       /* launch a document by fileclass like 'WordPad.Document.1' */
         /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
-        /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
-        if (sei->fMask & SEE_MASK_CLASSKEY)
-            HCR_GetExecuteCommandExA(sei->hkeyClass,
-                                    (sei->fMask & SEE_MASK_CLASSNAME) ? sei->lpClass: NULL,
-                                    (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
-        else if (sei->fMask & SEE_MASK_CLASSNAME)
-            HCR_GetExecuteCommandA(sei->lpClass, (sei->lpVerb) ? sei->lpVerb :
-                                  "open", szCommandline, sizeof(szCommandline));
+        /* FIXME: szCommandline should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
+        ULONG cmask=(sei_tmp.fMask & SEE_MASK_CLASSALL);
+        HCR_GetExecuteCommandW((cmask == SEE_MASK_CLASSKEY) ? sei_tmp.hkeyClass : NULL,
+                               (cmask == SEE_MASK_CLASSNAME) ? sei_tmp.lpClass: NULL,
+                               (sei_tmp.lpVerb) ? sei_tmp.lpVerb : wszOpen,
+                               wszParameters, sizeof(wszParameters)/sizeof(WCHAR));
 
         /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
-        TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", szCommandline, szApplicationName);
+        TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", debugstr_w(wszParameters), debugstr_w(wszApplicationName));
 
-        cmd[0] = '\0';
-        done = argify(cmd, sizeof(cmd), szCommandline, szApplicationName, pidl, NULL);
-        if (!done && szApplicationName[0])
+        wcmd[0] = '\0';
+        done = SHELL_ArgifyW(wcmd, sizeof(wcmd)/sizeof(WCHAR), wszParameters, wszApplicationName, sei_tmp.lpIDList, NULL);
+        if (!done && wszApplicationName[0])
         {
-            strcat(cmd, " ");
-            strcat(cmd, szApplicationName);
+            strcatW(wcmd, wSpace);
+            strcatW(wcmd, wszApplicationName);
         }
-        retval = execfunc(cmd, NULL, dir, sei, FALSE);
+        retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
         if (retval > 32)
             return TRUE;
         else
             return FALSE;
     }
 
-    /* Else, try to execute the filename */
-    TRACE("execute:'%s','%s'\n", szApplicationName, szCommandline);
 
     /* resolve shell shortcuts */
-    ext = PathFindExtensionA(szApplicationName);
-    if (ext && !strcasecmp(ext, ".lnk")) {     /* or check for: shell_attribs & SFGAO_LINK */
-       WCHAR cmd[MAX_PATH], args[MAX_PATH], wdir[MAX_PATH];
-
-       if (MultiByteToWideChar(CP_ACP, 0, szApplicationName, -1, cmd, MAX_PATH)) {
-           MultiByteToWideChar(CP_ACP, 0, dir, -1, wdir, MAX_PATH);
-
-           if (SUCCEEDED(_ResolveShortCut(cmd, wdir, args, sei->hwnd, &sei->nShow, &tmpPidl))) {
-               if (!*cmd && tmpPidl) {
-                   /* We got a PIDL instead of a file system path. */
-                   if (SHGetPathFromIDListA(tmpPidl, cmd))
-                       tmpPidl = NULL;
-
-                   if (cmd[0]==':' && cmd[1]==':') {
-                       /* open shell folder for the specified class GUID */
-                       strcpy(szApplicationName, "explorer.exe");
-                       WideCharToMultiByte(CP_ACP, 0, cmd, -1, szCommandline, MAX_PATH, NULL, NULL);
-
-                       *cmd = '\0';
-                   } else if (HCR_GetExecuteCommandA("Folder", sei->lpVerb? sei->lpVerb: "open", szCommandline, sizeof(szCommandline))) {
-                       res[0] = '\0';
-
-                       /*FIXME: seems to have problems in some cases */
-                       if (argify(res, sizeof(res), szCommandline, NULL, tmpPidl, NULL))
-                           strcpy(szApplicationName, res);
-
-                       szCommandline[0] = '\0';
-                       *cmd = '\0';
-                   }
-               }
+    ext = PathFindExtensionW(sei_tmp.lpFile);
 
-               if (*cmd) {
-                   WideCharToMultiByte(CP_ACP, 0, cmd, -1, szApplicationName, MAX_PATH, NULL, NULL);
-                   WideCharToMultiByte(CP_ACP, 0, wdir, -1, dir, MAX_PATH, NULL, NULL);
-                   WideCharToMultiByte(CP_ACP, 0, args, -1, szCommandline, MAX_PATH, NULL, NULL);
+    if (ext && !strncmpiW(ext, wExtLnk, sizeof(wExtLnk) / sizeof(WCHAR) - 1) &&
+        (ext[sizeof(wExtLnk) / sizeof(WCHAR) - 1] == '\0' ||
+         (sei_tmp.lpFile[0] == '"' && ext[sizeof(wExtLnk) / sizeof(WCHAR) - 1] == '"')))       /* or check for: shell_attribs & SFGAO_LINK */
+    {
+       HRESULT hr;
+       BOOL Quoted;
+
+       if (wszApplicationName[0] == '"')
+       {
+           if (wszApplicationName[strlenW(wszApplicationName) - 1] == '"')
+           {
+               wszApplicationName[strlenW(wszApplicationName) - 1] = '\0';
+               Quoted = TRUE;
+           }
+           else
+           {
+               Quoted = FALSE;
+           }
+       }
+       else
+       {
+           Quoted = FALSE;
+       }
+       /* expand paths before reading shell link */
+       if (ExpandEnvironmentStringsW(Quoted ? sei_tmp.lpFile + 1 : sei_tmp.lpFile, buffer, MAX_PATH))
+           lstrcpyW(Quoted ? wszApplicationName + 1 : wszApplicationName/*sei_tmp.lpFile*/, buffer);
+
+       if (*sei_tmp.lpParameters)
+           if (ExpandEnvironmentStringsW(sei_tmp.lpParameters, buffer, MAX_PATH))
+               lstrcpyW(wszParameters/*sei_tmp.lpParameters*/, buffer);
+
+       hr = SHELL_ResolveShortCutW((LPWSTR)(Quoted ? sei_tmp.lpFile + 1 : sei_tmp.lpFile),
+                                   (LPWSTR)sei_tmp.lpParameters, (LPWSTR)sei_tmp.lpDirectory,
+                                   sei_tmp.hwnd, sei_tmp.lpVerb?sei_tmp.lpVerb:wszEmpty, &sei_tmp.nShow, (LPITEMIDLIST*)&sei_tmp.lpIDList);
+       if (Quoted)
+       {
+           wszApplicationName[strlenW(wszApplicationName) + 1] = '\0';
+           wszApplicationName[strlenW(wszApplicationName)] = '"';
+       }
+
+       if (sei->lpIDList)
+           sei->fMask |= SEE_MASK_IDLIST;
+
+       if (SUCCEEDED(hr))
+       {
+           /* repeat IDList processing if needed */
+           if (sei_tmp.fMask & SEE_MASK_IDLIST)
+           {
+               IShellExecuteHookW* pSEH;
+
+               HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookW, (LPVOID*)&pSEH, NULL);
+
+               if (SUCCEEDED(hr))
+               {
+                   hr = IShellExecuteHookW_Execute(pSEH, sei);
+
+                   IShellExecuteHookW_Release(pSEH);
+
+                   if (hr == S_OK)
+                       return TRUE;
                }
 
-               /* If we prevoiusly had a PIDL, it is now resolved, so forget it. */
-               pidl = tmpPidl;
-           } else
-               FIXME("We could not resolve the shell shortcut.\n");
+               TRACE("-- idlist=%p (%s)\n", debugstr_w(sei_tmp.lpIDList), debugstr_w(sei_tmp.lpFile));
+           }
+       }
+    }
+
+
+    /* Has the IDList not yet been translated? */
+    if (sei_tmp.fMask & SEE_MASK_IDLIST)
+    {
+       /* last chance to translate IDList: now also allow CLSID paths */
+       if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW(sei_tmp.lpIDList, buffer, sizeof(buffer)))) {
+           if (buffer[0]==':' && buffer[1]==':') {
+               /* open shell folder for the specified class GUID */
+               strcpyW(wszParameters, buffer);
+               strcpyW(wszApplicationName, wExplorer);
+
+               sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
+           } else if (HCR_GetExecuteCommandW(0, wszFolder, sei_tmp.lpVerb?sei_tmp.lpVerb:wszOpen, buffer, sizeof(buffer))) {
+               SHELL_ArgifyW(wszApplicationName, sizeof(wszApplicationName)/sizeof(WCHAR), buffer, NULL, sei_tmp.lpIDList, NULL);
+
+               sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
+           }
        }
     }
 
-    /* The following code is needed for example to resolve a shortcut
-       to control panel applet "Keyboard", since this is accessed using
-       "rundll32.exe shell32.dll,Control_RunDLL %1,%*" with a command line
-       parameter received from ISF_ControlPanel_fnGetDisplayNameOf(). */
-    if (!*szCommandline) {
+    /* expand environment strings */
+    if (ExpandEnvironmentStringsW(sei_tmp.lpFile, buffer, MAX_PATH))
+       lstrcpyW(wszApplicationName, buffer);
+
+    if (*sei_tmp.lpParameters)
+        if (ExpandEnvironmentStringsW(sei_tmp.lpParameters, buffer, MAX_PATH))
+           lstrcpyW(wszParameters, buffer);
+
+    if (*sei_tmp.lpDirectory)
+       if (ExpandEnvironmentStringsW(sei_tmp.lpDirectory, buffer, MAX_PATH))
+           lstrcpyW(wszDir, buffer);
+
+    /* Else, try to execute the filename */
+    TRACE("execute:%s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir));
+
+    /* separate out command line arguments from executable file name */
+    if (!*sei_tmp.lpParameters) {
        /* If the executable path is quoted, handle the rest of the command line as parameters. */
-       if (*szApplicationName == '"') {
-           LPSTR src = szApplicationName + 1;
-           LPSTR dst = fileName;
-           LPSTR end;
+       if (sei_tmp.lpFile[0] == '"') {
+           LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1;
+           LPWSTR dst = wfileName;
+           LPWSTR end;
 
-           /* copy the unquoted executabe path to 'fileName' */
+           /* copy the unquoted executable path to 'wfileName' */
            while(*src && *src!='"')
                *dst++ = *src++;
 
@@ -981,137 +1221,127 @@ BOOL WINAPI ShellExecuteExA32 (LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execf
            } else
                end = src;
 
-           /* copy the paremeter string to 'szCommandline' */
-           strcpy(szCommandline, src);
+           /* copy the parameter string to 'wszParameters' */
+           strcpyW(wszParameters, src);
 
-           /* terminate 'szApplicationName' after the quote character */
+           /* terminate previous command string after the quote character */
            *end = '\0';
        }
        else
        {
-           /* If the executrable name is not quoted, we have to use this search loop here,
+           /* If the executable name is not quoted, we have to use this search loop here,
               that in CreateProcess() is not sufficient because it does not handle shell links. */
-           LPSTR space, s;
-           char buffer[MAX_PATH], xlpFile[MAX_PATH];
+           WCHAR buffer[MAX_PATH], xlpFile[MAX_PATH];
+           LPWSTR space, s;
 
-           LPSTR beg = szApplicationName;
-           for(s=beg; (space=strchr(s, ' ')); s=space+1) {
-               int idx = space-szApplicationName;
-               strncpy(buffer, szApplicationName, idx);
+           LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/;
+           for(s=beg; (space=strchrW(s, ' ')); s=space+1) {
+               int idx = space-sei_tmp.lpFile;
+               memcpy(buffer, sei_tmp.lpFile, idx * sizeof(WCHAR));
                buffer[idx] = '\0';
 
-               if (SearchPathA(*dir? dir: NULL, buffer, ".exe", sizeof(xlpFile), xlpFile, NULL))
+               /*FIXME This finds directory paths if the targeted file name contains spaces. */
+               if (SearchPathW(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, buffer, wszExe, sizeof(xlpFile), xlpFile, NULL))
                {
                    /* separate out command from parameter string */
-                   LPCSTR p = space + 1;
+                   LPCWSTR p = space + 1;
 
-                   while(isspace(*p))
+                   while(isspaceW(*p))
                        ++p;
 
-                   strcpy(szCommandline, p);
+                   strcpyW(wszParameters, p);
                    *space = '\0';
 
                    break;
                }
            }
 
-           strcpy(fileName, szApplicationName);
+           strcpyW(wfileName, sei_tmp.lpFile);
        }
     } else
-       strcpy(fileName, szApplicationName);
+       strcpyW(wfileName, sei_tmp.lpFile);
 
-    lpFile = fileName;
+    lpFile = wfileName;
 
-    if (szCommandline[0]) {
-        strcat(szApplicationName, " ");
-        strcat(szApplicationName, szCommandline);
+    strcpyW(wcmd, wszApplicationName);
+    if (sei_tmp.lpParameters[0]) {
+        strcatW(wcmd, wSpace);
+        strcatW(wcmd, wszParameters);
     }
 
-    retval = execfunc(szApplicationName, NULL, dir, sei, FALSE);
-    if (retval > 32)
-    {
-       /* Now, that we have successfully launched a process, we can free the PIDL.
-       It may have been used before for %I command line options. */
-       if (tmpPidl)
-           SHFree(tmpPidl);
+    /* We set the default to open, and that should generally work.
+       But that is not really the way the MS docs say to do it. */
+    if (!sei_tmp.lpVerb)
+        sei_tmp.lpVerb = wszOpen;
 
-        TRACE("execfunc: retval=%d sei->hInstApp=%p\n", retval, sei->hInstApp);
+    retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
+    if (retval > 32)
         return TRUE;
-    }
 
     /* Else, try to find the executable */
-    cmd[0] = '\0';
-    retval = SHELL_FindExecutable(*dir? dir: NULL, lpFile, sei->lpVerb, cmd, lpstrProtocol, &env, pidl, szCommandline);
+    wcmd[0] = '\0';
+    retval = SHELL_FindExecutable(sei_tmp.lpDirectory, lpFile, sei_tmp.lpVerb, wcmd, 1024, lpstrProtocol, &env, sei_tmp.lpIDList, sei_tmp.lpParameters);
     if (retval > 32)  /* Found */
     {
-#if 0  /* SHELL_FindExecutable() already quoted by calling argify() */
-        CHAR szQuotedCmd[MAX_PATH+2];
-        /* Must quote to handle case where cmd contains spaces, 
+        WCHAR wszQuotedCmd[MAX_PATH+2];
+        /* Must quote to handle case where cmd contains spaces,
          * else security hole if malicious user creates executable file "C:\\Program"
-        *
-        * FIXME: If we don't have set explicitly command line arguments, we must first
-        * split executable path from optional command line arguments. Otherwise we would quote
-        * the complete string with executable path _and_ arguments, which is not what we want.
          */
-        if (szCommandline[0])
-            sprintf(szQuotedCmd, "\"%s\" %s", cmd, szCommandline);
-        else
-            sprintf(szQuotedCmd, "\"%s\"", cmd);
-        TRACE("%s/%s => %s/%s\n", szApplicationName, sei->lpVerb?sei->lpVerb:"NULL", szQuotedCmd, lpstrProtocol);
-        if (*lpstrProtocol)
-            retval = execute_from_key(lpstrProtocol, lpFile, env, dir, sei, execfunc, szCommandline, pidl);
-        else
-            retval = execfunc(szQuotedCmd, env, dir, sei, FALSE);
-#else
+        strcpyW(wszQuotedCmd, wQuote);
+        strcatW(wszQuotedCmd, wcmd);
+        strcatW(wszQuotedCmd, wQuote);
+        if (wszParameters[0]) {
+            strcatW(wszQuotedCmd, wSpace);
+            strcatW(wszQuotedCmd, wszParameters);
+        }
+        TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(sei_tmp.lpVerb), debugstr_w(wszQuotedCmd), debugstr_w(lpstrProtocol));
         if (*lpstrProtocol)
-            retval = execute_from_key(lpstrProtocol, lpFile, env, dir, sei, execfunc, cmd, pidl);
+            retval = execute_from_key(lpstrProtocol, wszApplicationName, env, sei_tmp.lpParameters, execfunc, &sei_tmp, sei);
         else
-            retval = execfunc(cmd, env, dir, sei, FALSE);
-#endif
-        if (env) HeapFree( GetProcessHeap(), 0, env );
+            retval = execfunc(wszQuotedCmd, env, FALSE, &sei_tmp, sei);
+        HeapFree( GetProcessHeap(), 0, env );
     }
-    else if (PathIsURLA((LPSTR)lpFile))    /* File not found, check for URL */
+    else if (PathIsURLW((LPWSTR)lpFile))    /* File not found, check for URL */
     {
-        LPSTR lpstrRes;
+       static const WCHAR wShell[] = {'\\','s','h','e','l','l','\\',0};
+       static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
+        LPWSTR lpstrRes;
         INT iSize;
 
-        lpstrRes = strchr(lpFile, ':');
+        lpstrRes = strchrW(lpFile, ':');
         if (lpstrRes)
             iSize = lpstrRes - lpFile;
         else
-            iSize = strlen(lpFile);
+            iSize = strlenW(lpFile);
 
-        TRACE("Got URL: %s\n", lpFile);
-        /* Looking for ...protocol\shell\<verb>\command */
-        strncpy(lpstrProtocol, lpFile, iSize);
+        TRACE("Got URL: %s\n", debugstr_w(lpFile));
+        /* Looking for ...protocol\shell\lpOperation\command */
+        memcpy(lpstrProtocol, lpFile, iSize*sizeof(WCHAR));
         lpstrProtocol[iSize] = '\0';
-        strcat(lpstrProtocol, "\\shell\\");
-        strcat(lpstrProtocol, sei->lpVerb? sei->lpVerb: "open");    /*FIXME: enumerate registry subkeys - compare with the loop into SHELL_FindExecutable() */
-        strcat(lpstrProtocol, "\\command");
+        strcatW(lpstrProtocol, wShell);
+        strcatW(lpstrProtocol, sei_tmp.lpVerb? sei_tmp.lpVerb: wszOpen);
+        strcatW(lpstrProtocol, wCommand);
 
         /* Remove File Protocol from lpFile */
         /* In the case file://path/file     */
-        if (!strncasecmp(lpFile, "file", iSize))
+        if (!strncmpiW(lpFile, wFile, iSize))
         {
             lpFile += iSize;
             while (*lpFile == ':') lpFile++;
         }
-        retval = execute_from_key(lpstrProtocol, lpFile, NULL, dir, sei, execfunc, szCommandline, pidl);
+        retval = execute_from_key(lpstrProtocol, lpFile, NULL, sei_tmp.lpParameters, execfunc, &sei_tmp, sei);
     }
     /* Check if file specified is in the form www.??????.*** */
-    else if (!strncasecmp(lpFile, "www", 3))
+    else if (!strncmpiW(lpFile, wWww, 3))
     {
         /* if so, append lpFile http:// and call ShellExecute */
-        char lpstrTmpFile[256] = "http://" ;
-        strcat(lpstrTmpFile, lpFile);
-        retval = (UINT)ShellExecuteA(sei->hwnd, sei->lpVerb, lpstrTmpFile, NULL, NULL, 0);
+        WCHAR lpstrTmpFile[256];
+        strcpyW(lpstrTmpFile, wHttp);
+        strcatW(lpstrTmpFile, lpFile);
+        retval = (UINT)ShellExecuteW(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
     }
 
-    /* Now we can free the PIDL. It may have been used before for %I command line options. */
-    if (tmpPidl)
-       SHFree(tmpPidl);
-
-    TRACE("ShellExecuteExA32 retval=%d\n", retval);
+    TRACE("retval %u\n", retval);
 
     if (retval <= 32)
     {
@@ -1132,7 +1362,10 @@ HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
     SHELLEXECUTEINFOA sei;
     HANDLE hProcess = 0;
 
-    TRACE("\n");
+    TRACE("%p,%s,%s,%s,%s,%d\n",
+          hWnd, debugstr_a(lpOperation), debugstr_a(lpFile),
+          debugstr_a(lpParameters), debugstr_a(lpDirectory), iShowCmd);
+
     sei.cbSize = sizeof(sei);
     sei.fMask = 0;
     sei.hwnd = hWnd;
@@ -1147,79 +1380,66 @@ HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
     sei.dwHotKey = 0;
     sei.hProcess = hProcess;
 
-    ShellExecuteExA32 (&sei, SHELL_ExecuteA);
+    ShellExecuteExA (&sei);
     return sei.hInstApp;
 }
 
-/*************************************************************************
- * ShellExecuteEx                              [SHELL32.291]
- *
- */
-BOOL WINAPI ShellExecuteExAW (LPVOID sei)
-{
-    if (SHELL_OsIsUnicode())
-       return ShellExecuteExW (sei);
-    return ShellExecuteExA32 (sei, SHELL_ExecuteA);
-}
-
 /*************************************************************************
  * ShellExecuteExA                             [SHELL32.292]
  *
  */
 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
 {
-    BOOL ret = ShellExecuteExA32 (sei, SHELL_ExecuteA);
-
-    TRACE("ShellExecuteExA(): ret=%d\n", ret);
-
-    return ret;
-}
-
-/*************************************************************************
- * ShellExecuteExW                             [SHELL32.293]
- *
- */
-BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
-{
-    SHELLEXECUTEINFOA seiA;
+    SHELLEXECUTEINFOW seiW;
     BOOL ret;
+    WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL, *wClass = NULL;
 
     TRACE("%p\n", sei);
 
-    memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
+    memcpy(&seiW, sei, sizeof(SHELLEXECUTEINFOW));
 
     if (sei->lpVerb)
-        seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
+       seiW.lpVerb = __SHCloneStrAtoW(&wVerb, sei->lpVerb);
 
     if (sei->lpFile)
-        seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
+        seiW.lpFile = __SHCloneStrAtoW(&wFile, sei->lpFile);
 
     if (sei->lpParameters)
-        seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
+        seiW.lpParameters = __SHCloneStrAtoW(&wParameters, sei->lpParameters);
 
     if (sei->lpDirectory)
-        seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
+        seiW.lpDirectory = __SHCloneStrAtoW(&wDirectory, sei->lpDirectory);
 
-    if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
-        seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
+    if ((sei->fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME && sei->lpClass)
+        seiW.lpClass = __SHCloneStrAtoW(&wClass, sei->lpClass);
     else
-        seiA.lpClass = NULL;
+        seiW.lpClass = NULL;
 
-    ret = ShellExecuteExA(&seiA);
+    ret = ShellExecuteExW32 (&seiW, SHELL_ExecuteW);
 
-    if (seiA.lpVerb)   HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
-    if (seiA.lpFile)   HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
-    if (seiA.lpParameters)     HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
-    if (seiA.lpDirectory)      HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
-    if (seiA.lpClass)  HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
+    sei->hInstApp = seiW.hInstApp;
 
-    sei->hInstApp = seiA.hInstApp;
+    if (sei->fMask & SEE_MASK_NOCLOSEPROCESS)
+        sei->hProcess = seiW.hProcess;
 
-    TRACE("ShellExecuteExW(): ret=%d\n", ret);
+    if (wVerb) SHFree(wVerb);
+    if (wFile) SHFree(wFile);
+    if (wParameters) SHFree(wParameters);
+    if (wDirectory) SHFree(wDirectory);
+    if (wClass) SHFree(wClass);
 
     return ret;
 }
 
+/*************************************************************************
+ * ShellExecuteExW                             [SHELL32.293]
+ *
+ */
+BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
+{
+    return  ShellExecuteExW32 (sei, SHELL_ExecuteW);
+}
+
 /*************************************************************************
  * ShellExecuteW                       [SHELL32.294]
  * from shellapi.h
@@ -1231,7 +1451,6 @@ HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
 {
     SHELLEXECUTEINFOW sei;
     HANDLE hProcess = 0;
-    int ret;
 
     TRACE("\n");
     sei.cbSize = sizeof(sei);
@@ -1248,8 +1467,6 @@ HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
     sei.dwHotKey = 0;
     sei.hProcess = hProcess;
 
-    ret = ShellExecuteExW(&sei);
-
-    TRACE("ShellExecuteW(): ret=%d module=%p", ret, sei.hInstApp);
+    ShellExecuteExW32 (&sei, SHELL_ExecuteW);
     return sei.hInstApp;
 }