2 * Shell Library Functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
6 * Copyright 2018 Katayama Hirofumi MZ
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 WINE_DEFAULT_DEBUG_CHANNEL(exec
);
27 static const WCHAR wszOpen
[] = L
"open";
28 static const WCHAR wszExe
[] = L
".exe";
30 #define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
32 typedef UINT_PTR (*SHELL_ExecuteW32
)(const WCHAR
*lpCmd
, WCHAR
*env
, BOOL shWait
,
33 const SHELLEXECUTEINFOW
*sei
, LPSHELLEXECUTEINFOW sei_out
);
35 static void ParseNoTildeEffect(PWSTR
&res
, LPCWSTR
&args
, DWORD
&len
, DWORD
&used
, int argNum
)
37 bool firstCharQuote
= false;
38 bool quotes_opened
= false;
39 bool backslash_encountered
= false;
41 for (int curArg
= 0; curArg
<= argNum
&& *args
; ++curArg
)
43 firstCharQuote
= false;
47 firstCharQuote
= true;
55 // if we found a backslash then flip the variable
56 backslash_encountered
= !backslash_encountered
;
58 else if (*args
== '"')
62 if (*(args
+ 1) != '"')
64 quotes_opened
= false;
78 backslash_encountered
= false;
82 backslash_encountered
= false;
83 if (*args
== ' ' && !firstCharQuote
)
102 static void ParseTildeEffect(PWSTR
&res
, LPCWSTR
&args
, DWORD
&len
, DWORD
&used
, int argNum
)
104 bool quotes_opened
= false;
105 bool backslash_encountered
= false;
107 for (int curArg
= 0; curArg
<= argNum
&& *args
; ++curArg
)
113 // if we found a backslash then flip the variable
114 backslash_encountered
= !backslash_encountered
;
116 else if (*args
== '"')
120 if (*(args
+ 1) != '"')
122 quotes_opened
= false;
131 quotes_opened
= true;
134 backslash_encountered
= false;
138 backslash_encountered
= false;
139 if (*args
== ' ' && !quotes_opened
&& curArg
!= argNum
)
143 if (curArg
== argNum
)
155 /***********************************************************************
156 * SHELL_ArgifyW [Internal]
158 * this function is supposed to expand the escape sequences found in the registry
159 * some diving reported that the following were used:
160 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
165 * %I address of a global item ID (explorer switch /idlist)
166 * %L seems to be %1 as long filename followed by the 8+3 variation
168 * %* all following parameters (see batfile)
170 * The way we parse the command line arguments was determined through extensive
171 * testing and can be summed up by the following rules"
174 * - if first letter is " break on first non literal " and include any white spaces
175 * - if first letter is NOT " break on first " or white space
176 * - if " is opened any pair of consecutive " results in ONE literal "
179 * - use rules from here http://www.autohotkey.net/~deleyd/parameters/parameters.htm
182 static BOOL
SHELL_ArgifyW(WCHAR
* out
, DWORD len
, const WCHAR
* fmt
, const WCHAR
* lpFile
, LPITEMIDLIST pidl
, LPCWSTR args
, DWORD
* out_len
)
186 BOOL found_p1
= FALSE
;
190 bool tildeEffect
= false;
192 TRACE("Before parsing: %p, %d, %s, %s, %p, %p\n", out
, len
, debugstr_w(fmt
),
193 debugstr_w(lpFile
), pidl
, args
);
254 ParseTildeEffect(res
, args
, len
, used
, *fmt
- '2');
259 ParseNoTildeEffect(res
, args
, len
, used
, *fmt
- '2');
266 if (!done
|| (*fmt
== '1'))
268 /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
269 if (SearchPathW(NULL
, lpFile
, wszExe
, sizeof(xlpFile
) / sizeof(WCHAR
), xlpFile
, NULL
))
285 * IE uses this a lot for activating things such as windows media
286 * player. This is not verified to be fully correct but it appears
293 used
+= wcslen(lpFile
);
297 res
+= wcslen(lpFile
);
308 /* %p should not exceed 8, maybe 16 when looking forward to 64bit.
309 * allowing a buffer of 100 should more than exceed all needs */
312 HGLOBAL hmem
= SHAllocShared(pidl
, ILGetSize(pidl
), 0);
313 pv
= SHLockShared(hmem
, 0);
314 chars
= swprintf(buf
, L
":%p", pv
);
316 if (chars
>= sizeof(buf
) / sizeof(WCHAR
))
317 ERR("pidl format buffer too small!\n");
333 * Check if this is an env-variable here...
336 /* Make sure that we have at least one more %.*/
337 if (strchrW(fmt
, '%'))
339 WCHAR tmpBuffer
[1024];
340 PWSTR tmpB
= tmpBuffer
;
341 WCHAR tmpEnvBuff
[MAX_PATH
];
348 TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer
));
350 envRet
= GetEnvironmentVariableW(tmpBuffer
, tmpEnvBuff
, MAX_PATH
);
351 if (envRet
== 0 || envRet
> MAX_PATH
)
353 used
+= wcslen(tmpBuffer
);
356 wcscpy( res
, tmpBuffer
);
357 res
+= wcslen(tmpBuffer
);
362 used
+= wcslen(tmpEnvBuff
);
365 wcscpy( res
, tmpEnvBuff
);
366 res
+= wcslen(tmpEnvBuff
);
373 /* Don't skip past terminator (catch a single '%' at the end) */
390 if (res
- out
< static_cast<int>(len
))
395 TRACE("used %i of %i space\n", used
, len
);
399 TRACE("After parsing: %p, %d, %s, %s, %p, %p\n", out
, len
, debugstr_w(fmt
),
400 debugstr_w(lpFile
), pidl
, args
);
405 static HRESULT
SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl
, LPWSTR pszPath
, UINT uOutSize
)
408 CComPtr
<IShellFolder
> desktop
;
410 HRESULT hr
= SHGetDesktopFolder(&desktop
);
414 hr
= desktop
->GetDisplayNameOf(pidl
, SHGDN_FORPARSING
, &strret
);
417 StrRetToStrNW(pszPath
, uOutSize
, &strret
, pidl
);
423 /*************************************************************************
424 * SHELL_ExecuteW [Internal]
427 static UINT_PTR
SHELL_ExecuteW(const WCHAR
*lpCmd
, WCHAR
*env
, BOOL shWait
,
428 const SHELLEXECUTEINFOW
*psei
, LPSHELLEXECUTEINFOW psei_out
)
430 STARTUPINFOW startup
;
431 PROCESS_INFORMATION info
;
432 UINT_PTR retval
= SE_ERR_NOASSOC
;
434 WCHAR curdir
[MAX_PATH
];
435 DWORD dwCreationFlags
;
436 const WCHAR
*lpDirectory
= NULL
;
438 TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd
), debugstr_w(psei
->lpDirectory
));
440 /* make sure we don't fail the CreateProcess if the calling app passes in
441 * a bad working directory */
442 if (psei
->lpDirectory
&& psei
->lpDirectory
[0])
444 DWORD attr
= GetFileAttributesW(psei
->lpDirectory
);
445 if (attr
!= INVALID_FILE_ATTRIBUTES
&& attr
& FILE_ATTRIBUTE_DIRECTORY
)
446 lpDirectory
= psei
->lpDirectory
;
449 /* ShellExecute specifies the command from psei->lpDirectory
450 * if present. Not from the current dir as CreateProcess does */
452 if ((gcdret
= GetCurrentDirectoryW( MAX_PATH
, curdir
)))
453 if (!SetCurrentDirectoryW( lpDirectory
))
454 ERR("cannot set directory %s\n", debugstr_w(lpDirectory
));
456 ZeroMemory(&startup
, sizeof(STARTUPINFOW
));
457 startup
.cb
= sizeof(STARTUPINFOW
);
458 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
459 startup
.wShowWindow
= psei
->nShow
;
460 dwCreationFlags
= CREATE_UNICODE_ENVIRONMENT
;
461 if (!(psei
->fMask
& SEE_MASK_NO_CONSOLE
))
462 dwCreationFlags
|= CREATE_NEW_CONSOLE
;
463 startup
.lpTitle
= (LPWSTR
)(psei
->fMask
& (SEE_MASK_HASLINKNAME
| SEE_MASK_HASTITLE
) ? psei
->lpClass
: NULL
);
465 if (psei
->fMask
& SEE_MASK_HASLINKNAME
)
466 startup
.dwFlags
|= STARTF_TITLEISLINKNAME
;
468 if (CreateProcessW(NULL
, (LPWSTR
)lpCmd
, NULL
, NULL
, FALSE
, dwCreationFlags
, env
,
469 lpDirectory
, &startup
, &info
))
471 /* Give 30 seconds to the app to come up, if desired. Probably only needed
472 when starting app immediately before making a DDE connection. */
474 if (WaitForInputIdle(info
.hProcess
, 30000) == WAIT_FAILED
)
475 WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
478 if (psei
->fMask
& SEE_MASK_NOCLOSEPROCESS
)
479 psei_out
->hProcess
= info
.hProcess
;
481 CloseHandle( info
.hProcess
);
482 CloseHandle( info
.hThread
);
484 else if ((retval
= GetLastError()) >= 32)
486 WARN("CreateProcess returned error %ld\n", retval
);
487 retval
= ERROR_BAD_FORMAT
;
490 TRACE("returning %lu\n", retval
);
492 psei_out
->hInstApp
= (HINSTANCE
)retval
;
495 if (!SetCurrentDirectoryW(curdir
))
496 ERR("cannot return to directory %s\n", debugstr_w(curdir
));
502 /***********************************************************************
503 * SHELL_BuildEnvW [Internal]
505 * Build the environment for the new process, adding the specified
506 * path to the PATH variable. Returned pointer must be freed by caller.
508 static LPWSTR
SHELL_BuildEnvW( const WCHAR
*path
)
510 static const WCHAR wPath
[] = L
"PATH=";
511 WCHAR
*strings
, *new_env
;
513 int total
= wcslen(path
) + 1;
514 BOOL got_path
= FALSE
;
516 if (!(strings
= GetEnvironmentStringsW())) return NULL
;
520 int len
= wcslen(p
) + 1;
521 if (!_wcsnicmp( p
, wPath
, 5 )) got_path
= TRUE
;
525 if (!got_path
) total
+= 5; /* we need to create PATH */
526 total
++; /* terminating null */
528 if (!(new_env
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, total
* sizeof(WCHAR
))))
530 FreeEnvironmentStringsW(strings
);
537 int len
= wcslen(p
) + 1;
538 memcpy(p2
, p
, len
* sizeof(WCHAR
));
539 if (!_wcsnicmp( p
, wPath
, 5 ))
542 wcscpy( p2
+ len
, path
);
543 p2
+= wcslen(path
) + 1;
552 p2
+= wcslen(p2
) + 1;
555 FreeEnvironmentStringsW(strings
);
560 /***********************************************************************
561 * SHELL_TryAppPathW [Internal]
563 * Helper function for SHELL_FindExecutable
564 * @param lpResult - pointer to a buffer of size MAX_PATH
565 * On entry: szName is a filename (probably without path separators).
566 * On exit: if szName found in "App Path", place full path in lpResult, and return true
568 static BOOL
SHELL_TryAppPathW( LPCWSTR szName
, LPWSTR lpResult
, WCHAR
**env
)
576 if (env
) *env
= NULL
;
577 wcscpy(buffer
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
578 wcscat(buffer
, szName
);
579 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, buffer
, 0, KEY_READ
, &hkApp
);
582 // Add ".exe" extension, if extension does not exists
583 if (PathAddExtensionW(buffer
, wszExe
))
585 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, buffer
, 0, KEY_READ
, &hkApp
);
590 len
= MAX_PATH
* sizeof(WCHAR
);
591 res
= RegQueryValueW(hkApp
, NULL
, lpResult
, &len
);
597 DWORD count
= sizeof(buffer
);
598 if (!RegQueryValueExW(hkApp
, L
"Path", NULL
, NULL
, (LPBYTE
)buffer
, &count
) && buffer
[0])
599 *env
= SHELL_BuildEnvW(buffer
);
603 if (hkApp
) RegCloseKey(hkApp
);
607 /*************************************************************************
608 * SHELL_FindExecutableByVerb [Internal]
610 * called from SHELL_FindExecutable or SHELL_execute_class
612 * classname a buffer, big enough, to get the key name to do actually the
613 * command "WordPad.Document.1\\shell\\open\\command"
614 * passed as "WordPad.Document.1"
616 * lpVerb the operation on it (open)
617 * commandlen the size of command buffer (in bytes)
619 * command a buffer, to store the command to do the
620 * operation on the file
621 * key a buffer, big enough, to get the key name to do actually the
622 * command "WordPad.Document.1\\shell\\open\\command"
625 static UINT
SHELL_FindExecutableByVerb(LPCWSTR lpVerb
, LPWSTR key
, LPWSTR classname
, LPWSTR command
, LONG commandlen
)
627 static const WCHAR wCommand
[] = L
"\\command";
629 WCHAR verb
[MAX_PATH
];
631 if (RegOpenKeyExW(HKEY_CLASSES_ROOT
, classname
, 0, 0x02000000, &hkeyClass
))
632 return SE_ERR_NOASSOC
;
633 if (!HCR_GetDefaultVerbW(hkeyClass
, lpVerb
, verb
, sizeof(verb
) / sizeof(verb
[0])))
634 return SE_ERR_NOASSOC
;
635 RegCloseKey(hkeyClass
);
637 /* Looking for ...buffer\shell\<verb>\command */
638 wcscat(classname
, L
"\\shell\\");
639 wcscat(classname
, verb
);
640 wcscat(classname
, wCommand
);
642 if (RegQueryValueW(HKEY_CLASSES_ROOT
, classname
, command
,
643 &commandlen
) == ERROR_SUCCESS
)
645 commandlen
/= sizeof(WCHAR
);
646 if (key
) wcscpy(key
, classname
);
650 LONG paramlen
= sizeof(param
);
651 static const WCHAR wSpace
[] = {' ', 0};
653 /* FIXME: it seems all Windows version don't behave the same here.
654 * the doc states that this ddeexec information can be found after
656 * on Win98, it doesn't appear, but I think it does on Win2k
658 /* Get the parameters needed by the application
659 from the associated ddeexec key */
660 tmp
= strstrW(classname
, wCommand
);
662 wcscat(classname
, wDdeexec
);
663 if (RegQueryValueW(HKEY_CLASSES_ROOT
, classname
, param
,
664 ¶mlen
) == ERROR_SUCCESS
)
666 paramlen
/= sizeof(WCHAR
);
667 wcscat(command
, wSpace
);
668 wcscat(command
, param
);
669 commandlen
+= paramlen
;
673 command
[commandlen
] = '\0';
675 return 33; /* FIXME see SHELL_FindExecutable() */
678 return SE_ERR_NOASSOC
;
681 /*************************************************************************
682 * SHELL_FindExecutable [Internal]
684 * Utility for code sharing between FindExecutable and ShellExecute
686 * lpFile the name of a file
687 * lpVerb the operation on it (open)
689 * lpResult a buffer, big enough :-(, to store the command to do the
690 * operation on the file
691 * key a buffer, big enough, to get the key name to do actually the
692 * command (it'll be used afterwards for more information
695 static UINT
SHELL_FindExecutable(LPCWSTR lpPath
, LPCWSTR lpFile
, LPCWSTR lpVerb
,
696 LPWSTR lpResult
, DWORD resultLen
, LPWSTR key
, WCHAR
**env
, LPITEMIDLIST pidl
, LPCWSTR args
)
698 WCHAR
*extension
= NULL
; /* pointer to file extension */
699 WCHAR classname
[256]; /* registry name for this file type */
700 LONG classnamelen
= sizeof(classname
); /* length of above */
701 WCHAR command
[1024]; /* command from registry */
702 WCHAR wBuffer
[256]; /* Used to GetProfileString */
703 UINT retval
= SE_ERR_NOASSOC
;
704 WCHAR
*tok
; /* token pointer */
705 WCHAR xlpFile
[256]; /* result of SearchPath */
706 DWORD attribs
; /* file attributes */
708 TRACE("%s\n", debugstr_w(lpFile
));
711 return ERROR_INVALID_PARAMETER
;
714 lpResult
[0] = '\0'; /* Start off with an empty return string */
715 if (key
) *key
= '\0';
717 /* trap NULL parameters on entry */
720 WARN("(lpFile=%s,lpResult=%s): NULL parameter\n",
721 debugstr_w(lpFile
), debugstr_w(lpResult
));
722 return ERROR_FILE_NOT_FOUND
; /* File not found. Close enough, I guess. */
725 if (SHELL_TryAppPathW( lpFile
, lpResult
, env
))
727 TRACE("found %s via App Paths\n", debugstr_w(lpResult
));
731 if (SearchPathW(lpPath
, lpFile
, wszExe
, sizeof(xlpFile
) / sizeof(WCHAR
), xlpFile
, NULL
))
733 TRACE("SearchPathW returned non-zero\n");
735 /* The file was found in the application-supplied default directory (or the system search path) */
737 else if (lpPath
&& SearchPathW(NULL
, lpFile
, wszExe
, sizeof(xlpFile
)/sizeof(WCHAR
), xlpFile
, NULL
))
739 TRACE("SearchPathW returned non-zero\n");
741 /* The file was found in one of the directories in the system-wide search path */
744 attribs
= GetFileAttributesW(lpFile
);
745 if (attribs
!= INVALID_FILE_ATTRIBUTES
&& (attribs
& FILE_ATTRIBUTE_DIRECTORY
))
747 wcscpy(classname
, L
"Folder");
751 /* Did we get something? Anything? */
754 TRACE("Returning SE_ERR_FNF\n");
757 /* First thing we need is the file's extension */
758 extension
= wcsrchr(xlpFile
, '.'); /* Assume last "." is the one; */
759 /* File->Run in progman uses */
761 TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile
), debugstr_w(extension
));
763 if (extension
== NULL
|| extension
[1] == 0)
765 WARN("Returning SE_ERR_NOASSOC\n");
766 return SE_ERR_NOASSOC
;
769 /* Three places to check: */
770 /* 1. win.ini, [windows], programs (NB no leading '.') */
771 /* 2. Registry, HKEY_CLASS_ROOT\<classname>\shell\open\command */
772 /* 3. win.ini, [extensions], extension (NB no leading '.' */
773 /* All I know of the order is that registry is checked before */
774 /* extensions; however, it'd make sense to check the programs */
775 /* section first, so that's what happens here. */
777 /* See if it's a program - if GetProfileString fails, we skip this
778 * section. Actually, if GetProfileString fails, we've probably
779 * got a lot more to worry about than running a program... */
780 if (GetProfileStringW(L
"windows", L
"programs", L
"exe pif bat cmd com", wBuffer
, sizeof(wBuffer
) / sizeof(WCHAR
)) > 0)
787 while (*p
&& *p
!= ' ' && *p
!= '\t') p
++;
791 while (*p
== ' ' || *p
== '\t') p
++;
794 if (wcsicmp(tok
, &extension
[1]) == 0) /* have to skip the leading "." */
796 wcscpy(lpResult
, xlpFile
);
797 /* Need to perhaps check that the file has a path
799 TRACE("found %s\n", debugstr_w(lpResult
));
801 /* Greater than 32 to indicate success */
808 if (RegQueryValueW(HKEY_CLASSES_ROOT
, extension
, classname
,
809 &classnamelen
) == ERROR_SUCCESS
)
811 classnamelen
/= sizeof(WCHAR
);
812 if (classnamelen
== sizeof(classname
) / sizeof(WCHAR
))
815 classname
[classnamelen
] = '\0';
816 TRACE("File type: %s\n", debugstr_w(classname
));
826 /* pass the verb string to SHELL_FindExecutableByVerb() */
827 retval
= SHELL_FindExecutableByVerb(lpVerb
, key
, classname
, command
, sizeof(command
));
832 SHELL_ArgifyW(lpResult
, resultLen
, command
, xlpFile
, pidl
, args
, &finishedLen
);
833 if (finishedLen
> resultLen
)
834 ERR("Argify buffer not large enough.. truncated\n");
835 /* Remove double quotation marks and command line arguments */
836 if (*lpResult
== '"')
839 while (*(p
+ 1) != '"')
848 /* Truncate on first space */
850 while (*p
!= ' ' && *p
!= '\0')
856 else /* Check win.ini */
858 /* Toss the leading dot */
860 if (GetProfileStringW(L
"extensions", extension
, L
"", command
, sizeof(command
) / sizeof(WCHAR
)) > 0)
862 if (wcslen(command
) != 0)
864 wcscpy(lpResult
, command
);
865 tok
= wcschr(lpResult
, '^'); /* should be ^.extension? */
869 wcscat(lpResult
, xlpFile
); /* what if no dir in xlpFile? */
870 tok
= wcschr(command
, '^'); /* see above */
871 if ((tok
!= NULL
) && (wcslen(tok
) > 5))
873 wcscat(lpResult
, &tok
[5]);
876 retval
= 33; /* FIXME - see above */
881 TRACE("returning %s\n", debugstr_w(lpResult
));
885 /******************************************************************
888 * callback for the DDE connection. not really useful
890 static HDDEDATA CALLBACK
dde_cb(UINT uType
, UINT uFmt
, HCONV hConv
,
891 HSZ hsz1
, HSZ hsz2
, HDDEDATA hData
,
892 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
894 TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
895 uType
, uFmt
, hConv
, hsz1
, hsz2
, hData
, dwData1
, dwData2
);
899 /******************************************************************
902 * ShellExecute helper. Used to do an operation with a DDE connection
904 * Handles both the direct connection (try #1), and if it fails,
905 * launching an application and trying (#2) to connect to it
908 static unsigned dde_connect(const WCHAR
* key
, const WCHAR
* start
, WCHAR
* ddeexec
,
909 const WCHAR
* lpFile
, WCHAR
*env
,
910 LPCWSTR szCommandline
, LPITEMIDLIST pidl
, SHELL_ExecuteW32 execfunc
,
911 const SHELLEXECUTEINFOW
*psei
, LPSHELLEXECUTEINFOW psei_out
)
914 WCHAR
* endkey
= regkey
+ wcslen(key
);
915 WCHAR app
[256], topic
[256], ifexec
[256], static_res
[256];
916 WCHAR
* dynamic_res
=NULL
;
918 LONG applen
, topiclen
, ifexeclen
;
922 DWORD resultLen
, endkeyLen
;
923 HSZ hszApp
, hszTopic
;
926 unsigned ret
= SE_ERR_NOASSOC
;
927 BOOL unicode
= !(GetVersion() & 0x80000000);
929 if (strlenW(key
) + 1 > sizeof(regkey
) / sizeof(regkey
[0]))
931 FIXME("input parameter %s larger than buffer\n", debugstr_w(key
));
935 static const WCHAR wApplication
[] = L
"\\application";
936 endkeyLen
= sizeof(regkey
) / sizeof(regkey
[0]) - (endkey
- regkey
);
937 if (strlenW(wApplication
) + 1 > endkeyLen
)
939 FIXME("endkey %s overruns buffer\n", debugstr_w(wApplication
));
942 wcscpy(endkey
, wApplication
);
943 applen
= sizeof(app
);
944 if (RegQueryValueW(HKEY_CLASSES_ROOT
, regkey
, app
, &applen
) != ERROR_SUCCESS
)
946 WCHAR command
[1024], fullpath
[MAX_PATH
];
947 static const WCHAR wSo
[] = L
".so";
948 DWORD sizeSo
= sizeof(wSo
) / sizeof(WCHAR
);
952 /* Get application command from start string and find filename of application */
955 if (strlenW(start
+ 1) + 1 > sizeof(command
) / sizeof(command
[0]))
957 FIXME("size of input parameter %s larger than buffer\n",
958 debugstr_w(start
+ 1));
961 wcscpy(command
, start
+ 1);
962 if ((ptr
= wcschr(command
, '"')))
964 ret
= SearchPathW(NULL
, command
, wszExe
, sizeof(fullpath
) / sizeof(WCHAR
), fullpath
, &ptr
);
970 for (p
= start
; (space
= const_cast<LPWSTR
>(strchrW(p
, ' '))); p
= space
+ 1)
972 int idx
= space
- start
;
973 memcpy(command
, start
, idx
* sizeof(WCHAR
));
975 if ((ret
= SearchPathW(NULL
, command
, wszExe
, sizeof(fullpath
) / sizeof(WCHAR
), fullpath
, &ptr
)))
979 ret
= SearchPathW(NULL
, start
, wszExe
, sizeof(fullpath
) / sizeof(WCHAR
), fullpath
, &ptr
);
984 ERR("Unable to find application path for command %s\n", debugstr_w(start
));
985 return ERROR_ACCESS_DENIED
;
987 if (strlenW(ptr
) + 1 > sizeof(app
) / sizeof(app
[0]))
989 FIXME("size of found path %s larger than buffer\n", debugstr_w(ptr
));
994 /* Remove extensions (including .so) */
995 ptr
= app
+ wcslen(app
) - (sizeSo
- 1);
996 if (wcslen(app
) >= sizeSo
&&
1000 ptr
= const_cast<LPWSTR
>(strrchrW(app
, '.'));
1005 static const WCHAR wTopic
[] = L
"\\topic";
1006 if (strlenW(wTopic
) + 1 > endkeyLen
)
1008 FIXME("endkey %s overruns buffer\n", debugstr_w(wTopic
));
1011 wcscpy(endkey
, wTopic
);
1012 topiclen
= sizeof(topic
);
1013 if (RegQueryValueW(HKEY_CLASSES_ROOT
, regkey
, topic
, &topiclen
) != ERROR_SUCCESS
)
1015 wcscpy(topic
, L
"System");
1020 if (DdeInitializeW(&ddeInst
, dde_cb
, APPCMD_CLIENTONLY
, 0L) != DMLERR_NO_ERROR
)
1025 if (DdeInitializeA(&ddeInst
, dde_cb
, APPCMD_CLIENTONLY
, 0L) != DMLERR_NO_ERROR
)
1029 hszApp
= DdeCreateStringHandleW(ddeInst
, app
, CP_WINUNICODE
);
1030 hszTopic
= DdeCreateStringHandleW(ddeInst
, topic
, CP_WINUNICODE
);
1032 hConv
= DdeConnect(ddeInst
, hszApp
, hszTopic
, NULL
);
1036 TRACE("Launching %s\n", debugstr_w(start
));
1037 ret
= execfunc(start
, env
, TRUE
, psei
, psei_out
);
1040 TRACE("Couldn't launch\n");
1043 hConv
= DdeConnect(ddeInst
, hszApp
, hszTopic
, NULL
);
1046 TRACE("Couldn't connect. ret=%d\n", ret
);
1047 DdeUninitialize(ddeInst
);
1048 SetLastError(ERROR_DDE_FAIL
);
1049 return 30; /* whatever */
1051 static const WCHAR wIfexec
[] = L
"\\ifexec";
1052 if (strlenW(wIfexec
) + 1 > endkeyLen
)
1054 FIXME("endkey %s overruns buffer\n", debugstr_w(wIfexec
));
1057 strcpyW(endkey
, wIfexec
);
1058 ifexeclen
= sizeof(ifexec
);
1059 if (RegQueryValueW(HKEY_CLASSES_ROOT
, regkey
, ifexec
, &ifexeclen
) == ERROR_SUCCESS
)
1065 SHELL_ArgifyW(static_res
, sizeof(static_res
)/sizeof(WCHAR
), exec
, lpFile
, pidl
, szCommandline
, &resultLen
);
1066 if (resultLen
> sizeof(static_res
)/sizeof(WCHAR
))
1068 res
= dynamic_res
= static_cast<WCHAR
*>(HeapAlloc(GetProcessHeap(), 0, resultLen
* sizeof(WCHAR
)));
1069 SHELL_ArgifyW(dynamic_res
, resultLen
, exec
, lpFile
, pidl
, szCommandline
, NULL
);
1073 TRACE("%s %s => %s\n", debugstr_w(exec
), debugstr_w(lpFile
), debugstr_w(res
));
1075 /* It's documented in the KB 330337 that IE has a bug and returns
1076 * error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
1079 hDdeData
= DdeClientTransaction((LPBYTE
)res
, (strlenW(res
) + 1) * sizeof(WCHAR
), hConv
, 0L, 0, XTYP_EXECUTE
, 30000, &tid
);
1082 DWORD lenA
= WideCharToMultiByte(CP_ACP
, 0, res
, -1, NULL
, 0, NULL
, NULL
);
1083 char *resA
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, lenA
);
1084 WideCharToMultiByte(CP_ACP
, 0, res
, -1, resA
, lenA
, NULL
, NULL
);
1085 hDdeData
= DdeClientTransaction( (LPBYTE
)resA
, lenA
, hConv
, 0L, 0,
1086 XTYP_EXECUTE
, 10000, &tid
);
1087 HeapFree(GetProcessHeap(), 0, resA
);
1090 DdeFreeDataHandle(hDdeData
);
1092 WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst
));
1095 HeapFree(GetProcessHeap(), 0, dynamic_res
);
1097 DdeDisconnect(hConv
);
1100 DdeUninitialize(ddeInst
);
1105 /*************************************************************************
1106 * execute_from_key [Internal]
1108 static UINT_PTR
execute_from_key(LPCWSTR key
, LPCWSTR lpFile
, WCHAR
*env
,
1109 LPCWSTR szCommandline
, LPCWSTR executable_name
,
1110 SHELL_ExecuteW32 execfunc
,
1111 LPSHELLEXECUTEINFOW psei
, LPSHELLEXECUTEINFOW psei_out
)
1113 WCHAR cmd
[256], param
[1024], ddeexec
[256];
1114 DWORD cmdlen
= sizeof(cmd
), ddeexeclen
= sizeof(ddeexec
);
1115 UINT_PTR retval
= SE_ERR_NOASSOC
;
1119 TRACE("%s %s %s %s %s\n", debugstr_w(key
), debugstr_w(lpFile
), debugstr_w(env
),
1120 debugstr_w(szCommandline
), debugstr_w(executable_name
));
1125 /* Get the application from the registry */
1126 if (RegQueryValueW(HKEY_CLASSES_ROOT
, key
, cmd
, (LONG
*)&cmdlen
) == ERROR_SUCCESS
)
1128 TRACE("got cmd: %s\n", debugstr_w(cmd
));
1130 /* Is there a replace() function anywhere? */
1131 cmdlen
/= sizeof(WCHAR
);
1132 if (cmdlen
>= sizeof(cmd
) / sizeof(WCHAR
))
1133 cmdlen
= sizeof(cmd
) / sizeof(WCHAR
) - 1;
1135 SHELL_ArgifyW(param
, sizeof(param
) / sizeof(WCHAR
), cmd
, lpFile
, (LPITEMIDLIST
)psei
->lpIDList
, szCommandline
, &resultLen
);
1136 if (resultLen
> sizeof(param
) / sizeof(WCHAR
))
1137 ERR("Argify buffer not large enough, truncating\n");
1140 /* Get the parameters needed by the application
1141 from the associated ddeexec key */
1142 tmp
= const_cast<LPWSTR
>(strstrW(key
, L
"command"));
1144 wcscpy(tmp
, L
"ddeexec");
1146 if (RegQueryValueW(HKEY_CLASSES_ROOT
, key
, ddeexec
, (LONG
*)&ddeexeclen
) == ERROR_SUCCESS
)
1148 TRACE("Got ddeexec %s => %s\n", debugstr_w(key
), debugstr_w(ddeexec
));
1149 if (!param
[0]) strcpyW(param
, executable_name
);
1150 retval
= dde_connect(key
, param
, ddeexec
, lpFile
, env
, szCommandline
, (LPITEMIDLIST
)psei
->lpIDList
, execfunc
, psei
, psei_out
);
1154 TRACE("executing: %s\n", debugstr_w(param
));
1155 retval
= execfunc(param
, env
, FALSE
, psei
, psei_out
);
1158 WARN("Nothing appropriate found for %s\n", debugstr_w(key
));
1163 /*************************************************************************
1164 * FindExecutableA [SHELL32.@]
1166 HINSTANCE WINAPI
FindExecutableA(LPCSTR lpFile
, LPCSTR lpDirectory
, LPSTR lpResult
)
1169 WCHAR
*wFile
= NULL
, *wDirectory
= NULL
;
1170 WCHAR wResult
[MAX_PATH
];
1172 if (lpFile
) __SHCloneStrAtoW(&wFile
, lpFile
);
1173 if (lpDirectory
) __SHCloneStrAtoW(&wDirectory
, lpDirectory
);
1175 retval
= FindExecutableW(wFile
, wDirectory
, wResult
);
1176 WideCharToMultiByte(CP_ACP
, 0, wResult
, -1, lpResult
, MAX_PATH
, NULL
, NULL
);
1180 TRACE("returning %s\n", lpResult
);
1184 /*************************************************************************
1185 * FindExecutableW [SHELL32.@]
1187 * This function returns the executable associated with the specified file
1188 * for the default verb.
1191 * lpFile [I] The file to find the association for. This must refer to
1192 * an existing file otherwise FindExecutable fails and returns
1194 * lpResult [O] Points to a buffer into which the executable path is
1195 * copied. This parameter must not be NULL otherwise
1196 * FindExecutable() segfaults. The buffer must be of size at
1197 * least MAX_PATH characters.
1200 * A value greater than 32 on success, less than or equal to 32 otherwise.
1201 * See the SE_ERR_* constants.
1204 * On Windows XP and 2003, FindExecutable() seems to first convert the
1205 * filename into 8.3 format, thus taking into account only the first three
1206 * characters of the extension, and expects to find an association for those.
1207 * However other Windows versions behave sanely.
1209 HINSTANCE WINAPI
FindExecutableW(LPCWSTR lpFile
, LPCWSTR lpDirectory
, LPWSTR lpResult
)
1211 UINT_PTR retval
= SE_ERR_NOASSOC
;
1212 WCHAR old_dir
[1024];
1213 WCHAR res
[MAX_PATH
];
1215 TRACE("File %s, Dir %s\n", debugstr_w(lpFile
), debugstr_w(lpDirectory
));
1217 lpResult
[0] = '\0'; /* Start off with an empty return string */
1219 return (HINSTANCE
)SE_ERR_FNF
;
1223 GetCurrentDirectoryW(sizeof(old_dir
) / sizeof(WCHAR
), old_dir
);
1224 SetCurrentDirectoryW(lpDirectory
);
1227 retval
= SHELL_FindExecutable(lpDirectory
, lpFile
, wszOpen
, res
, MAX_PATH
, NULL
, NULL
, NULL
, NULL
);
1229 strcpyW(lpResult
, res
);
1231 TRACE("returning %s\n", debugstr_w(lpResult
));
1233 SetCurrentDirectoryW(old_dir
);
1234 return (HINSTANCE
)retval
;
1237 /* FIXME: is this already implemented somewhere else? */
1238 static HKEY
ShellExecute_GetClassKey(const SHELLEXECUTEINFOW
*sei
)
1240 LPCWSTR ext
= NULL
, lpClass
= NULL
;
1242 DWORD type
= 0, sz
= 0;
1246 if (sei
->fMask
& SEE_MASK_CLASSALL
)
1247 return sei
->hkeyClass
;
1249 if (sei
->fMask
& SEE_MASK_CLASSNAME
)
1250 lpClass
= sei
->lpClass
;
1253 ext
= PathFindExtensionW(sei
->lpFile
);
1254 TRACE("ext = %s\n", debugstr_w(ext
));
1258 r
= RegOpenKeyW(HKEY_CLASSES_ROOT
, ext
, &hkey
);
1259 if (r
!= ERROR_SUCCESS
)
1262 r
= RegQueryValueExW(hkey
, NULL
, 0, &type
, NULL
, &sz
);
1263 if (r
== ERROR_SUCCESS
&& type
== REG_SZ
)
1265 sz
+= sizeof (WCHAR
);
1266 cls
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, sz
);
1268 RegQueryValueExW(hkey
, NULL
, 0, &type
, (LPBYTE
) cls
, &sz
);
1271 RegCloseKey( hkey
);
1275 TRACE("class = %s\n", debugstr_w(lpClass
));
1279 RegOpenKeyW( HKEY_CLASSES_ROOT
, lpClass
, &hkey
);
1281 HeapFree(GetProcessHeap(), 0, cls
);
1286 static IDataObject
*shellex_get_dataobj( LPSHELLEXECUTEINFOW sei
)
1288 LPCITEMIDLIST pidllast
= NULL
;
1289 CComPtr
<IDataObject
> dataobj
;
1290 CComPtr
<IShellFolder
> shf
;
1291 LPITEMIDLIST pidl
= NULL
;
1294 if (sei
->fMask
& SEE_MASK_CLASSALL
)
1295 pidl
= (LPITEMIDLIST
)sei
->lpIDList
;
1298 WCHAR fullpath
[MAX_PATH
];
1302 ret
= GetFullPathNameW(sei
->lpFile
, MAX_PATH
, fullpath
, NULL
);
1306 pidl
= ILCreateFromPathW(fullpath
);
1309 r
= SHBindToParent(pidl
, IID_PPV_ARG(IShellFolder
, &shf
), &pidllast
);
1313 shf
->GetUIObjectOf(NULL
, 1, &pidllast
, IID_NULL_PPV_ARG(IDataObject
, &dataobj
));
1316 if (pidl
!= sei
->lpIDList
)
1318 return dataobj
.Detach();
1321 static HRESULT
shellex_run_context_menu_default(IShellExtInit
*obj
,
1322 LPSHELLEXECUTEINFOW sei
)
1324 CComPtr
<IContextMenu
> cm
= NULL
;
1325 CMINVOKECOMMANDINFOEX ici
;
1332 TRACE("%p %p\n", obj
, sei
);
1334 r
= obj
->QueryInterface(IID_PPV_ARG(IContextMenu
, &cm
));
1338 hmenu
= CreateMenu();
1342 /* the number of the last menu added is returned in r */
1343 r
= cm
->QueryContextMenu(hmenu
, 0, 0x20, 0x7fff, CMF_DEFAULTONLY
);
1347 n
= GetMenuItemCount(hmenu
);
1348 for (i
= 0; i
< n
; i
++)
1350 memset(&info
, 0, sizeof(info
));
1351 info
.cbSize
= sizeof info
;
1352 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
1353 info
.dwTypeData
= string
;
1354 info
.cch
= sizeof string
;
1356 GetMenuItemInfoW(hmenu
, i
, TRUE
, &info
);
1358 TRACE("menu %d %s %08x %08lx %08x %08x\n", i
, debugstr_w(string
),
1359 info
.fState
, info
.dwItemData
, info
.fType
, info
.wID
);
1360 if ((!sei
->lpVerb
&& (info
.fState
& MFS_DEFAULT
)) ||
1361 (sei
->lpVerb
&& !lstrcmpiW(sei
->lpVerb
, string
)))
1372 memset(&ici
, 0, sizeof ici
);
1373 ici
.cbSize
= sizeof ici
;
1374 ici
.fMask
= CMIC_MASK_UNICODE
| (sei
->fMask
& (SEE_MASK_NO_CONSOLE
| SEE_MASK_NOASYNC
| SEE_MASK_ASYNCOK
| SEE_MASK_FLAG_NO_UI
));
1375 ici
.nShow
= sei
->nShow
;
1376 ici
.lpVerb
= MAKEINTRESOURCEA(def
);
1377 ici
.hwnd
= sei
->hwnd
;
1378 ici
.lpParametersW
= sei
->lpParameters
;
1380 r
= cm
->InvokeCommand((LPCMINVOKECOMMANDINFO
)&ici
);
1382 TRACE("invoke command returned %08x\n", r
);
1386 DestroyMenu( hmenu
);
1390 static HRESULT
shellex_load_object_and_run(HKEY hkey
, LPCGUID guid
, LPSHELLEXECUTEINFOW sei
)
1392 // Can not use CComPtr here because of CoUninitialize at the end, before the destructors would run.
1393 IDataObject
*dataobj
= NULL
;
1394 IObjectWithSite
*ows
= NULL
;
1395 IShellExtInit
*obj
= NULL
;
1398 TRACE("%p %s %p\n", hkey
, debugstr_guid(guid
), sei
);
1400 r
= CoInitialize(NULL
);
1404 r
= CoCreateInstance(*guid
, NULL
, CLSCTX_INPROC_SERVER
,
1405 IID_PPV_ARG(IShellExtInit
, &obj
));
1408 ERR("failed %08x\n", r
);
1412 dataobj
= shellex_get_dataobj(sei
);
1415 ERR("failed to get data object\n");
1420 r
= obj
->Initialize(NULL
, dataobj
, hkey
);
1424 r
= obj
->QueryInterface(IID_PPV_ARG(IObjectWithSite
, &ows
));
1430 r
= shellex_run_context_menu_default(obj
, sei
);
1444 /*************************************************************************
1445 * ShellExecute_FromContextMenu [Internal]
1447 static LONG
ShellExecute_FromContextMenu( LPSHELLEXECUTEINFOW sei
)
1449 HKEY hkey
, hkeycm
= 0;
1456 TRACE("%s\n", debugstr_w(sei
->lpFile
));
1458 hkey
= ShellExecute_GetClassKey(sei
);
1460 return ERROR_FUNCTION_FAILED
;
1462 r
= RegOpenKeyW(hkey
, L
"shellex\\ContextMenuHandlers", &hkeycm
);
1463 if (r
== ERROR_SUCCESS
)
1468 r
= RegEnumKeyW(hkeycm
, i
++, szguid
, sizeof(szguid
) / sizeof(szguid
[0]));
1469 if (r
!= ERROR_SUCCESS
)
1472 hr
= CLSIDFromString(szguid
, &guid
);
1475 /* stop at the first one that succeeds in running */
1476 hr
= shellex_load_object_and_run(hkey
, &guid
, sei
);
1481 RegCloseKey(hkeycm
);
1484 if (hkey
!= sei
->hkeyClass
)
1489 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
);
1491 static UINT_PTR
SHELL_execute_class(LPCWSTR wszApplicationName
, LPSHELLEXECUTEINFOW psei
, LPSHELLEXECUTEINFOW psei_out
, SHELL_ExecuteW32 execfunc
)
1493 WCHAR execCmd
[1024], classname
[1024];
1494 /* launch a document by fileclass like 'WordPad.Document.1' */
1495 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
1496 /* FIXME: wcmd should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
1497 ULONG cmask
= (psei
->fMask
& SEE_MASK_CLASSALL
);
1502 /* FIXME: remove following block when SHELL_quote_and_execute supports hkeyClass parameter */
1503 if (cmask
!= SEE_MASK_CLASSNAME
)
1506 HCR_GetExecuteCommandW((cmask
== SEE_MASK_CLASSKEY
) ? psei
->hkeyClass
: NULL
,
1507 (cmask
== SEE_MASK_CLASSNAME
) ? psei
->lpClass
: NULL
,
1509 execCmd
, sizeof(execCmd
));
1511 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
1512 TRACE("SEE_MASK_CLASSNAME->%s, doc->%s\n", debugstr_w(execCmd
), debugstr_w(wszApplicationName
));
1515 done
= SHELL_ArgifyW(wcmd
, sizeof(wcmd
) / sizeof(WCHAR
), execCmd
, wszApplicationName
, (LPITEMIDLIST
)psei
->lpIDList
, NULL
, &resultLen
);
1516 if (!done
&& wszApplicationName
[0])
1518 strcatW(wcmd
, L
" ");
1519 if (*wszApplicationName
!= '"')
1521 strcatW(wcmd
, L
"\"");
1522 strcatW(wcmd
, wszApplicationName
);
1523 strcatW(wcmd
, L
"\"");
1526 strcatW(wcmd
, wszApplicationName
);
1528 if (resultLen
> sizeof(wcmd
) / sizeof(WCHAR
))
1529 ERR("Argify buffer not large enough... truncating\n");
1530 return execfunc(wcmd
, NULL
, FALSE
, psei
, psei_out
);
1533 strcpyW(classname
, psei
->lpClass
);
1534 rslt
= SHELL_FindExecutableByVerb(psei
->lpVerb
, NULL
, classname
, execCmd
, sizeof(execCmd
));
1536 TRACE("SHELL_FindExecutableByVerb returned %u (%s, %s)\n", (unsigned int)rslt
, debugstr_w(classname
), debugstr_w(execCmd
));
1539 rslt
= SHELL_quote_and_execute( execCmd
, L
"", classname
,
1540 wszApplicationName
, NULL
, psei
,
1541 psei_out
, execfunc
);
1546 static BOOL
SHELL_translate_idlist(LPSHELLEXECUTEINFOW sei
, LPWSTR wszParameters
, DWORD parametersLen
, LPWSTR wszApplicationName
, DWORD dwApplicationNameLen
)
1548 static const WCHAR wExplorer
[] = L
"explorer.exe";
1549 WCHAR buffer
[MAX_PATH
];
1550 BOOL appKnownSingular
= FALSE
;
1552 /* last chance to translate IDList: now also allow CLSID paths */
1553 if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW((LPCITEMIDLIST
)sei
->lpIDList
, buffer
, sizeof(buffer
)/sizeof(WCHAR
)))) {
1554 if (buffer
[0] == ':' && buffer
[1] == ':') {
1555 /* open shell folder for the specified class GUID */
1556 if (strlenW(buffer
) + 1 > parametersLen
)
1557 ERR("parameters len exceeds buffer size (%i > %i), truncating\n",
1558 lstrlenW(buffer
) + 1, parametersLen
);
1559 lstrcpynW(wszParameters
, buffer
, parametersLen
);
1560 if (strlenW(wExplorer
) > dwApplicationNameLen
)
1561 ERR("application len exceeds buffer size (%i > %i), truncating\n",
1562 lstrlenW(wExplorer
) + 1, dwApplicationNameLen
);
1563 lstrcpynW(wszApplicationName
, wExplorer
, dwApplicationNameLen
);
1564 appKnownSingular
= TRUE
;
1566 sei
->fMask
&= ~SEE_MASK_INVOKEIDLIST
;
1568 WCHAR target
[MAX_PATH
];
1571 /* Check if we're executing a directory and if so use the
1572 handler for the Folder class */
1573 strcpyW(target
, buffer
);
1574 attribs
= GetFileAttributesW(buffer
);
1575 if (attribs
!= INVALID_FILE_ATTRIBUTES
&&
1576 (attribs
& FILE_ATTRIBUTE_DIRECTORY
) &&
1577 HCR_GetExecuteCommandW(0, L
"Folder",
1579 buffer
, sizeof(buffer
))) {
1580 SHELL_ArgifyW(wszApplicationName
, dwApplicationNameLen
,
1581 buffer
, target
, (LPITEMIDLIST
)sei
->lpIDList
, NULL
, &resultLen
);
1582 if (resultLen
> dwApplicationNameLen
)
1583 ERR("Argify buffer not large enough... truncating\n");
1584 appKnownSingular
= FALSE
;
1586 sei
->fMask
&= ~SEE_MASK_INVOKEIDLIST
;
1589 return appKnownSingular
;
1592 static UINT_PTR
SHELL_quote_and_execute(LPCWSTR wcmd
, LPCWSTR wszParameters
, LPCWSTR wszKeyname
, LPCWSTR wszApplicationName
, LPWSTR env
, LPSHELLEXECUTEINFOW psei
, LPSHELLEXECUTEINFOW psei_out
, SHELL_ExecuteW32 execfunc
)
1596 WCHAR
*wszQuotedCmd
;
1598 /* Length of quotes plus length of command plus NULL terminator */
1599 len
= 2 + lstrlenW(wcmd
) + 1;
1600 if (wszParameters
[0])
1602 /* Length of space plus length of parameters */
1603 len
+= 1 + lstrlenW(wszParameters
);
1605 wszQuotedCmd
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1606 /* Must quote to handle case where cmd contains spaces,
1607 * else security hole if malicious user creates executable file "C:\\Program"
1609 strcpyW(wszQuotedCmd
, L
"\"");
1610 strcatW(wszQuotedCmd
, wcmd
);
1611 strcatW(wszQuotedCmd
, L
"\"");
1612 if (wszParameters
[0])
1614 strcatW(wszQuotedCmd
, L
" ");
1615 strcatW(wszQuotedCmd
, wszParameters
);
1618 TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName
), debugstr_w(psei
->lpVerb
), debugstr_w(wszQuotedCmd
), debugstr_w(wszKeyname
));
1621 retval
= execute_from_key(wszKeyname
, wszApplicationName
, env
, psei
->lpParameters
, wcmd
, execfunc
, psei
, psei_out
);
1623 retval
= execfunc(wszQuotedCmd
, env
, FALSE
, psei
, psei_out
);
1624 HeapFree(GetProcessHeap(), 0, wszQuotedCmd
);
1628 static UINT_PTR
SHELL_execute_url(LPCWSTR lpFile
, LPCWSTR wcmd
, LPSHELLEXECUTEINFOW psei
, LPSHELLEXECUTEINFOW psei_out
, SHELL_ExecuteW32 execfunc
)
1630 static const WCHAR wShell
[] = L
"\\shell\\";
1631 static const WCHAR wCommand
[] = L
"\\command";
1633 WCHAR
*lpstrProtocol
;
1638 lpstrRes
= strchrW(lpFile
, ':');
1640 iSize
= lpstrRes
- lpFile
;
1642 iSize
= strlenW(lpFile
);
1644 TRACE("Got URL: %s\n", debugstr_w(lpFile
));
1645 /* Looking for ...<protocol>\shell\<lpVerb>\command */
1646 len
= iSize
+ lstrlenW(wShell
) + lstrlenW(wCommand
) + 1;
1647 if (psei
->lpVerb
&& *psei
->lpVerb
)
1648 len
+= lstrlenW(psei
->lpVerb
);
1650 len
+= lstrlenW(wszOpen
);
1651 lpstrProtocol
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1652 memcpy(lpstrProtocol
, lpFile
, iSize
* sizeof(WCHAR
));
1653 lpstrProtocol
[iSize
] = '\0';
1654 strcatW(lpstrProtocol
, wShell
);
1655 strcatW(lpstrProtocol
, psei
->lpVerb
&& *psei
->lpVerb
? psei
->lpVerb
: wszOpen
);
1656 strcatW(lpstrProtocol
, wCommand
);
1658 retval
= execute_from_key(lpstrProtocol
, lpFile
, NULL
, psei
->lpParameters
,
1659 wcmd
, execfunc
, psei
, psei_out
);
1660 HeapFree(GetProcessHeap(), 0, lpstrProtocol
);
1664 static void do_error_dialog(UINT_PTR retval
, HWND hwnd
, WCHAR
* filename
)
1667 DWORD_PTR msgArguments
[3] = { (DWORD_PTR
)filename
, 0, 0 };
1670 error_code
= GetLastError();
1671 if (retval
== SE_ERR_NOASSOC
)
1672 LoadStringW(shell32_hInstance
, IDS_SHLEXEC_NOASSOC
, msg
, sizeof(msg
) / sizeof(WCHAR
));
1674 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1679 sizeof(msg
) / sizeof(WCHAR
),
1680 (va_list*)msgArguments
);
1682 MessageBoxW(hwnd
, msg
, NULL
, MB_ICONERROR
);
1685 static WCHAR
*expand_environment( const WCHAR
*str
)
1690 len
= ExpandEnvironmentStringsW(str
, NULL
, 0);
1691 if (!len
) return NULL
;
1693 buf
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1694 if (!buf
) return NULL
;
1696 len
= ExpandEnvironmentStringsW(str
, buf
, len
);
1699 HeapFree(GetProcessHeap(), 0, buf
);
1705 /*************************************************************************
1706 * SHELL_execute [Internal]
1708 static BOOL
SHELL_execute(LPSHELLEXECUTEINFOW sei
, SHELL_ExecuteW32 execfunc
)
1710 static const DWORD unsupportedFlags
=
1711 SEE_MASK_INVOKEIDLIST
| SEE_MASK_ICON
| SEE_MASK_HOTKEY
|
1712 SEE_MASK_CONNECTNETDRV
| SEE_MASK_FLAG_DDEWAIT
|
1713 SEE_MASK_UNICODE
| SEE_MASK_ASYNCOK
| SEE_MASK_HMONITOR
;
1715 WCHAR parametersBuffer
[1024], dirBuffer
[MAX_PATH
], wcmdBuffer
[1024];
1716 WCHAR
*wszApplicationName
, *wszParameters
, *wszDir
, *wcmd
;
1717 DWORD dwApplicationNameLen
= MAX_PATH
+ 2;
1718 DWORD parametersLen
= sizeof(parametersBuffer
) / sizeof(WCHAR
);
1719 DWORD dirLen
= sizeof(dirBuffer
) / sizeof(WCHAR
);
1720 DWORD wcmdLen
= sizeof(wcmdBuffer
) / sizeof(WCHAR
);
1722 SHELLEXECUTEINFOW sei_tmp
; /* modifiable copy of SHELLEXECUTEINFO struct */
1723 WCHAR wfileName
[MAX_PATH
];
1725 WCHAR wszKeyname
[256];
1727 UINT_PTR retval
= SE_ERR_NOASSOC
;
1728 BOOL appKnownSingular
= FALSE
;
1730 /* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
1733 TRACE("mask=0x%08x hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
1734 sei_tmp
.fMask
, sei_tmp
.hwnd
, debugstr_w(sei_tmp
.lpVerb
),
1735 debugstr_w(sei_tmp
.lpFile
), debugstr_w(sei_tmp
.lpParameters
),
1736 debugstr_w(sei_tmp
.lpDirectory
), sei_tmp
.nShow
,
1737 ((sei_tmp
.fMask
& SEE_MASK_CLASSALL
) == SEE_MASK_CLASSNAME
) ?
1738 debugstr_w(sei_tmp
.lpClass
) : "not used");
1740 sei
->hProcess
= NULL
;
1742 /* make copies of all path/command strings */
1743 if (!sei_tmp
.lpFile
)
1745 wszApplicationName
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen
* sizeof(WCHAR
));
1746 *wszApplicationName
= '\0';
1748 else if (*sei_tmp
.lpFile
== '\"' && sei_tmp
.lpFile
[(len
= strlenW(sei_tmp
.lpFile
))-1] == '\"')
1750 if(len
-1 >= dwApplicationNameLen
)
1751 dwApplicationNameLen
= len
;
1753 wszApplicationName
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen
* sizeof(WCHAR
));
1754 memcpy(wszApplicationName
, sei_tmp
.lpFile
+ 1, len
* sizeof(WCHAR
));
1757 wszApplicationName
[len
-2] = '\0';
1758 appKnownSingular
= TRUE
;
1760 TRACE("wszApplicationName=%s\n", debugstr_w(wszApplicationName
));
1764 DWORD l
= strlenW(sei_tmp
.lpFile
) + 1;
1765 if(l
> dwApplicationNameLen
) dwApplicationNameLen
= l
+ 1;
1766 wszApplicationName
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen
* sizeof(WCHAR
));
1767 memcpy(wszApplicationName
, sei_tmp
.lpFile
, l
* sizeof(WCHAR
));
1770 wszParameters
= parametersBuffer
;
1771 if (sei_tmp
.lpParameters
)
1773 len
= lstrlenW(sei_tmp
.lpParameters
) + 1;
1774 if (len
> parametersLen
)
1776 wszParameters
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1777 parametersLen
= len
;
1779 strcpyW(wszParameters
, sei_tmp
.lpParameters
);
1782 *wszParameters
= L
'\0';
1785 if (sei_tmp
.lpDirectory
)
1787 len
= lstrlenW(sei_tmp
.lpDirectory
) + 1;
1790 wszDir
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1793 strcpyW(wszDir
, sei_tmp
.lpDirectory
);
1798 /* adjust string pointers to point to the new buffers */
1799 sei_tmp
.lpFile
= wszApplicationName
;
1800 sei_tmp
.lpParameters
= wszParameters
;
1801 sei_tmp
.lpDirectory
= wszDir
;
1803 if (sei_tmp
.fMask
& unsupportedFlags
)
1805 FIXME("flags ignored: 0x%08x\n", sei_tmp
.fMask
& unsupportedFlags
);
1808 /* process the IDList */
1809 if (sei_tmp
.fMask
& SEE_MASK_IDLIST
)
1811 CComPtr
<IShellExecuteHookW
> pSEH
;
1813 HRESULT hr
= SHBindToParent((LPCITEMIDLIST
)sei_tmp
.lpIDList
, IID_PPV_ARG(IShellExecuteHookW
, &pSEH
), NULL
);
1817 hr
= pSEH
->Execute(&sei_tmp
);
1821 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
1822 if (wszParameters
!= parametersBuffer
)
1823 HeapFree(GetProcessHeap(), 0, wszParameters
);
1824 if (wszDir
!= dirBuffer
)
1825 HeapFree(GetProcessHeap(), 0, wszDir
);
1830 SHGetPathFromIDListW((LPCITEMIDLIST
)sei_tmp
.lpIDList
, wszApplicationName
);
1831 appKnownSingular
= TRUE
;
1832 TRACE("-- idlist=%p (%s)\n", sei_tmp
.lpIDList
, debugstr_w(wszApplicationName
));
1835 if (sei_tmp
.fMask
& SEE_MASK_DOENVSUBST
)
1839 tmp
= expand_environment(sei_tmp
.lpFile
);
1844 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
1845 sei_tmp
.lpFile
= wszApplicationName
= tmp
;
1847 tmp
= expand_environment(sei_tmp
.lpDirectory
);
1852 if (wszDir
!= dirBuffer
) HeapFree(GetProcessHeap(), 0, wszDir
);
1853 sei_tmp
.lpDirectory
= wszDir
= tmp
;
1856 if (ERROR_SUCCESS
== ShellExecute_FromContextMenu(&sei_tmp
))
1858 sei
->hInstApp
= (HINSTANCE
) 33;
1859 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
1860 if (wszParameters
!= parametersBuffer
)
1861 HeapFree(GetProcessHeap(), 0, wszParameters
);
1862 if (wszDir
!= dirBuffer
)
1863 HeapFree(GetProcessHeap(), 0, wszDir
);
1867 if (sei_tmp
.fMask
& SEE_MASK_CLASSALL
)
1869 retval
= SHELL_execute_class(wszApplicationName
, &sei_tmp
, sei
, execfunc
);
1870 if (retval
<= 32 && !(sei_tmp
.fMask
& SEE_MASK_FLAG_NO_UI
))
1877 Info
.pcszFile
= wszApplicationName
;
1878 Info
.pcszClass
= NULL
;
1879 Info
.oaifInFlags
= OAIF_ALLOW_REGISTRATION
| OAIF_EXEC
;
1881 //if (SHOpenWithDialog(sei_tmp.hwnd, &Info) != S_OK)
1882 DBG_UNREFERENCED_LOCAL_VARIABLE(Info
);
1883 do_error_dialog(retval
, sei_tmp
.hwnd
, wszApplicationName
);
1885 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
1886 if (wszParameters
!= parametersBuffer
)
1887 HeapFree(GetProcessHeap(), 0, wszParameters
);
1888 if (wszDir
!= dirBuffer
)
1889 HeapFree(GetProcessHeap(), 0, wszDir
);
1893 /* Has the IDList not yet been translated? */
1894 if (sei_tmp
.fMask
& SEE_MASK_IDLIST
)
1896 appKnownSingular
= SHELL_translate_idlist( &sei_tmp
, wszParameters
,
1899 dwApplicationNameLen
);
1902 /* convert file URLs */
1903 if (UrlIsFileUrlW(sei_tmp
.lpFile
))
1909 buf
= static_cast<LPWSTR
>(HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
)));
1910 if (!buf
|| FAILED(PathCreateFromUrlW(sei_tmp
.lpFile
, buf
, &size
, 0)))
1912 HeapFree(GetProcessHeap(), 0, buf
);
1916 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
1917 wszApplicationName
= buf
;
1918 sei_tmp
.lpFile
= wszApplicationName
;
1920 else /* or expand environment strings (not both!) */
1922 len
= ExpandEnvironmentStringsW(sei_tmp
.lpFile
, NULL
, 0);
1926 buf
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
1928 ExpandEnvironmentStringsW(sei_tmp
.lpFile
, buf
, len
+ 1);
1929 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
1930 wszApplicationName
= buf
;
1931 /* appKnownSingular unmodified */
1933 sei_tmp
.lpFile
= wszApplicationName
;
1937 if (*sei_tmp
.lpDirectory
)
1939 len
= ExpandEnvironmentStringsW(sei_tmp
.lpDirectory
, NULL
, 0);
1944 buf
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1945 ExpandEnvironmentStringsW(sei_tmp
.lpDirectory
, buf
, len
);
1946 if (wszDir
!= dirBuffer
)
1947 HeapFree(GetProcessHeap(), 0, wszDir
);
1949 sei_tmp
.lpDirectory
= wszDir
;
1953 /* Else, try to execute the filename */
1954 TRACE("execute: %s,%s,%s\n", debugstr_w(wszApplicationName
), debugstr_w(wszParameters
), debugstr_w(wszDir
));
1956 /* separate out command line arguments from executable file name */
1957 if (!*sei_tmp
.lpParameters
&& !appKnownSingular
)
1959 /* If the executable path is quoted, handle the rest of the command line as parameters. */
1960 if (sei_tmp
.lpFile
[0] == L
'"')
1962 LPWSTR src
= wszApplicationName
/*sei_tmp.lpFile*/ + 1;
1963 LPWSTR dst
= wfileName
;
1966 /* copy the unquoted executable path to 'wfileName' */
1967 while(*src
&& *src
!= L
'"')
1976 while(isspaceW(*src
))
1982 /* copy the parameter string to 'wszParameters' */
1983 strcpyW(wszParameters
, src
);
1985 /* terminate previous command string after the quote character */
1991 /* If the executable name is not quoted, we have to use this search loop here,
1992 that in CreateProcess() is not sufficient because it does not handle shell links. */
1993 WCHAR buffer
[MAX_PATH
], xlpFile
[MAX_PATH
];
1996 LPWSTR beg
= wszApplicationName
/*sei_tmp.lpFile*/;
1997 for(s
= beg
; (space
= const_cast<LPWSTR
>(strchrW(s
, L
' '))); s
= space
+ 1)
1999 int idx
= space
- sei_tmp
.lpFile
;
2000 memcpy(buffer
, sei_tmp
.lpFile
, idx
* sizeof(WCHAR
));
2003 /*FIXME This finds directory paths if the targeted file name contains spaces. */
2004 if (SearchPathW(*sei_tmp
.lpDirectory
? sei_tmp
.lpDirectory
: NULL
, buffer
, wszExe
, sizeof(xlpFile
) / sizeof(xlpFile
[0]), xlpFile
, NULL
))
2006 /* separate out command from parameter string */
2007 LPCWSTR p
= space
+ 1;
2012 strcpyW(wszParameters
, p
);
2019 lpFile
= sei_tmp
.lpFile
;
2023 lpFile
= sei_tmp
.lpFile
;
2026 len
= lstrlenW(wszApplicationName
) + 3;
2027 if (sei_tmp
.lpParameters
[0])
2028 len
+= 1 + lstrlenW(wszParameters
);
2031 wcmd
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2034 swprintf(wcmd
, L
"\"%s\"", wszApplicationName
);
2035 if (sei_tmp
.lpParameters
[0])
2037 strcatW(wcmd
, L
" ");
2038 strcatW(wcmd
, wszParameters
);
2041 retval
= execfunc(wcmd
, NULL
, FALSE
, &sei_tmp
, sei
);
2044 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
2045 if (wszParameters
!= parametersBuffer
)
2046 HeapFree(GetProcessHeap(), 0, wszParameters
);
2047 if (wszDir
!= dirBuffer
)
2048 HeapFree(GetProcessHeap(), 0, wszDir
);
2049 if (wcmd
!= wcmdBuffer
)
2050 HeapFree(GetProcessHeap(), 0, wcmd
);
2054 /* Else, try to find the executable */
2056 retval
= SHELL_FindExecutable(sei_tmp
.lpDirectory
, lpFile
, sei_tmp
.lpVerb
, wcmd
, wcmdLen
, wszKeyname
, &env
, (LPITEMIDLIST
)sei_tmp
.lpIDList
, sei_tmp
.lpParameters
);
2057 if (retval
> 32) /* Found */
2059 retval
= SHELL_quote_and_execute(wcmd
, wszParameters
, wszKeyname
,
2060 wszApplicationName
, env
, &sei_tmp
,
2062 HeapFree(GetProcessHeap(), 0, env
);
2064 else if (PathIsDirectoryW(lpFile
))
2066 WCHAR wExec
[MAX_PATH
];
2067 WCHAR
* lpQuotedFile
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * (strlenW(lpFile
) + 3));
2071 retval
= SHELL_FindExecutable(sei_tmp
.lpDirectory
, L
"explorer",
2072 wszOpen
, wExec
, MAX_PATH
,
2073 NULL
, &env
, NULL
, NULL
);
2076 swprintf(lpQuotedFile
, L
"\"%s\"", lpFile
);
2077 retval
= SHELL_quote_and_execute(wExec
, lpQuotedFile
,
2079 wszApplicationName
, env
,
2080 &sei_tmp
, sei
, execfunc
);
2081 HeapFree(GetProcessHeap(), 0, env
);
2083 HeapFree(GetProcessHeap(), 0, lpQuotedFile
);
2086 retval
= 0; /* Out of memory */
2088 else if (PathIsURLW(lpFile
)) /* File not found, check for URL */
2090 retval
= SHELL_execute_url(lpFile
, wcmd
, &sei_tmp
, sei
, execfunc
);
2092 /* Check if file specified is in the form www.??????.*** */
2093 else if (!strncmpiW(lpFile
, L
"www", 3))
2095 /* if so, prefix lpFile with http:// and call ShellExecute */
2096 WCHAR lpstrTmpFile
[256];
2097 strcpyW(lpstrTmpFile
, L
"http://");
2098 strcatW(lpstrTmpFile
, lpFile
);
2099 retval
= (UINT_PTR
)ShellExecuteW(sei_tmp
.hwnd
, sei_tmp
.lpVerb
, lpstrTmpFile
, NULL
, NULL
, 0);
2102 TRACE("retval %lu\n", retval
);
2104 if (retval
<= 32 && !(sei_tmp
.fMask
& SEE_MASK_FLAG_NO_UI
))
2111 Info
.pcszFile
= wszApplicationName
;
2112 Info
.pcszClass
= NULL
;
2113 Info
.oaifInFlags
= OAIF_ALLOW_REGISTRATION
| OAIF_EXEC
;
2115 //if (SHOpenWithDialog(sei_tmp.hwnd, &Info) != S_OK)
2116 DBG_UNREFERENCED_LOCAL_VARIABLE(Info
);
2117 do_error_dialog(retval
, sei_tmp
.hwnd
, wszApplicationName
);
2120 HeapFree(GetProcessHeap(), 0, wszApplicationName
);
2121 if (wszParameters
!= parametersBuffer
)
2122 HeapFree(GetProcessHeap(), 0, wszParameters
);
2123 if (wszDir
!= dirBuffer
)
2124 HeapFree(GetProcessHeap(), 0, wszDir
);
2125 if (wcmd
!= wcmdBuffer
)
2126 HeapFree(GetProcessHeap(), 0, wcmd
);
2128 sei
->hInstApp
= (HINSTANCE
)(retval
> 32 ? 33 : retval
);
2133 /*************************************************************************
2134 * ShellExecuteA [SHELL32.290]
2136 HINSTANCE WINAPI
ShellExecuteA(HWND hWnd
, LPCSTR lpVerb
, LPCSTR lpFile
,
2137 LPCSTR lpParameters
, LPCSTR lpDirectory
, INT iShowCmd
)
2139 SHELLEXECUTEINFOA sei
;
2141 TRACE("%p,%s,%s,%s,%s,%d\n",
2142 hWnd
, debugstr_a(lpVerb
), debugstr_a(lpFile
),
2143 debugstr_a(lpParameters
), debugstr_a(lpDirectory
), iShowCmd
);
2145 sei
.cbSize
= sizeof(sei
);
2146 sei
.fMask
= SEE_MASK_FLAG_NO_UI
;
2148 sei
.lpVerb
= lpVerb
;
2149 sei
.lpFile
= lpFile
;
2150 sei
.lpParameters
= lpParameters
;
2151 sei
.lpDirectory
= lpDirectory
;
2152 sei
.nShow
= iShowCmd
;
2159 ShellExecuteExA(&sei
);
2160 return sei
.hInstApp
;
2163 /*************************************************************************
2164 * ShellExecuteExA [SHELL32.292]
2170 ShellExecuteExA(LPSHELLEXECUTEINFOA sei
)
2172 SHELLEXECUTEINFOW seiW
;
2174 WCHAR
*wVerb
= NULL
, *wFile
= NULL
, *wParameters
= NULL
, *wDirectory
= NULL
, *wClass
= NULL
;
2178 memcpy(&seiW
, sei
, sizeof(SHELLEXECUTEINFOW
));
2181 seiW
.lpVerb
= __SHCloneStrAtoW(&wVerb
, sei
->lpVerb
);
2184 seiW
.lpFile
= __SHCloneStrAtoW(&wFile
, sei
->lpFile
);
2186 if (sei
->lpParameters
)
2187 seiW
.lpParameters
= __SHCloneStrAtoW(&wParameters
, sei
->lpParameters
);
2189 if (sei
->lpDirectory
)
2190 seiW
.lpDirectory
= __SHCloneStrAtoW(&wDirectory
, sei
->lpDirectory
);
2192 if ((sei
->fMask
& SEE_MASK_CLASSALL
) == SEE_MASK_CLASSNAME
&& sei
->lpClass
)
2193 seiW
.lpClass
= __SHCloneStrAtoW(&wClass
, sei
->lpClass
);
2195 seiW
.lpClass
= NULL
;
2197 ret
= SHELL_execute(&seiW
, SHELL_ExecuteW
);
2199 sei
->hInstApp
= seiW
.hInstApp
;
2201 if (sei
->fMask
& SEE_MASK_NOCLOSEPROCESS
)
2202 sei
->hProcess
= seiW
.hProcess
;
2206 SHFree(wParameters
);
2213 /*************************************************************************
2214 * ShellExecuteExW [SHELL32.293]
2220 ShellExecuteExW(LPSHELLEXECUTEINFOW sei
)
2222 return SHELL_execute(sei
, SHELL_ExecuteW
);
2225 /*************************************************************************
2226 * ShellExecuteW [SHELL32.294]
2228 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpVerb,
2229 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
2231 HINSTANCE WINAPI
ShellExecuteW(HWND hwnd
, LPCWSTR lpVerb
, LPCWSTR lpFile
,
2232 LPCWSTR lpParameters
, LPCWSTR lpDirectory
, INT nShowCmd
)
2234 SHELLEXECUTEINFOW sei
;
2237 sei
.cbSize
= sizeof(sei
);
2238 sei
.fMask
= SEE_MASK_FLAG_NO_UI
;
2240 sei
.lpVerb
= lpVerb
;
2241 sei
.lpFile
= lpFile
;
2242 sei
.lpParameters
= lpParameters
;
2243 sei
.lpDirectory
= lpDirectory
;
2244 sei
.nShow
= nShowCmd
;
2251 SHELL_execute(&sei
, SHELL_ExecuteW
);
2252 return sei
.hInstApp
;
2255 /*************************************************************************
2256 * WOWShellExecute [SHELL32.@]
2258 * FIXME: the callback function most likely doesn't work the same way on Windows.
2260 EXTERN_C HINSTANCE WINAPI
WOWShellExecute(HWND hWnd
, LPCSTR lpVerb
, LPCSTR lpFile
,
2261 LPCSTR lpParameters
, LPCSTR lpDirectory
, INT iShowCmd
, void *callback
)
2263 SHELLEXECUTEINFOW seiW
;
2264 WCHAR
*wVerb
= NULL
, *wFile
= NULL
, *wParameters
= NULL
, *wDirectory
= NULL
;
2265 HANDLE hProcess
= 0;
2267 seiW
.lpVerb
= lpVerb
? __SHCloneStrAtoW(&wVerb
, lpVerb
) : NULL
;
2268 seiW
.lpFile
= lpFile
? __SHCloneStrAtoW(&wFile
, lpFile
) : NULL
;
2269 seiW
.lpParameters
= lpParameters
? __SHCloneStrAtoW(&wParameters
, lpParameters
) : NULL
;
2270 seiW
.lpDirectory
= lpDirectory
? __SHCloneStrAtoW(&wDirectory
, lpDirectory
) : NULL
;
2272 seiW
.cbSize
= sizeof(seiW
);
2275 seiW
.nShow
= iShowCmd
;
2280 seiW
.hProcess
= hProcess
;
2282 SHELL_execute(&seiW
, (SHELL_ExecuteW32
)callback
);
2286 SHFree(wParameters
);
2288 return seiW
.hInstApp
;
2291 /*************************************************************************
2292 * OpenAs_RunDLLW [SHELL32.@]
2294 EXTERN_C
void WINAPI
2295 OpenAs_RunDLLW(HWND hwnd
, HINSTANCE hinst
, LPCWSTR cmdline
, int cmdshow
)
2298 TRACE("%p, %p, %s, %d\n", hwnd
, hinst
, debugstr_w(cmdline
), cmdshow
);
2300 ZeroMemory(&info
, sizeof(info
));
2301 info
.pcszFile
= cmdline
;
2302 info
.pcszClass
= NULL
;
2303 info
.oaifInFlags
= OAIF_ALLOW_REGISTRATION
| OAIF_REGISTER_EXT
| OAIF_EXEC
;
2305 SHOpenWithDialog(hwnd
, &info
);
2308 /*************************************************************************
2309 * OpenAs_RunDLLA [SHELL32.@]
2311 EXTERN_C
void WINAPI
2312 OpenAs_RunDLLA(HWND hwnd
, HINSTANCE hinst
, LPCSTR cmdline
, int cmdshow
)
2314 LPWSTR pszCmdLineW
= NULL
;
2315 TRACE("%p, %p, %s, %d\n", hwnd
, hinst
, debugstr_a(cmdline
), cmdshow
);
2317 __SHCloneStrAtoW(&pszCmdLineW
, cmdline
);
2318 OpenAs_RunDLLW(hwnd
, hinst
, pszCmdLineW
, cmdshow
);
2319 SHFree(pszCmdLineW
);