push 3cf4bc9cdb38c4fc36232fe19b9b904fd4d068e9
[wine/hacks.git] / dlls / shell32 / shlexec.c
blob515bb48648c98762a85d45b7c6b5b96a4beeaa32
1 /*
2 * Shell Library Functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include <ctype.h>
33 #include <assert.h>
35 #define COBJMACROS
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "winreg.h"
41 #include "winuser.h"
42 #include "shlwapi.h"
43 #include "ddeml.h"
45 #include "wine/winbase16.h"
46 #include "shell32_main.h"
47 #include "pidl.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(exec);
53 static const WCHAR wszOpen[] = {'o','p','e','n',0};
54 static const WCHAR wszExe[] = {'.','e','x','e',0};
55 static const WCHAR wszILPtr[] = {':','%','p',0};
56 static const WCHAR wszShell[] = {'\\','s','h','e','l','l','\\',0};
57 static const WCHAR wszFolder[] = {'F','o','l','d','e','r',0};
58 static const WCHAR wszEmpty[] = {0};
60 #define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
63 /***********************************************************************
64 * SHELL_ArgifyW [Internal]
66 * this function is supposed to expand the escape sequences found in the registry
67 * some diving reported that the following were used:
68 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
69 * %1 file
70 * %2 printer
71 * %3 driver
72 * %4 port
73 * %I address of a global item ID (explorer switch /idlist)
74 * %L seems to be %1 as long filename followed by the 8+3 variation
75 * %S ???
76 * %* all following parameters (see batfile)
79 static BOOL SHELL_ArgifyW(WCHAR* out, int len, const WCHAR* fmt, const WCHAR* lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD* out_len)
81 WCHAR xlpFile[1024];
82 BOOL done = FALSE;
83 BOOL found_p1 = FALSE;
84 PWSTR res = out;
85 PCWSTR cmd;
86 DWORD used = 0;
88 TRACE("%p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
89 debugstr_w(lpFile), pidl, args);
91 while (*fmt)
93 if (*fmt == '%')
95 switch (*++fmt)
97 case '\0':
98 case '%':
99 used++;
100 if (used < len)
101 *res++ = '%';
102 break;
104 case '2':
105 case '3':
106 case '4':
107 case '5':
108 case '6':
109 case '7':
110 case '8':
111 case '9':
112 case '0':
113 case '*':
114 if (args)
116 if (*fmt == '*')
118 used++;
119 if (used < len)
120 *res++ = '"';
121 while(*args)
123 used++;
124 if (used < len)
125 *res++ = *args++;
126 else
127 args++;
129 used++;
130 if (used < len)
131 *res++ = '"';
133 else
135 while(*args && !isspace(*args))
137 used++;
138 if (used < len)
139 *res++ = *args++;
140 else
141 args++;
144 while(isspace(*args))
145 ++args;
147 break;
149 /* else fall through */
150 case '1':
151 if (!done || (*fmt == '1'))
153 /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
154 if (SearchPathW(NULL, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
155 cmd = xlpFile;
156 else
157 cmd = lpFile;
159 used += strlenW(cmd);
160 if (used < len)
162 strcpyW(res, cmd);
163 res += strlenW(cmd);
166 found_p1 = TRUE;
167 break;
170 * IE uses this a lot for activating things such as windows media
171 * player. This is not verified to be fully correct but it appears
172 * to work just fine.
174 case 'l':
175 case 'L':
176 if (lpFile) {
177 used += strlenW(lpFile);
178 if (used < len)
180 strcpyW(res, lpFile);
181 res += strlenW(lpFile);
184 found_p1 = TRUE;
185 break;
187 case 'i':
188 case 'I':
189 if (pidl) {
190 INT chars = 0;
191 /* %p should not exceed 8, maybe 16 when looking forward to 64bit.
192 * allowing a buffer of 100 should more than exceed all needs */
193 WCHAR buf[100];
194 LPVOID pv;
195 HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
196 pv = SHLockShared(hmem, 0);
197 chars = sprintfW(buf, wszILPtr, pv);
198 if (chars >= sizeof(buf)/sizeof(WCHAR))
199 ERR("pidl format buffer too small!\n");
200 used += chars;
201 if (used < len)
203 strcpyW(res,buf);
204 res += chars;
206 SHUnlockShared(pv);
208 found_p1 = TRUE;
209 break;
211 default:
213 * Check if this is an env-variable here...
216 /* Make sure that we have at least one more %.*/
217 if (strchrW(fmt, '%'))
219 WCHAR tmpBuffer[1024];
220 PWSTR tmpB = tmpBuffer;
221 WCHAR tmpEnvBuff[MAX_PATH];
222 DWORD envRet;
224 while (*fmt != '%')
225 *tmpB++ = *fmt++;
226 *tmpB++ = 0;
228 TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer));
230 envRet = GetEnvironmentVariableW(tmpBuffer, tmpEnvBuff, MAX_PATH);
231 if (envRet == 0 || envRet > MAX_PATH)
233 used += strlenW(tmpBuffer);
234 if (used < len)
236 strcpyW( res, tmpBuffer );
237 res += strlenW(tmpBuffer);
240 else
242 used += strlenW(tmpEnvBuff);
243 if (used < len)
245 strcpyW( res, tmpEnvBuff );
246 res += strlenW(tmpEnvBuff);
250 done = TRUE;
251 break;
253 /* Don't skip past terminator (catch a single '%' at the end) */
254 if (*fmt != '\0')
256 fmt++;
259 else
261 used ++;
262 if (used < len)
263 *res++ = *fmt++;
264 else
265 fmt++;
269 *res = '\0';
270 TRACE("used %i of %i space\n",used,len);
271 if (out_len)
272 *out_len = used;
274 return found_p1;
277 static HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
279 STRRET strret;
280 IShellFolder* desktop;
282 HRESULT hr = SHGetDesktopFolder(&desktop);
284 if (SUCCEEDED(hr)) {
285 hr = IShellFolder_GetDisplayNameOf(desktop, pidl, SHGDN_FORPARSING, &strret);
287 if (SUCCEEDED(hr))
288 StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
290 IShellFolder_Release(desktop);
293 return hr;
296 /*************************************************************************
297 * SHELL_ExecuteW [Internal]
300 static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
301 const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
303 STARTUPINFOW startup;
304 PROCESS_INFORMATION info;
305 UINT_PTR retval = SE_ERR_NOASSOC;
306 UINT gcdret = 0;
307 WCHAR curdir[MAX_PATH];
308 DWORD dwCreationFlags;
309 const WCHAR *lpDirectory = NULL;
311 TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
313 /* make sure we don't fail the CreateProcess if the calling app passes in
314 * a bad working directory */
315 if (psei->lpDirectory && psei->lpDirectory[0])
317 DWORD attr = GetFileAttributesW(psei->lpDirectory);
318 if (attr != INVALID_FILE_ATTRIBUTES && attr & FILE_ATTRIBUTE_DIRECTORY)
319 lpDirectory = psei->lpDirectory;
322 /* ShellExecute specifies the command from psei->lpDirectory
323 * if present. Not from the current dir as CreateProcess does */
324 if( lpDirectory )
325 if( ( gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
326 if( !SetCurrentDirectoryW( lpDirectory))
327 ERR("cannot set directory %s\n", debugstr_w(lpDirectory));
328 ZeroMemory(&startup,sizeof(STARTUPINFOW));
329 startup.cb = sizeof(STARTUPINFOW);
330 startup.dwFlags = STARTF_USESHOWWINDOW;
331 startup.wShowWindow = psei->nShow;
332 dwCreationFlags = CREATE_UNICODE_ENVIRONMENT;
333 if (psei->fMask & SEE_MASK_NO_CONSOLE)
334 dwCreationFlags |= CREATE_NEW_CONSOLE;
335 if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env,
336 lpDirectory, &startup, &info))
338 /* Give 30 seconds to the app to come up, if desired. Probably only needed
339 when starting app immediately before making a DDE connection. */
340 if (shWait)
341 if (WaitForInputIdle( info.hProcess, 30000 ) == WAIT_FAILED)
342 WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
343 retval = 33;
344 if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
345 psei_out->hProcess = info.hProcess;
346 else
347 CloseHandle( info.hProcess );
348 CloseHandle( info.hThread );
350 else if ((retval = GetLastError()) >= 32)
352 TRACE("CreateProcess returned error %ld\n", retval);
353 retval = ERROR_BAD_FORMAT;
356 TRACE("returning %lu\n", retval);
358 psei_out->hInstApp = (HINSTANCE)retval;
359 if( gcdret )
360 if( !SetCurrentDirectoryW( curdir))
361 ERR("cannot return to directory %s\n", debugstr_w(curdir));
363 return retval;
367 /***********************************************************************
368 * SHELL_BuildEnvW [Internal]
370 * Build the environment for the new process, adding the specified
371 * path to the PATH variable. Returned pointer must be freed by caller.
373 static void *SHELL_BuildEnvW( const WCHAR *path )
375 static const WCHAR wPath[] = {'P','A','T','H','=',0};
376 WCHAR *strings, *new_env;
377 WCHAR *p, *p2;
378 int total = strlenW(path) + 1;
379 BOOL got_path = FALSE;
381 if (!(strings = GetEnvironmentStringsW())) return NULL;
382 p = strings;
383 while (*p)
385 int len = strlenW(p) + 1;
386 if (!strncmpiW( p, wPath, 5 )) got_path = TRUE;
387 total += len;
388 p += len;
390 if (!got_path) total += 5; /* we need to create PATH */
391 total++; /* terminating null */
393 if (!(new_env = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) )))
395 FreeEnvironmentStringsW( strings );
396 return NULL;
398 p = strings;
399 p2 = new_env;
400 while (*p)
402 int len = strlenW(p) + 1;
403 memcpy( p2, p, len * sizeof(WCHAR) );
404 if (!strncmpiW( p, wPath, 5 ))
406 p2[len - 1] = ';';
407 strcpyW( p2 + len, path );
408 p2 += strlenW(path) + 1;
410 p += len;
411 p2 += len;
413 if (!got_path)
415 strcpyW( p2, wPath );
416 strcatW( p2, path );
417 p2 += strlenW(p2) + 1;
419 *p2 = 0;
420 FreeEnvironmentStringsW( strings );
421 return new_env;
425 /***********************************************************************
426 * SHELL_TryAppPathW [Internal]
428 * Helper function for SHELL_FindExecutable
429 * @param lpResult - pointer to a buffer of size MAX_PATH
430 * On entry: szName is a filename (probably without path separators).
431 * On exit: if szName found in "App Path", place full path in lpResult, and return true
433 static BOOL SHELL_TryAppPathW( LPCWSTR szName, LPWSTR lpResult, WCHAR **env)
435 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',
436 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','A','p','p',' ','P','a','t','h','s','\\',0};
437 static const WCHAR wPath[] = {'P','a','t','h',0};
438 HKEY hkApp = 0;
439 WCHAR buffer[1024];
440 LONG len;
441 LONG res;
442 BOOL found = FALSE;
444 if (env) *env = NULL;
445 strcpyW(buffer, wszKeyAppPaths);
446 strcatW(buffer, szName);
447 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
448 if (res) goto end;
450 len = MAX_PATH*sizeof(WCHAR);
451 res = RegQueryValueW(hkApp, NULL, lpResult, &len);
452 if (res) goto end;
453 found = TRUE;
455 if (env)
457 DWORD count = sizeof(buffer);
458 if (!RegQueryValueExW(hkApp, wPath, NULL, NULL, (LPBYTE)buffer, &count) && buffer[0])
459 *env = SHELL_BuildEnvW( buffer );
462 end:
463 if (hkApp) RegCloseKey(hkApp);
464 return found;
467 static UINT SHELL_FindExecutableByOperation(LPCWSTR lpOperation, LPWSTR key, LPWSTR filetype, LPWSTR command, LONG commandlen)
469 static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
470 HKEY hkeyClass;
471 WCHAR verb[MAX_PATH];
473 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, filetype, 0, 0x02000000, &hkeyClass))
474 return SE_ERR_NOASSOC;
475 if (!HCR_GetDefaultVerbW(hkeyClass, lpOperation, verb, sizeof(verb)/sizeof(verb[0])))
476 return SE_ERR_NOASSOC;
477 RegCloseKey(hkeyClass);
479 /* Looking for ...buffer\shell\<verb>\command */
480 strcatW(filetype, wszShell);
481 strcatW(filetype, verb);
482 strcatW(filetype, wCommand);
484 if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, command,
485 &commandlen) == ERROR_SUCCESS)
487 commandlen /= sizeof(WCHAR);
488 if (key) strcpyW(key, filetype);
489 #if 0
490 LPWSTR tmp;
491 WCHAR param[256];
492 LONG paramlen = sizeof(param);
493 static const WCHAR wSpace[] = {' ',0};
495 /* FIXME: it seems all Windows version don't behave the same here.
496 * the doc states that this ddeexec information can be found after
497 * the exec names.
498 * on Win98, it doesn't appear, but I think it does on Win2k
500 /* Get the parameters needed by the application
501 from the associated ddeexec key */
502 tmp = strstrW(filetype, wCommand);
503 tmp[0] = '\0';
504 strcatW(filetype, wDdeexec);
505 if (RegQueryValueW(HKEY_CLASSES_ROOT, filetype, param,
506 &paramlen) == ERROR_SUCCESS)
508 paramlen /= sizeof(WCHAR);
509 strcatW(command, wSpace);
510 strcatW(command, param);
511 commandlen += paramlen;
513 #endif
515 command[commandlen] = '\0';
517 return 33; /* FIXME see SHELL_FindExecutable() */
520 return SE_ERR_NOASSOC;
523 /*************************************************************************
524 * SHELL_FindExecutable [Internal]
526 * Utility for code sharing between FindExecutable and ShellExecute
527 * in:
528 * lpFile the name of a file
529 * lpOperation the operation on it (open)
530 * out:
531 * lpResult a buffer, big enough :-(, to store the command to do the
532 * operation on the file
533 * key a buffer, big enough, to get the key name to do actually the
534 * command (it'll be used afterwards for more information
535 * on the operation)
537 static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpOperation,
538 LPWSTR lpResult, int resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
540 static const WCHAR wWindows[] = {'w','i','n','d','o','w','s',0};
541 static const WCHAR wPrograms[] = {'p','r','o','g','r','a','m','s',0};
542 static const WCHAR wExtensions[] = {'e','x','e',' ','p','i','f',' ','b','a','t',' ','c','m','d',' ','c','o','m',0};
543 WCHAR *extension = NULL; /* pointer to file extension */
544 WCHAR filetype[256]; /* registry name for this filetype */
545 LONG filetypelen = sizeof(filetype); /* length of above */
546 WCHAR command[1024]; /* command from registry */
547 WCHAR wBuffer[256]; /* Used to GetProfileString */
548 UINT retval = SE_ERR_NOASSOC;
549 WCHAR *tok; /* token pointer */
550 WCHAR xlpFile[256]; /* result of SearchPath */
551 DWORD attribs; /* file attributes */
553 TRACE("%s\n", debugstr_w(lpFile));
555 if (!lpResult)
556 return ERROR_INVALID_PARAMETER;
558 xlpFile[0] = '\0';
559 lpResult[0] = '\0'; /* Start off with an empty return string */
560 if (key) *key = '\0';
562 /* trap NULL parameters on entry */
563 if (!lpFile)
565 WARN("(lpFile=%s,lpResult=%s): NULL parameter\n",
566 debugstr_w(lpFile), debugstr_w(lpResult));
567 return ERROR_FILE_NOT_FOUND; /* File not found. Close enough, I guess. */
570 if (SHELL_TryAppPathW( lpFile, lpResult, env ))
572 TRACE("found %s via App Paths\n", debugstr_w(lpResult));
573 return 33;
576 if (SearchPathW(lpPath, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
578 TRACE("SearchPathW returned non-zero\n");
579 lpFile = xlpFile;
580 /* Hey, isn't this value ignored? Why make this call? Shouldn't we return here? --dank*/
583 attribs = GetFileAttributesW(lpFile);
584 if (attribs!=INVALID_FILE_ATTRIBUTES && (attribs&FILE_ATTRIBUTE_DIRECTORY))
586 strcpyW(filetype, wszFolder);
587 filetypelen = 6; /* strlen("Folder") */
589 else
591 /* Did we get something? Anything? */
592 if (xlpFile[0]==0)
594 TRACE("Returning SE_ERR_FNF\n");
595 return SE_ERR_FNF;
597 /* First thing we need is the file's extension */
598 extension = strrchrW(xlpFile, '.'); /* Assume last "." is the one; */
599 /* File->Run in progman uses */
600 /* .\FILE.EXE :( */
601 TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile), debugstr_w(extension));
603 if (extension == NULL || extension[1]==0)
605 WARN("Returning SE_ERR_NOASSOC\n");
606 return SE_ERR_NOASSOC;
609 /* Three places to check: */
610 /* 1. win.ini, [windows], programs (NB no leading '.') */
611 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
612 /* 3. win.ini, [extensions], extension (NB no leading '.' */
613 /* All I know of the order is that registry is checked before */
614 /* extensions; however, it'd make sense to check the programs */
615 /* section first, so that's what happens here. */
617 /* See if it's a program - if GetProfileString fails, we skip this
618 * section. Actually, if GetProfileString fails, we've probably
619 * got a lot more to worry about than running a program... */
620 if (GetProfileStringW(wWindows, wPrograms, wExtensions, wBuffer, sizeof(wBuffer)/sizeof(WCHAR)) > 0)
622 CharLowerW(wBuffer);
623 tok = wBuffer;
624 while (*tok)
626 WCHAR *p = tok;
627 while (*p && *p != ' ' && *p != '\t') p++;
628 if (*p)
630 *p++ = 0;
631 while (*p == ' ' || *p == '\t') p++;
634 if (strcmpiW(tok, &extension[1]) == 0) /* have to skip the leading "." */
636 strcpyW(lpResult, xlpFile);
637 /* Need to perhaps check that the file has a path
638 * attached */
639 TRACE("found %s\n", debugstr_w(lpResult));
640 return 33;
641 /* Greater than 32 to indicate success */
643 tok = p;
647 /* Check registry */
648 if (RegQueryValueW(HKEY_CLASSES_ROOT, extension, filetype,
649 &filetypelen) == ERROR_SUCCESS)
651 filetypelen /= sizeof(WCHAR);
652 if (filetypelen == sizeof(filetype)/sizeof(WCHAR))
653 filetypelen--;
654 filetype[filetypelen] = '\0';
655 TRACE("File type: %s\n", debugstr_w(filetype));
657 else
659 *filetype = '\0';
660 filetypelen = 0;
664 if (*filetype)
666 /* pass the operation string to SHELL_FindExecutableByOperation() */
667 filetype[filetypelen] = '\0';
668 retval = SHELL_FindExecutableByOperation(lpOperation, key, filetype, command, sizeof(command));
670 if (retval > 32)
672 DWORD finishedLen;
673 SHELL_ArgifyW(lpResult, resultLen, command, xlpFile, pidl, args, &finishedLen);
674 if (finishedLen > resultLen)
675 ERR("Argify buffer not large enough.. truncated\n");
677 /* Remove double quotation marks and command line arguments */
678 if (*lpResult == '"')
680 WCHAR *p = lpResult;
681 while (*(p + 1) != '"')
683 *p = *(p + 1);
684 p++;
686 *p = '\0';
688 else
690 /* Truncate on first space */
691 WCHAR *p = lpResult;
692 while (*p != ' ' && *p != '\0')
693 p++;
694 *p='\0';
698 else /* Check win.ini */
700 static const WCHAR wExtensions[] = {'e','x','t','e','n','s','i','o','n','s',0};
702 /* Toss the leading dot */
703 extension++;
704 if (GetProfileStringW(wExtensions, extension, wszEmpty, command, sizeof(command)/sizeof(WCHAR)) > 0)
706 if (strlenW(command) != 0)
708 strcpyW(lpResult, command);
709 tok = strchrW(lpResult, '^'); /* should be ^.extension? */
710 if (tok != NULL)
712 tok[0] = '\0';
713 strcatW(lpResult, xlpFile); /* what if no dir in xlpFile? */
714 tok = strchrW(command, '^'); /* see above */
715 if ((tok != NULL) && (strlenW(tok)>5))
717 strcatW(lpResult, &tok[5]);
720 retval = 33; /* FIXME - see above */
725 TRACE("returning %s\n", debugstr_w(lpResult));
726 return retval;
729 /******************************************************************
730 * dde_cb
732 * callback for the DDE connection. not really useful
734 static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
735 HSZ hsz1, HSZ hsz2, HDDEDATA hData,
736 ULONG_PTR dwData1, ULONG_PTR dwData2)
738 TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
739 uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
740 return NULL;
743 /******************************************************************
744 * dde_connect
746 * ShellExecute helper. Used to do an operation with a DDE connection
748 * Handles both the direct connection (try #1), and if it fails,
749 * launching an application and trying (#2) to connect to it
752 static unsigned dde_connect(const WCHAR* key, const WCHAR* start, WCHAR* ddeexec,
753 const WCHAR* lpFile, WCHAR *env,
754 LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc,
755 const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
757 static const WCHAR wApplication[] = {'\\','a','p','p','l','i','c','a','t','i','o','n',0};
758 static const WCHAR wTopic[] = {'\\','t','o','p','i','c',0};
759 WCHAR regkey[256];
760 WCHAR * endkey = regkey + strlenW(key);
761 WCHAR app[256], topic[256], ifexec[256], res[256];
762 LONG applen, topiclen, ifexeclen;
763 WCHAR * exec;
764 DWORD ddeInst = 0;
765 DWORD tid;
766 DWORD resultLen;
767 HSZ hszApp, hszTopic;
768 HCONV hConv;
769 HDDEDATA hDdeData;
770 unsigned ret = SE_ERR_NOASSOC;
771 BOOL unicode = !(GetVersion() & 0x80000000);
773 strcpyW(regkey, key);
774 strcpyW(endkey, wApplication);
775 applen = sizeof(app);
776 if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, app, &applen) != ERROR_SUCCESS)
778 WCHAR command[1024], fullpath[MAX_PATH];
779 static const WCHAR wSo[] = { '.','s','o',0 };
780 int sizeSo = sizeof(wSo)/sizeof(WCHAR);
781 LPWSTR ptr = NULL;
782 DWORD ret = 0;
784 /* Get application command from start string and find filename of application */
785 if (*start == '"')
787 strcpyW(command, start+1);
788 if ((ptr = strchrW(command, '"')))
789 *ptr = 0;
790 ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr);
792 else
794 LPWSTR p,space;
795 for (p=(LPWSTR)start; (space=strchrW(p, ' ')); p=space+1)
797 int idx = space-start;
798 memcpy(command, start, idx*sizeof(WCHAR));
799 command[idx] = '\0';
800 if ((ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr)))
801 break;
803 if (!ret)
804 ret = SearchPathW(NULL, start, wszExe, sizeof(fullpath)/sizeof(WCHAR), fullpath, &ptr);
807 if (!ret)
809 ERR("Unable to find application path for command %s\n", debugstr_w(start));
810 return ERROR_ACCESS_DENIED;
812 strcpyW(app, ptr);
814 /* Remove extensions (including .so) */
815 ptr = app + strlenW(app) - (sizeSo-1);
816 if (strlenW(app) >= sizeSo &&
817 !strcmpW(ptr, wSo))
818 *ptr = 0;
820 ptr = strrchrW(app, '.');
821 assert(ptr);
822 *ptr = 0;
825 strcpyW(endkey, wTopic);
826 topiclen = sizeof(topic);
827 if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, topic, &topiclen) != ERROR_SUCCESS)
829 static const WCHAR wSystem[] = {'S','y','s','t','e','m',0};
830 strcpyW(topic, wSystem);
833 if (unicode)
835 if (DdeInitializeW(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
836 return 2;
838 else
840 if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
841 return 2;
844 hszApp = DdeCreateStringHandleW(ddeInst, app, CP_WINUNICODE);
845 hszTopic = DdeCreateStringHandleW(ddeInst, topic, CP_WINUNICODE);
847 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
848 exec = ddeexec;
849 if (!hConv)
851 static const WCHAR wIfexec[] = {'\\','i','f','e','x','e','c',0};
852 TRACE("Launching %s\n", debugstr_w(start));
853 ret = execfunc(start, env, TRUE, psei, psei_out);
854 if (ret <= 32)
856 TRACE("Couldn't launch\n");
857 goto error;
859 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
860 if (!hConv)
862 TRACE("Couldn't connect. ret=%d\n", ret);
863 DdeUninitialize(ddeInst);
864 SetLastError(ERROR_DDE_FAIL);
865 return 30; /* whatever */
867 strcpyW(endkey, wIfexec);
868 ifexeclen = sizeof(ifexec);
869 if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, ifexec, &ifexeclen) == ERROR_SUCCESS)
871 exec = ifexec;
875 SHELL_ArgifyW(res, sizeof(res)/sizeof(WCHAR), exec, lpFile, pidl, szCommandline, &resultLen);
876 if (resultLen > sizeof(res)/sizeof(WCHAR))
877 ERR("Argify buffer not large enough, truncated\n");
878 TRACE("%s %s => %s\n", debugstr_w(exec), debugstr_w(lpFile), debugstr_w(res));
880 /* It's documented in the KB 330337 that IE has a bug and returns
881 * error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
883 if (unicode)
884 hDdeData = DdeClientTransaction((LPBYTE)res, (strlenW(res) + 1) * sizeof(WCHAR), hConv, 0L, 0,
885 XTYP_EXECUTE, 30000, &tid);
886 else
888 DWORD lenA = WideCharToMultiByte(CP_ACP, 0, res, -1, NULL, 0, NULL, NULL);
889 char *resA = HeapAlloc(GetProcessHeap(), 0, lenA);
890 WideCharToMultiByte(CP_ACP, 0, res, -1, resA, lenA, NULL, NULL);
891 hDdeData = DdeClientTransaction( (LPBYTE)resA, lenA, hConv, 0L, 0,
892 XTYP_EXECUTE, 10000, &tid );
893 HeapFree(GetProcessHeap(), 0, resA);
895 if (hDdeData)
896 DdeFreeDataHandle(hDdeData);
897 else
898 WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst));
899 ret = 33;
901 DdeDisconnect(hConv);
903 error:
904 DdeUninitialize(ddeInst);
906 return ret;
909 /*************************************************************************
910 * execute_from_key [Internal]
912 static UINT_PTR execute_from_key(LPCWSTR key, LPCWSTR lpFile, WCHAR *env, LPCWSTR szCommandline,
913 LPCWSTR executable_name,
914 SHELL_ExecuteW32 execfunc,
915 LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
917 static const WCHAR wCommand[] = {'c','o','m','m','a','n','d',0};
918 static const WCHAR wDdeexec[] = {'d','d','e','e','x','e','c',0};
919 WCHAR cmd[256], param[1024], ddeexec[256];
920 LONG cmdlen = sizeof(cmd), ddeexeclen = sizeof(ddeexec);
921 UINT_PTR retval = SE_ERR_NOASSOC;
922 DWORD resultLen;
923 LPWSTR tmp;
925 TRACE("%s %s %s %s %s\n", debugstr_w(key), debugstr_w(lpFile), debugstr_w(env),
926 debugstr_w(szCommandline), debugstr_w(executable_name));
928 cmd[0] = '\0';
929 param[0] = '\0';
931 /* Get the application from the registry */
932 if (RegQueryValueW(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
934 TRACE("got cmd: %s\n", debugstr_w(cmd));
936 /* Is there a replace() function anywhere? */
937 cmdlen /= sizeof(WCHAR);
938 cmd[cmdlen] = '\0';
939 SHELL_ArgifyW(param, sizeof(param)/sizeof(WCHAR), cmd, lpFile, psei->lpIDList, szCommandline, &resultLen);
940 if (resultLen > sizeof(param)/sizeof(WCHAR))
941 ERR("Argify buffer not large enough, truncating\n");
944 /* Get the parameters needed by the application
945 from the associated ddeexec key */
946 tmp = strstrW(key, wCommand);
947 assert(tmp);
948 strcpyW(tmp, wDdeexec);
950 if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ddeexec, &ddeexeclen) == ERROR_SUCCESS)
952 TRACE("Got ddeexec %s => %s\n", debugstr_w(key), debugstr_w(ddeexec));
953 if (!param[0]) strcpyW(param, executable_name);
954 retval = dde_connect(key, param, ddeexec, lpFile, env, szCommandline, psei->lpIDList, execfunc, psei, psei_out);
956 else if (param[0])
958 TRACE("executing: %s\n", debugstr_w(param));
959 retval = execfunc(param, env, FALSE, psei, psei_out);
961 else
962 WARN("Nothing appropriate found for %s\n", debugstr_w(key));
964 return retval;
967 /*************************************************************************
968 * FindExecutableA [SHELL32.@]
970 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
972 HINSTANCE retval;
973 WCHAR *wFile = NULL, *wDirectory = NULL;
974 WCHAR wResult[MAX_PATH];
976 if (lpFile) __SHCloneStrAtoW(&wFile, lpFile);
977 if (lpDirectory) __SHCloneStrAtoW(&wDirectory, lpDirectory);
979 retval = FindExecutableW(wFile, wDirectory, wResult);
980 WideCharToMultiByte(CP_ACP, 0, wResult, -1, lpResult, MAX_PATH, NULL, NULL);
981 SHFree( wFile );
982 SHFree( wDirectory );
984 TRACE("returning %s\n", lpResult);
985 return retval;
988 /*************************************************************************
989 * FindExecutableW [SHELL32.@]
991 * This function returns the executable associated with the specified file
992 * for the default verb.
994 * PARAMS
995 * lpFile [I] The file to find the association for. This must refer to
996 * an existing file otherwise FindExecutable fails and returns
997 * SE_ERR_FNF.
998 * lpResult [O] Points to a buffer into which the executable path is
999 * copied. This parameter must not be NULL otherwise
1000 * FindExecutable() segfaults. The buffer must be of size at
1001 * least MAX_PATH characters.
1003 * RETURNS
1004 * A value greater than 32 on success, less than or equal to 32 otherwise.
1005 * See the SE_ERR_* constants.
1007 * NOTES
1008 * On Windows XP and 2003, FindExecutable() seems to first convert the
1009 * filename into 8.3 format, thus taking into account only the first three
1010 * characters of the extension, and expects to find an association for those.
1011 * However other Windows versions behave sanely.
1013 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
1015 UINT_PTR retval = SE_ERR_NOASSOC;
1016 WCHAR old_dir[1024];
1018 TRACE("File %s, Dir %s\n", debugstr_w(lpFile), debugstr_w(lpDirectory));
1020 lpResult[0] = '\0'; /* Start off with an empty return string */
1021 if (lpFile == NULL)
1022 return (HINSTANCE)SE_ERR_FNF;
1024 if (lpDirectory)
1026 GetCurrentDirectoryW(sizeof(old_dir)/sizeof(WCHAR), old_dir);
1027 SetCurrentDirectoryW(lpDirectory);
1030 retval = SHELL_FindExecutable(lpDirectory, lpFile, wszOpen, lpResult, MAX_PATH, NULL, NULL, NULL, NULL);
1032 TRACE("returning %s\n", debugstr_w(lpResult));
1033 if (lpDirectory)
1034 SetCurrentDirectoryW(old_dir);
1035 return (HINSTANCE)retval;
1038 /* FIXME: is this already implemented somewhere else? */
1039 static HKEY ShellExecute_GetClassKey( const SHELLEXECUTEINFOW *sei )
1041 LPCWSTR ext = NULL, lpClass = NULL;
1042 LPWSTR cls = NULL;
1043 DWORD type = 0, sz = 0;
1044 HKEY hkey = 0;
1045 LONG r;
1047 if (sei->fMask & SEE_MASK_CLASSALL)
1048 return sei->hkeyClass;
1050 if (sei->fMask & SEE_MASK_CLASSNAME)
1051 lpClass = sei->lpClass;
1052 else
1054 ext = PathFindExtensionW( sei->lpFile );
1055 TRACE("ext = %s\n", debugstr_w( ext ) );
1056 if (!ext)
1057 return hkey;
1059 r = RegOpenKeyW( HKEY_CLASSES_ROOT, ext, &hkey );
1060 if (r != ERROR_SUCCESS )
1061 return hkey;
1063 r = RegQueryValueExW( hkey, NULL, 0, &type, NULL, &sz );
1064 if ( r == ERROR_SUCCESS && type == REG_SZ )
1066 sz += sizeof (WCHAR);
1067 cls = HeapAlloc( GetProcessHeap(), 0, sz );
1068 cls[0] = 0;
1069 RegQueryValueExW( hkey, NULL, 0, &type, (LPBYTE) cls, &sz );
1072 RegCloseKey( hkey );
1073 lpClass = cls;
1076 TRACE("class = %s\n", debugstr_w(lpClass) );
1078 hkey = 0;
1079 if ( lpClass )
1080 RegOpenKeyW( HKEY_CLASSES_ROOT, lpClass, &hkey );
1082 HeapFree( GetProcessHeap(), 0, cls );
1084 return hkey;
1087 static IDataObject *shellex_get_dataobj( LPSHELLEXECUTEINFOW sei )
1089 LPCITEMIDLIST pidllast = NULL;
1090 IDataObject *dataobj = NULL;
1091 IShellFolder *shf = NULL;
1092 LPITEMIDLIST pidl = NULL;
1093 HRESULT r;
1095 if (sei->fMask & SEE_MASK_CLASSALL)
1096 pidl = sei->lpIDList;
1097 else
1099 WCHAR fullpath[MAX_PATH];
1100 BOOL ret;
1102 fullpath[0] = 0;
1103 ret = GetFullPathNameW( sei->lpFile, MAX_PATH, fullpath, NULL );
1104 if (!ret)
1105 goto end;
1107 pidl = ILCreateFromPathW( fullpath );
1110 r = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&shf, &pidllast );
1111 if ( FAILED( r ) )
1112 goto end;
1114 IShellFolder_GetUIObjectOf( shf, NULL, 1, &pidllast,
1115 &IID_IDataObject, NULL, (LPVOID*) &dataobj );
1117 end:
1118 if ( pidl != sei->lpIDList )
1119 ILFree( pidl );
1120 if ( shf )
1121 IShellFolder_Release( shf );
1122 return dataobj;
1125 static HRESULT shellex_run_context_menu_default( IShellExtInit *obj,
1126 LPSHELLEXECUTEINFOW sei )
1128 IContextMenu *cm = NULL;
1129 CMINVOKECOMMANDINFOEX ici;
1130 MENUITEMINFOW info;
1131 WCHAR string[0x80];
1132 INT i, n, def = -1;
1133 HMENU hmenu = 0;
1134 HRESULT r;
1136 TRACE("%p %p\n", obj, sei );
1138 r = IShellExtInit_QueryInterface( obj, &IID_IContextMenu, (LPVOID*) &cm );
1139 if ( FAILED( r ) )
1140 return r;
1142 hmenu = CreateMenu();
1143 if ( !hmenu )
1144 goto end;
1146 /* the number of the last menu added is returned in r */
1147 r = IContextMenu_QueryContextMenu( cm, hmenu, 0, 0x20, 0x7fff, CMF_DEFAULTONLY );
1148 if ( FAILED( r ) )
1149 goto end;
1151 n = GetMenuItemCount( hmenu );
1152 for ( i = 0; i < n; i++ )
1154 memset( &info, 0, sizeof info );
1155 info.cbSize = sizeof info;
1156 info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
1157 info.dwTypeData = string;
1158 info.cch = sizeof string;
1159 string[0] = 0;
1160 GetMenuItemInfoW( hmenu, i, TRUE, &info );
1162 TRACE("menu %d %s %08x %08lx %08x %08x\n", i, debugstr_w(string),
1163 info.fState, info.dwItemData, info.fType, info.wID );
1164 if ( ( !sei->lpVerb && (info.fState & MFS_DEFAULT) ) ||
1165 ( sei->lpVerb && !lstrcmpiW( sei->lpVerb, string ) ) )
1167 def = i;
1168 break;
1172 r = E_FAIL;
1173 if ( def == -1 )
1174 goto end;
1176 memset( &ici, 0, sizeof ici );
1177 ici.cbSize = sizeof ici;
1178 ici.fMask = CMIC_MASK_UNICODE | (sei->fMask & (SEE_MASK_NOASYNC|SEE_MASK_ASYNCOK|SEE_MASK_FLAG_NO_UI));
1179 ici.nShow = sei->nShow;
1180 ici.lpVerb = MAKEINTRESOURCEA( def );
1181 ici.hwnd = sei->hwnd;
1182 ici.lpParametersW = sei->lpParameters;
1184 r = IContextMenu_InvokeCommand( cm, (LPCMINVOKECOMMANDINFO) &ici );
1186 TRACE("invoke command returned %08x\n", r );
1188 end:
1189 if ( hmenu )
1190 DestroyMenu( hmenu );
1191 if ( cm )
1192 IContextMenu_Release( cm );
1193 return r;
1196 static HRESULT shellex_load_object_and_run( HKEY hkey, LPCGUID guid, LPSHELLEXECUTEINFOW sei )
1198 IDataObject *dataobj = NULL;
1199 IObjectWithSite *ows = NULL;
1200 IShellExtInit *obj = NULL;
1201 HRESULT r;
1203 TRACE("%p %s %p\n", hkey, debugstr_guid( guid ), sei );
1205 r = CoInitialize( NULL );
1206 if ( FAILED( r ) )
1207 goto end;
1209 r = CoCreateInstance( guid, NULL, CLSCTX_INPROC_SERVER,
1210 &IID_IShellExtInit, (LPVOID*)&obj );
1211 if ( FAILED( r ) )
1213 ERR("failed %08x\n", r );
1214 goto end;
1217 dataobj = shellex_get_dataobj( sei );
1218 if ( !dataobj )
1220 ERR("failed to get data object\n");
1221 goto end;
1224 r = IShellExtInit_Initialize( obj, NULL, dataobj, hkey );
1225 if ( FAILED( r ) )
1226 goto end;
1228 r = IShellExtInit_QueryInterface( obj, &IID_IObjectWithSite, (LPVOID*) &ows );
1229 if ( FAILED( r ) )
1230 goto end;
1232 IObjectWithSite_SetSite( ows, NULL );
1234 r = shellex_run_context_menu_default( obj, sei );
1236 end:
1237 if ( ows )
1238 IObjectWithSite_Release( ows );
1239 if ( dataobj )
1240 IDataObject_Release( dataobj );
1241 if ( obj )
1242 IShellExtInit_Release( obj );
1243 CoUninitialize();
1244 return r;
1248 /*************************************************************************
1249 * ShellExecute_FromContextMenu [Internal]
1251 static LONG ShellExecute_FromContextMenu( LPSHELLEXECUTEINFOW sei )
1253 static const WCHAR szcm[] = { 's','h','e','l','l','e','x','\\',
1254 'C','o','n','t','e','x','t','M','e','n','u','H','a','n','d','l','e','r','s',0 };
1255 HKEY hkey, hkeycm = 0;
1256 WCHAR szguid[39];
1257 HRESULT hr;
1258 GUID guid;
1259 DWORD i;
1260 LONG r;
1262 TRACE("%s\n", debugstr_w(sei->lpFile) );
1264 hkey = ShellExecute_GetClassKey( sei );
1265 if ( !hkey )
1266 return ERROR_FUNCTION_FAILED;
1268 r = RegOpenKeyW( hkey, szcm, &hkeycm );
1269 if ( r == ERROR_SUCCESS )
1271 i = 0;
1272 while ( 1 )
1274 r = RegEnumKeyW( hkeycm, i++, szguid, sizeof(szguid)/sizeof(szguid[0]) );
1275 if ( r != ERROR_SUCCESS )
1276 break;
1278 hr = CLSIDFromString( szguid, &guid );
1279 if (SUCCEEDED(hr))
1281 /* stop at the first one that succeeds in running */
1282 hr = shellex_load_object_and_run( hkey, &guid, sei );
1283 if ( SUCCEEDED( hr ) )
1284 break;
1287 RegCloseKey( hkeycm );
1290 if ( hkey != sei->hkeyClass )
1291 RegCloseKey( hkey );
1292 return r;
1295 static UINT_PTR SHELL_execute_class( LPCWSTR wszApplicationName, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc )
1297 static const WCHAR wSpace[] = {' ',0};
1298 WCHAR execCmd[1024], wcmd[1024];
1299 /* launch a document by fileclass like 'WordPad.Document.1' */
1300 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
1301 /* FIXME: wcmd should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
1302 ULONG cmask=(psei->fMask & SEE_MASK_CLASSALL);
1303 DWORD resultLen;
1304 BOOL done;
1306 HCR_GetExecuteCommandW((cmask == SEE_MASK_CLASSKEY) ? psei->hkeyClass : NULL,
1307 (cmask == SEE_MASK_CLASSNAME) ? psei->lpClass: NULL,
1308 psei->lpVerb,
1309 execCmd, sizeof(execCmd));
1311 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
1312 TRACE("SEE_MASK_CLASSNAME->%s, doc->%s\n", debugstr_w(execCmd), debugstr_w(wszApplicationName));
1314 wcmd[0] = '\0';
1315 done = SHELL_ArgifyW(wcmd, sizeof(wcmd)/sizeof(WCHAR), execCmd, wszApplicationName, psei->lpIDList, NULL, &resultLen);
1316 if (!done && wszApplicationName[0])
1318 strcatW(wcmd, wSpace);
1319 strcatW(wcmd, wszApplicationName);
1321 if (resultLen > sizeof(wcmd)/sizeof(WCHAR))
1322 ERR("Argify buffer not large enough... truncating\n");
1323 return execfunc(wcmd, NULL, FALSE, psei, psei_out);
1326 static BOOL SHELL_translate_idlist( LPSHELLEXECUTEINFOW sei, LPWSTR wszParameters, DWORD parametersLen, LPWSTR wszApplicationName, DWORD dwApplicationNameLen )
1328 static const WCHAR wExplorer[] = {'e','x','p','l','o','r','e','r','.','e','x','e',0};
1329 WCHAR buffer[MAX_PATH];
1330 BOOL appKnownSingular = FALSE;
1332 /* last chance to translate IDList: now also allow CLSID paths */
1333 if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW(sei->lpIDList, buffer, sizeof(buffer)))) {
1334 if (buffer[0]==':' && buffer[1]==':') {
1335 /* open shell folder for the specified class GUID */
1336 if (strlenW(buffer) + 1 > parametersLen)
1337 ERR("parameters len exceeds buffer size (%i > %i), truncating\n",
1338 lstrlenW(buffer) + 1, parametersLen);
1339 lstrcpynW(wszParameters, buffer, parametersLen);
1340 if (strlenW(wExplorer) > dwApplicationNameLen)
1341 ERR("application len exceeds buffer size (%i > %i), truncating\n",
1342 lstrlenW(wExplorer) + 1, dwApplicationNameLen);
1343 lstrcpynW(wszApplicationName, wExplorer, dwApplicationNameLen);
1344 appKnownSingular = TRUE;
1346 sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
1347 } else {
1348 WCHAR target[MAX_PATH];
1349 DWORD attribs;
1350 DWORD resultLen;
1351 /* Check if we're executing a directory and if so use the
1352 handler for the Folder class */
1353 strcpyW(target, buffer);
1354 attribs = GetFileAttributesW(buffer);
1355 if (attribs != INVALID_FILE_ATTRIBUTES &&
1356 (attribs & FILE_ATTRIBUTE_DIRECTORY) &&
1357 HCR_GetExecuteCommandW(0, wszFolder,
1358 sei->lpVerb,
1359 buffer, sizeof(buffer))) {
1360 SHELL_ArgifyW(wszApplicationName, dwApplicationNameLen,
1361 buffer, target, sei->lpIDList, NULL, &resultLen);
1362 if (resultLen > dwApplicationNameLen)
1363 ERR("Argify buffer not large enough... truncating\n");
1364 appKnownSingular = FALSE;
1366 sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
1369 return appKnownSingular;
1372 static UINT_PTR SHELL_quote_and_execute( LPCWSTR wcmd, LPCWSTR wszParameters, LPCWSTR lpstrProtocol, LPCWSTR wszApplicationName, LPWSTR env, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc )
1374 static const WCHAR wQuote[] = {'"',0};
1375 static const WCHAR wSpace[] = {' ',0};
1376 UINT_PTR retval;
1377 DWORD len;
1378 WCHAR *wszQuotedCmd;
1380 /* Length of quotes plus length of command plus NULL terminator */
1381 len = 2 + lstrlenW(wcmd) + 1;
1382 if (wszParameters[0])
1384 /* Length of space plus length of parameters */
1385 len += 1 + lstrlenW(wszParameters);
1387 wszQuotedCmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1388 /* Must quote to handle case where cmd contains spaces,
1389 * else security hole if malicious user creates executable file "C:\\Program"
1391 strcpyW(wszQuotedCmd, wQuote);
1392 strcatW(wszQuotedCmd, wcmd);
1393 strcatW(wszQuotedCmd, wQuote);
1394 if (wszParameters[0]) {
1395 strcatW(wszQuotedCmd, wSpace);
1396 strcatW(wszQuotedCmd, wszParameters);
1398 TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(psei->lpVerb), debugstr_w(wszQuotedCmd), debugstr_w(lpstrProtocol));
1399 if (*lpstrProtocol)
1400 retval = execute_from_key(lpstrProtocol, wszApplicationName, env, psei->lpParameters, wcmd, execfunc, psei, psei_out);
1401 else
1402 retval = execfunc(wszQuotedCmd, env, FALSE, psei, psei_out);
1403 HeapFree(GetProcessHeap(), 0, wszQuotedCmd);
1404 return retval;
1407 static UINT_PTR SHELL_execute_url( LPCWSTR lpFile, LPCWSTR wFile, LPCWSTR wcmd, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc )
1409 static const WCHAR wShell[] = {'\\','s','h','e','l','l','\\',0};
1410 static const WCHAR wCommand[] = {'\\','c','o','m','m','a','n','d',0};
1411 UINT_PTR retval;
1412 WCHAR *lpstrProtocol;
1413 LPCWSTR lpstrRes;
1414 INT iSize;
1415 DWORD len;
1417 lpstrRes = strchrW(lpFile, ':');
1418 if (lpstrRes)
1419 iSize = lpstrRes - lpFile;
1420 else
1421 iSize = strlenW(lpFile);
1423 TRACE("Got URL: %s\n", debugstr_w(lpFile));
1424 /* Looking for ...protocol\shell\lpOperation\command */
1425 len = iSize + lstrlenW(wShell) + lstrlenW(wCommand) + 1;
1426 if (psei->lpVerb)
1427 len += lstrlenW(psei->lpVerb);
1428 else
1429 len += lstrlenW(wszOpen);
1430 lpstrProtocol = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1431 memcpy(lpstrProtocol, lpFile, iSize*sizeof(WCHAR));
1432 lpstrProtocol[iSize] = '\0';
1433 strcatW(lpstrProtocol, wShell);
1434 strcatW(lpstrProtocol, psei->lpVerb? psei->lpVerb: wszOpen);
1435 strcatW(lpstrProtocol, wCommand);
1437 /* Remove File Protocol from lpFile */
1438 /* In the case file://path/file */
1439 if (!strncmpiW(lpFile, wFile, iSize))
1441 lpFile += iSize;
1442 while (*lpFile == ':') lpFile++;
1444 retval = execute_from_key(lpstrProtocol, lpFile, NULL, psei->lpParameters,
1445 wcmd, execfunc, psei, psei_out);
1446 HeapFree(GetProcessHeap(), 0, lpstrProtocol);
1447 return retval;
1450 /*************************************************************************
1451 * SHELL_execute [Internal]
1453 BOOL SHELL_execute( LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc )
1455 static const WCHAR wSpace[] = {' ',0};
1456 static const WCHAR wWww[] = {'w','w','w',0};
1457 static const WCHAR wFile[] = {'f','i','l','e',0};
1458 static const WCHAR wHttp[] = {'h','t','t','p',':','/','/',0};
1459 static const DWORD unsupportedFlags =
1460 SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
1461 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI |
1462 SEE_MASK_UNICODE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR;
1464 WCHAR parametersBuffer[1024], dirBuffer[MAX_PATH], wcmdBuffer[1024];
1465 WCHAR *wszApplicationName, *wszParameters, *wszDir, *wcmd;
1466 DWORD dwApplicationNameLen = MAX_PATH+2;
1467 DWORD parametersLen = sizeof(parametersBuffer) / sizeof(WCHAR);
1468 DWORD dirLen = sizeof(dirBuffer) / sizeof(WCHAR);
1469 DWORD wcmdLen = sizeof(wcmdBuffer) / sizeof(WCHAR);
1470 DWORD len;
1471 SHELLEXECUTEINFOW sei_tmp; /* modifiable copy of SHELLEXECUTEINFO struct */
1472 WCHAR wfileName[MAX_PATH];
1473 WCHAR *env;
1474 WCHAR lpstrProtocol[256];
1475 LPCWSTR lpFile;
1476 UINT_PTR retval = SE_ERR_NOASSOC;
1477 BOOL appKnownSingular = FALSE;
1479 /* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
1480 sei_tmp = *sei;
1482 TRACE("mask=0x%08x hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
1483 sei_tmp.fMask, sei_tmp.hwnd, debugstr_w(sei_tmp.lpVerb),
1484 debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters),
1485 debugstr_w(sei_tmp.lpDirectory), sei_tmp.nShow,
1486 ((sei_tmp.fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME) ?
1487 debugstr_w(sei_tmp.lpClass) : "not used");
1489 sei->hProcess = NULL;
1491 /* make copies of all path/command strings */
1492 if (!sei_tmp.lpFile)
1494 wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1495 *wszApplicationName = '\0';
1497 else if (*sei_tmp.lpFile == '\"')
1499 DWORD l = strlenW(sei_tmp.lpFile+1);
1500 if(l >= dwApplicationNameLen) dwApplicationNameLen = l+1;
1501 wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1502 memcpy(wszApplicationName, sei_tmp.lpFile+1, (l+1)*sizeof(WCHAR));
1503 if (wszApplicationName[l-1] == '\"')
1504 wszApplicationName[l-1] = '\0';
1505 appKnownSingular = TRUE;
1506 TRACE("wszApplicationName=%s\n",debugstr_w(wszApplicationName));
1507 } else {
1508 DWORD l = strlenW(sei_tmp.lpFile)+1;
1509 if(l > dwApplicationNameLen) dwApplicationNameLen = l+1;
1510 wszApplicationName = HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen*sizeof(WCHAR));
1511 memcpy(wszApplicationName, sei_tmp.lpFile, l*sizeof(WCHAR));
1514 wszParameters = parametersBuffer;
1515 if (sei_tmp.lpParameters)
1517 len = lstrlenW(sei_tmp.lpParameters) + 1;
1518 if (len > parametersLen)
1520 wszParameters = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1521 parametersLen = len;
1523 strcpyW(wszParameters, sei_tmp.lpParameters);
1525 else
1526 *wszParameters = '\0';
1528 wszDir = dirBuffer;
1529 if (sei_tmp.lpDirectory)
1531 len = lstrlenW(sei_tmp.lpDirectory) + 1;
1532 if (len > dirLen)
1534 wszDir = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1535 dirLen = len;
1537 strcpyW(wszDir, sei_tmp.lpDirectory);
1539 else
1540 *wszDir = '\0';
1542 /* adjust string pointers to point to the new buffers */
1543 sei_tmp.lpFile = wszApplicationName;
1544 sei_tmp.lpParameters = wszParameters;
1545 sei_tmp.lpDirectory = wszDir;
1547 if (sei_tmp.fMask & unsupportedFlags)
1549 FIXME("flags ignored: 0x%08x\n", sei_tmp.fMask & unsupportedFlags);
1552 /* process the IDList */
1553 if (sei_tmp.fMask & SEE_MASK_IDLIST)
1555 IShellExecuteHookW* pSEH;
1557 HRESULT hr = SHBindToParent(sei_tmp.lpIDList, &IID_IShellExecuteHookW, (LPVOID*)&pSEH, NULL);
1559 if (SUCCEEDED(hr))
1561 hr = IShellExecuteHookW_Execute(pSEH, &sei_tmp);
1563 IShellExecuteHookW_Release(pSEH);
1565 if (hr == S_OK) {
1566 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1567 if (wszParameters != parametersBuffer)
1568 HeapFree(GetProcessHeap(), 0, wszParameters);
1569 if (wszDir != dirBuffer)
1570 HeapFree(GetProcessHeap(), 0, wszDir);
1571 return TRUE;
1575 SHGetPathFromIDListW(sei_tmp.lpIDList, wszApplicationName);
1576 appKnownSingular = TRUE;
1577 TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, debugstr_w(wszApplicationName));
1580 if ( ERROR_SUCCESS == ShellExecute_FromContextMenu( &sei_tmp ) )
1582 sei->hInstApp = (HINSTANCE) 33;
1583 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1584 if (wszParameters != parametersBuffer)
1585 HeapFree(GetProcessHeap(), 0, wszParameters);
1586 if (wszDir != dirBuffer)
1587 HeapFree(GetProcessHeap(), 0, wszDir);
1588 return TRUE;
1591 if (sei_tmp.fMask & SEE_MASK_CLASSALL)
1593 retval = SHELL_execute_class( wszApplicationName, &sei_tmp, sei,
1594 execfunc );
1595 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1596 if (wszParameters != parametersBuffer)
1597 HeapFree(GetProcessHeap(), 0, wszParameters);
1598 if (wszDir != dirBuffer)
1599 HeapFree(GetProcessHeap(), 0, wszDir);
1600 return retval > 32;
1603 /* Has the IDList not yet been translated? */
1604 if (sei_tmp.fMask & SEE_MASK_IDLIST)
1606 appKnownSingular = SHELL_translate_idlist( &sei_tmp, wszParameters,
1607 parametersLen,
1608 wszApplicationName,
1609 dwApplicationNameLen );
1612 /* expand environment strings */
1613 len = ExpandEnvironmentStringsW(sei_tmp.lpFile, NULL, 0);
1614 if (len>0)
1616 LPWSTR buf;
1617 buf = HeapAlloc(GetProcessHeap(),0,(len+1)*sizeof(WCHAR));
1619 ExpandEnvironmentStringsW(sei_tmp.lpFile, buf, len+1);
1620 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1621 dwApplicationNameLen = len+1;
1622 wszApplicationName = buf;
1623 /* appKnownSingular unmodified */
1625 sei_tmp.lpFile = wszApplicationName;
1628 if (*sei_tmp.lpParameters)
1630 len = ExpandEnvironmentStringsW(sei_tmp.lpParameters, NULL, 0);
1631 if (len > 0)
1633 LPWSTR buf;
1634 len++;
1635 buf = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
1636 ExpandEnvironmentStringsW(sei_tmp.lpParameters, buf, len);
1637 if (wszParameters != parametersBuffer)
1638 HeapFree(GetProcessHeap(), 0, wszParameters);
1639 wszParameters = buf;
1640 parametersLen = len;
1641 sei_tmp.lpParameters = wszParameters;
1645 if (*sei_tmp.lpDirectory)
1647 len = ExpandEnvironmentStringsW(sei_tmp.lpDirectory, NULL, 0);
1648 if (len > 0)
1650 LPWSTR buf;
1651 len++;
1652 buf = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
1653 ExpandEnvironmentStringsW(sei_tmp.lpDirectory, buf, len);
1654 if (wszDir != dirBuffer)
1655 HeapFree(GetProcessHeap(), 0, wszDir);
1656 wszDir = buf;
1657 sei_tmp.lpDirectory = wszDir;
1661 /* Else, try to execute the filename */
1662 TRACE("execute:%s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir));
1664 /* separate out command line arguments from executable file name */
1665 if (!*sei_tmp.lpParameters && !appKnownSingular) {
1666 /* If the executable path is quoted, handle the rest of the command line as parameters. */
1667 if (sei_tmp.lpFile[0] == '"') {
1668 LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1;
1669 LPWSTR dst = wfileName;
1670 LPWSTR end;
1672 /* copy the unquoted executable path to 'wfileName' */
1673 while(*src && *src!='"')
1674 *dst++ = *src++;
1676 *dst = '\0';
1678 if (*src == '"') {
1679 end = ++src;
1681 while(isspace(*src))
1682 ++src;
1683 } else
1684 end = src;
1686 /* copy the parameter string to 'wszParameters' */
1687 strcpyW(wszParameters, src);
1689 /* terminate previous command string after the quote character */
1690 *end = '\0';
1692 else
1694 /* If the executable name is not quoted, we have to use this search loop here,
1695 that in CreateProcess() is not sufficient because it does not handle shell links. */
1696 WCHAR buffer[MAX_PATH], xlpFile[MAX_PATH];
1697 LPWSTR space, s;
1699 LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/;
1700 for(s=beg; (space=strchrW(s, ' ')); s=space+1) {
1701 int idx = space-sei_tmp.lpFile;
1702 memcpy(buffer, sei_tmp.lpFile, idx * sizeof(WCHAR));
1703 buffer[idx] = '\0';
1705 /*FIXME This finds directory paths if the targeted file name contains spaces. */
1706 if (SearchPathW(*sei_tmp.lpDirectory? sei_tmp.lpDirectory: NULL, buffer, wszExe, sizeof(xlpFile)/sizeof(xlpFile[0]), xlpFile, NULL))
1708 /* separate out command from parameter string */
1709 LPCWSTR p = space + 1;
1711 while(isspaceW(*p))
1712 ++p;
1714 strcpyW(wszParameters, p);
1715 *space = '\0';
1717 break;
1721 lstrcpynW(wfileName, sei_tmp.lpFile,sizeof(wfileName)/sizeof(WCHAR));
1723 } else
1724 lstrcpynW(wfileName, sei_tmp.lpFile,sizeof(wfileName)/sizeof(WCHAR));
1726 lpFile = wfileName;
1728 wcmd = wcmdBuffer;
1729 len = lstrlenW(wszApplicationName) + 1;
1730 if (sei_tmp.lpParameters[0])
1731 len += 1 + lstrlenW(wszParameters);
1732 if (len > wcmdLen)
1734 wcmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1735 wcmdLen = len;
1737 strcpyW(wcmd, wszApplicationName);
1738 if (sei_tmp.lpParameters[0]) {
1739 strcatW(wcmd, wSpace);
1740 strcatW(wcmd, wszParameters);
1743 retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
1744 if (retval > 32) {
1745 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1746 if (wszParameters != parametersBuffer)
1747 HeapFree(GetProcessHeap(), 0, wszParameters);
1748 if (wszDir != dirBuffer)
1749 HeapFree(GetProcessHeap(), 0, wszDir);
1750 if (wcmd != wcmdBuffer)
1751 HeapFree(GetProcessHeap(), 0, wcmd);
1752 return TRUE;
1755 /* Else, try to find the executable */
1756 wcmd[0] = '\0';
1757 retval = SHELL_FindExecutable(sei_tmp.lpDirectory, lpFile, sei_tmp.lpVerb, wcmd, wcmdLen, lpstrProtocol, &env, sei_tmp.lpIDList, sei_tmp.lpParameters);
1758 if (retval > 32) /* Found */
1760 retval = SHELL_quote_and_execute( wcmd, wszParameters, lpstrProtocol,
1761 wszApplicationName, env, &sei_tmp,
1762 sei, execfunc );
1763 HeapFree( GetProcessHeap(), 0, env );
1765 else if (PathIsDirectoryW(lpFile))
1767 static const WCHAR wExplorer[] = {'e','x','p','l','o','r','e','r',0};
1768 static const WCHAR wQuote[] = {'"',0};
1769 WCHAR wExec[MAX_PATH];
1770 WCHAR * lpQuotedFile = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR) * (strlenW(lpFile) + 3) );
1772 if (lpQuotedFile)
1774 retval = SHELL_FindExecutable( sei_tmp.lpDirectory, wExplorer,
1775 wszOpen, wExec, MAX_PATH,
1776 NULL, &env, NULL, NULL );
1777 if (retval > 32)
1779 strcpyW(lpQuotedFile, wQuote);
1780 strcatW(lpQuotedFile, lpFile);
1781 strcatW(lpQuotedFile, wQuote);
1782 retval = SHELL_quote_and_execute( wExec, lpQuotedFile,
1783 lpstrProtocol,
1784 wszApplicationName, env,
1785 &sei_tmp, sei, execfunc );
1786 HeapFree( GetProcessHeap(), 0, env );
1788 HeapFree( GetProcessHeap(), 0, lpQuotedFile );
1790 else
1791 retval = 0; /* Out of memory */
1793 else if (PathIsURLW(lpFile)) /* File not found, check for URL */
1795 retval = SHELL_execute_url( lpFile, wFile, wcmd, &sei_tmp, sei, execfunc );
1797 /* Check if file specified is in the form www.??????.*** */
1798 else if (!strncmpiW(lpFile, wWww, 3))
1800 /* if so, append lpFile http:// and call ShellExecute */
1801 WCHAR lpstrTmpFile[256];
1802 strcpyW(lpstrTmpFile, wHttp);
1803 strcatW(lpstrTmpFile, lpFile);
1804 retval = (UINT_PTR)ShellExecuteW(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
1807 TRACE("retval %lu\n", retval);
1809 HeapFree(GetProcessHeap(), 0, wszApplicationName);
1810 if (wszParameters != parametersBuffer)
1811 HeapFree(GetProcessHeap(), 0, wszParameters);
1812 if (wszDir != dirBuffer)
1813 HeapFree(GetProcessHeap(), 0, wszDir);
1814 if (wcmd != wcmdBuffer)
1815 HeapFree(GetProcessHeap(), 0, wcmd);
1817 sei->hInstApp = (HINSTANCE)(retval > 32 ? 33 : retval);
1818 return retval > 32;
1821 /*************************************************************************
1822 * ShellExecuteA [SHELL32.290]
1824 HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
1825 LPCSTR lpParameters,LPCSTR lpDirectory, INT iShowCmd)
1827 SHELLEXECUTEINFOA sei;
1829 TRACE("%p,%s,%s,%s,%s,%d\n",
1830 hWnd, debugstr_a(lpOperation), debugstr_a(lpFile),
1831 debugstr_a(lpParameters), debugstr_a(lpDirectory), iShowCmd);
1833 sei.cbSize = sizeof(sei);
1834 sei.fMask = 0;
1835 sei.hwnd = hWnd;
1836 sei.lpVerb = lpOperation;
1837 sei.lpFile = lpFile;
1838 sei.lpParameters = lpParameters;
1839 sei.lpDirectory = lpDirectory;
1840 sei.nShow = iShowCmd;
1841 sei.lpIDList = 0;
1842 sei.lpClass = 0;
1843 sei.hkeyClass = 0;
1844 sei.dwHotKey = 0;
1845 sei.hProcess = 0;
1847 ShellExecuteExA (&sei);
1848 return sei.hInstApp;
1851 /*************************************************************************
1852 * ShellExecuteExA [SHELL32.292]
1855 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
1857 SHELLEXECUTEINFOW seiW;
1858 BOOL ret;
1859 WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL, *wClass = NULL;
1861 TRACE("%p\n", sei);
1863 memcpy(&seiW, sei, sizeof(SHELLEXECUTEINFOW));
1865 if (sei->lpVerb)
1866 seiW.lpVerb = __SHCloneStrAtoW(&wVerb, sei->lpVerb);
1868 if (sei->lpFile)
1869 seiW.lpFile = __SHCloneStrAtoW(&wFile, sei->lpFile);
1871 if (sei->lpParameters)
1872 seiW.lpParameters = __SHCloneStrAtoW(&wParameters, sei->lpParameters);
1874 if (sei->lpDirectory)
1875 seiW.lpDirectory = __SHCloneStrAtoW(&wDirectory, sei->lpDirectory);
1877 if ((sei->fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME && sei->lpClass)
1878 seiW.lpClass = __SHCloneStrAtoW(&wClass, sei->lpClass);
1879 else
1880 seiW.lpClass = NULL;
1882 ret = SHELL_execute( &seiW, SHELL_ExecuteW );
1884 sei->hInstApp = seiW.hInstApp;
1886 if (sei->fMask & SEE_MASK_NOCLOSEPROCESS)
1887 sei->hProcess = seiW.hProcess;
1889 SHFree(wVerb);
1890 SHFree(wFile);
1891 SHFree(wParameters);
1892 SHFree(wDirectory);
1893 SHFree(wClass);
1895 return ret;
1898 /*************************************************************************
1899 * ShellExecuteExW [SHELL32.293]
1902 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
1904 return SHELL_execute( sei, SHELL_ExecuteW );
1907 /*************************************************************************
1908 * ShellExecuteW [SHELL32.294]
1909 * from shellapi.h
1910 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
1911 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
1913 HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
1914 LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
1916 SHELLEXECUTEINFOW sei;
1918 TRACE("\n");
1919 sei.cbSize = sizeof(sei);
1920 sei.fMask = 0;
1921 sei.hwnd = hwnd;
1922 sei.lpVerb = lpOperation;
1923 sei.lpFile = lpFile;
1924 sei.lpParameters = lpParameters;
1925 sei.lpDirectory = lpDirectory;
1926 sei.nShow = nShowCmd;
1927 sei.lpIDList = 0;
1928 sei.lpClass = 0;
1929 sei.hkeyClass = 0;
1930 sei.dwHotKey = 0;
1931 sei.hProcess = 0;
1933 SHELL_execute( &sei, SHELL_ExecuteW );
1934 return sei.hInstApp;
1937 /*************************************************************************
1938 * OpenAs_RunDLLA [SHELL32.@]
1940 void WINAPI OpenAs_RunDLLA(HWND hwnd, HINSTANCE hinst, LPCSTR cmdline, int cmdshow)
1942 FIXME("%p, %p, %s, %d\n", hwnd, hinst, debugstr_a(cmdline), cmdshow);
1945 /*************************************************************************
1946 * OpenAs_RunDLLW [SHELL32.@]
1948 void WINAPI OpenAs_RunDLLW(HWND hwnd, HINSTANCE hinst, LPCWSTR cmdline, int cmdshow)
1950 FIXME("%p, %p, %s, %d\n", hwnd, hinst, debugstr_w(cmdline), cmdshow);