2011-05-15 15:55:49 +00:00
|
|
|
/*
|
2011-09-03 15:37:09 +00:00
|
|
|
* Shell Library Functions
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 2002 Eric Pouech
|
2019-11-14 14:25:21 +00:00
|
|
|
* Copyright 2018-2019 Katayama Hirofumi MZ
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2018-08-05 11:39:17 +00:00
|
|
|
#include <undocshell.h>
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(exec);
|
|
|
|
|
2022-02-15 23:54:20 +00:00
|
|
|
EXTERN_C BOOL PathIsExeW(LPCWSTR lpszPath);
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
#define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
typedef UINT_PTR (*SHELL_ExecuteW32)(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
|
|
|
|
const SHELLEXECUTEINFOW *sei, LPSHELLEXECUTEINFOW sei_out);
|
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
static void ParseNoTildeEffect(PWSTR &res, LPCWSTR &args, DWORD &len, DWORD &used, int argNum)
|
|
|
|
{
|
|
|
|
bool firstCharQuote = false;
|
|
|
|
bool quotes_opened = false;
|
|
|
|
bool backslash_encountered = false;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
for (int curArg = 0; curArg <= argNum && *args; ++curArg)
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
|
|
|
firstCharQuote = false;
|
|
|
|
if (*args == '"')
|
|
|
|
{
|
|
|
|
quotes_opened = true;
|
|
|
|
firstCharQuote = true;
|
|
|
|
args++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*args)
|
|
|
|
{
|
|
|
|
if (*args == '\\')
|
|
|
|
{
|
|
|
|
// if we found a backslash then flip the variable
|
|
|
|
backslash_encountered = !backslash_encountered;
|
|
|
|
}
|
|
|
|
else if (*args == '"')
|
|
|
|
{
|
|
|
|
if (quotes_opened)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
if (*(args + 1) != '"')
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
|
|
|
quotes_opened = false;
|
|
|
|
args++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
args++;
|
2011-09-02 19:29:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quotes_opened = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
backslash_encountered = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
backslash_encountered = false;
|
|
|
|
if (*args == ' ' && !firstCharQuote)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curArg == argNum)
|
|
|
|
{
|
|
|
|
used++;
|
|
|
|
if (used < len)
|
|
|
|
*res++ = *args;
|
|
|
|
}
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
args++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*args == ' ')
|
|
|
|
++args;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ParseTildeEffect(PWSTR &res, LPCWSTR &args, DWORD &len, DWORD &used, int argNum)
|
|
|
|
{
|
|
|
|
bool quotes_opened = false;
|
|
|
|
bool backslash_encountered = false;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
for (int curArg = 0; curArg <= argNum && *args; ++curArg)
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
|
|
|
while(*args)
|
|
|
|
{
|
|
|
|
if (*args == '\\')
|
|
|
|
{
|
|
|
|
// if we found a backslash then flip the variable
|
|
|
|
backslash_encountered = !backslash_encountered;
|
|
|
|
}
|
|
|
|
else if (*args == '"')
|
|
|
|
{
|
|
|
|
if (quotes_opened)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
if (*(args + 1) != '"')
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
|
|
|
quotes_opened = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
args++;
|
2011-09-02 19:29:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
quotes_opened = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
backslash_encountered = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
backslash_encountered = false;
|
2012-01-05 18:34:35 +00:00
|
|
|
if (*args == ' ' && !quotes_opened && curArg != argNum)
|
2011-09-02 19:29:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curArg == argNum)
|
|
|
|
{
|
|
|
|
used++;
|
|
|
|
if (used < len)
|
|
|
|
*res++ = *args;
|
|
|
|
}
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
args++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* SHELL_ArgifyW [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* this function is supposed to expand the escape sequences found in the registry
|
|
|
|
* some diving reported that the following were used:
|
|
|
|
* + %1, %2... seem to report to parameter of index N in ShellExecute pmts
|
2011-09-03 15:37:09 +00:00
|
|
|
* %1 file
|
|
|
|
* %2 printer
|
|
|
|
* %3 driver
|
|
|
|
* %4 port
|
2011-05-15 15:55:49 +00:00
|
|
|
* %I address of a global item ID (explorer switch /idlist)
|
|
|
|
* %L seems to be %1 as long filename followed by the 8+3 variation
|
|
|
|
* %S ???
|
2019-11-14 14:25:21 +00:00
|
|
|
* %W Working directory
|
|
|
|
* %V Use either %L or %W
|
2011-05-15 15:55:49 +00:00
|
|
|
* %* all following parameters (see batfile)
|
|
|
|
*
|
2011-09-03 15:37:09 +00:00
|
|
|
* The way we parse the command line arguments was determined through extensive
|
|
|
|
* testing and can be summed up by the following rules"
|
|
|
|
*
|
|
|
|
* - %2
|
|
|
|
* - if first letter is " break on first non literal " and include any white spaces
|
|
|
|
* - if first letter is NOT " break on first " or white space
|
|
|
|
* - if " is opened any pair of consecutive " results in ONE literal "
|
|
|
|
*
|
|
|
|
* - %~2
|
|
|
|
* - use rules from here http://www.autohotkey.net/~deleyd/parameters/parameters.htm
|
|
|
|
*/
|
2011-09-02 19:29:30 +00:00
|
|
|
|
2018-07-12 15:45:43 +00:00
|
|
|
static BOOL SHELL_ArgifyW(WCHAR* out, DWORD len, const WCHAR* fmt, const WCHAR* lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD* out_len, const WCHAR* lpDir)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WCHAR xlpFile[1024];
|
|
|
|
BOOL done = FALSE;
|
|
|
|
BOOL found_p1 = FALSE;
|
|
|
|
PWSTR res = out;
|
|
|
|
PCWSTR cmd;
|
|
|
|
DWORD used = 0;
|
2011-09-02 19:29:30 +00:00
|
|
|
bool tildeEffect = false;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-02 19:56:58 +00:00
|
|
|
TRACE("Before parsing: %p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
|
2011-05-15 15:55:49 +00:00
|
|
|
debugstr_w(lpFile), pidl, args);
|
|
|
|
|
|
|
|
while (*fmt)
|
|
|
|
{
|
|
|
|
if (*fmt == '%')
|
|
|
|
{
|
|
|
|
switch (*++fmt)
|
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
case '\0':
|
|
|
|
case '%':
|
|
|
|
{
|
|
|
|
used++;
|
|
|
|
if (used < len)
|
|
|
|
*res++ = '%';
|
2012-01-05 18:34:35 +00:00
|
|
|
};
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
case '*':
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
if (args)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
if (*fmt == '*')
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
used++;
|
2011-09-02 19:29:30 +00:00
|
|
|
while(*args)
|
|
|
|
{
|
|
|
|
used++;
|
|
|
|
if (used < len)
|
|
|
|
*res++ = *args++;
|
|
|
|
else
|
|
|
|
args++;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
used++;
|
2011-09-02 19:29:30 +00:00
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-05 18:34:35 +00:00
|
|
|
};
|
|
|
|
break;
|
2011-09-02 19:29:30 +00:00
|
|
|
|
|
|
|
case '~':
|
|
|
|
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
2012-01-05 18:34:35 +00:00
|
|
|
//case '0':
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
if (*fmt == '~')
|
|
|
|
{
|
|
|
|
fmt++;
|
|
|
|
tildeEffect = true;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
if (args)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
if (tildeEffect)
|
|
|
|
{
|
|
|
|
ParseTildeEffect(res, args, len, used, *fmt - '2');
|
|
|
|
tildeEffect = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ParseNoTildeEffect(res, args, len, used, *fmt - '2');
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2012-01-05 18:34:35 +00:00
|
|
|
};
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
case '1':
|
|
|
|
if (!done || (*fmt == '1'))
|
|
|
|
{
|
|
|
|
/*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
|
2022-01-09 21:38:31 +00:00
|
|
|
if (SearchPathW(lpDir, lpFile, L".exe", ARRAY_SIZE(xlpFile), xlpFile, NULL))
|
2011-09-02 19:29:30 +00:00
|
|
|
cmd = xlpFile;
|
|
|
|
else
|
|
|
|
cmd = lpFile;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
used += wcslen(cmd);
|
|
|
|
if (used < len)
|
|
|
|
{
|
|
|
|
wcscpy(res, cmd);
|
|
|
|
res += wcslen(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found_p1 = TRUE;
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
/*
|
|
|
|
* IE uses this a lot for activating things such as windows media
|
|
|
|
* player. This is not verified to be fully correct but it appears
|
|
|
|
* to work just fine.
|
|
|
|
*/
|
2011-09-02 19:29:30 +00:00
|
|
|
case 'l':
|
|
|
|
case 'L':
|
2011-09-03 15:37:09 +00:00
|
|
|
if (lpFile)
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
used += wcslen(lpFile);
|
|
|
|
if (used < len)
|
|
|
|
{
|
|
|
|
wcscpy(res, lpFile);
|
|
|
|
res += wcslen(lpFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found_p1 = TRUE;
|
2011-09-02 19:29:30 +00:00
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2019-11-14 14:25:21 +00:00
|
|
|
case 'w':
|
|
|
|
case 'W':
|
|
|
|
if (lpDir)
|
|
|
|
{
|
|
|
|
used += wcslen(lpDir);
|
|
|
|
if (used < len)
|
|
|
|
{
|
|
|
|
wcscpy(res, lpDir);
|
|
|
|
res += wcslen(lpDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
case 'V':
|
|
|
|
if (lpFile)
|
|
|
|
{
|
|
|
|
used += wcslen(lpFile);
|
|
|
|
if (used < len)
|
|
|
|
{
|
|
|
|
wcscpy(res, lpFile);
|
|
|
|
res += wcslen(lpFile);
|
|
|
|
}
|
|
|
|
found_p1 = TRUE;
|
|
|
|
}
|
|
|
|
else if (lpDir)
|
|
|
|
{
|
|
|
|
used += wcslen(lpDir);
|
|
|
|
if (used < len)
|
|
|
|
{
|
|
|
|
wcscpy(res, lpDir);
|
|
|
|
res += wcslen(lpDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
case 'i':
|
|
|
|
case 'I':
|
2011-09-03 15:37:09 +00:00
|
|
|
if (pidl)
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
DWORD chars = 0;
|
|
|
|
/* %p should not exceed 8, maybe 16 when looking forward to 64bit.
|
|
|
|
* allowing a buffer of 100 should more than exceed all needs */
|
|
|
|
WCHAR buf[100];
|
|
|
|
LPVOID pv;
|
|
|
|
HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
|
|
|
|
pv = SHLockShared(hmem, 0);
|
2012-01-05 18:34:35 +00:00
|
|
|
chars = swprintf(buf, L":%p", pv);
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2022-01-09 21:38:31 +00:00
|
|
|
if (chars >= ARRAY_SIZE(buf))
|
2011-09-03 15:37:09 +00:00
|
|
|
ERR("pidl format buffer too small!\n");
|
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
used += chars;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
if (used < len)
|
2011-09-03 15:37:09 +00:00
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
wcscpy(res, buf);
|
2011-09-03 15:37:09 +00:00
|
|
|
res += chars;
|
|
|
|
}
|
|
|
|
SHUnlockShared(pv);
|
|
|
|
}
|
2011-09-02 19:29:30 +00:00
|
|
|
found_p1 = TRUE;
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
default:
|
2011-09-02 19:29:30 +00:00
|
|
|
/*
|
|
|
|
* Check if this is an env-variable here...
|
|
|
|
*/
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
/* Make sure that we have at least one more %.*/
|
|
|
|
if (strchrW(fmt, '%'))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
WCHAR tmpBuffer[1024];
|
|
|
|
PWSTR tmpB = tmpBuffer;
|
|
|
|
WCHAR tmpEnvBuff[MAX_PATH];
|
|
|
|
DWORD envRet;
|
|
|
|
|
|
|
|
while (*fmt != '%')
|
|
|
|
*tmpB++ = *fmt++;
|
|
|
|
*tmpB++ = 0;
|
|
|
|
|
|
|
|
TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer));
|
|
|
|
|
|
|
|
envRet = GetEnvironmentVariableW(tmpBuffer, tmpEnvBuff, MAX_PATH);
|
|
|
|
if (envRet == 0 || envRet > MAX_PATH)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
used += wcslen(tmpBuffer);
|
|
|
|
if (used < len)
|
|
|
|
{
|
|
|
|
wcscpy( res, tmpBuffer );
|
|
|
|
res += wcslen(tmpBuffer);
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2011-09-02 19:29:30 +00:00
|
|
|
else
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2011-09-02 19:29:30 +00:00
|
|
|
used += wcslen(tmpEnvBuff);
|
|
|
|
if (used < len)
|
|
|
|
{
|
|
|
|
wcscpy( res, tmpEnvBuff );
|
|
|
|
res += wcslen(tmpEnvBuff);
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-02 19:29:30 +00:00
|
|
|
done = TRUE;
|
|
|
|
break;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
/* Don't skip past terminator (catch a single '%' at the end) */
|
|
|
|
if (*fmt != '\0')
|
|
|
|
{
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
used ++;
|
|
|
|
if (used < len)
|
|
|
|
*res++ = *fmt++;
|
|
|
|
else
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
used++;
|
|
|
|
if (res - out < static_cast<int>(len))
|
|
|
|
*res = '\0';
|
|
|
|
else
|
|
|
|
out[len-1] = '\0';
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("used %i of %i space\n", used, len);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (out_len)
|
|
|
|
*out_len = used;
|
|
|
|
|
2011-09-02 19:56:58 +00:00
|
|
|
TRACE("After parsing: %p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
|
|
|
|
debugstr_w(lpFile), pidl, args);
|
2011-09-02 19:29:30 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
return found_p1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
|
|
|
|
{
|
|
|
|
STRRET strret;
|
2014-08-20 00:39:40 +00:00
|
|
|
CComPtr<IShellFolder> desktop;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
HRESULT hr = SHGetDesktopFolder(&desktop);
|
|
|
|
|
2011-09-02 19:29:30 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
hr = desktop->GetDisplayNameOf(pidl, SHGDN_FORPARSING, &strret);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* SHELL_ExecuteW [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
|
2012-01-05 18:34:35 +00:00
|
|
|
const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
STARTUPINFOW startup;
|
|
|
|
PROCESS_INFORMATION info;
|
|
|
|
UINT_PTR retval = SE_ERR_NOASSOC;
|
|
|
|
UINT gcdret = 0;
|
|
|
|
WCHAR curdir[MAX_PATH];
|
|
|
|
DWORD dwCreationFlags;
|
|
|
|
const WCHAR *lpDirectory = NULL;
|
|
|
|
|
|
|
|
TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
|
|
|
|
|
|
|
|
/* make sure we don't fail the CreateProcess if the calling app passes in
|
|
|
|
* a bad working directory */
|
|
|
|
if (psei->lpDirectory && psei->lpDirectory[0])
|
|
|
|
{
|
|
|
|
DWORD attr = GetFileAttributesW(psei->lpDirectory);
|
|
|
|
if (attr != INVALID_FILE_ATTRIBUTES && attr & FILE_ATTRIBUTE_DIRECTORY)
|
|
|
|
lpDirectory = psei->lpDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ShellExecute specifies the command from psei->lpDirectory
|
|
|
|
* if present. Not from the current dir as CreateProcess does */
|
2012-01-05 18:34:35 +00:00
|
|
|
if (lpDirectory)
|
|
|
|
if ((gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
|
|
|
|
if (!SetCurrentDirectoryW( lpDirectory))
|
2011-05-15 15:55:49 +00:00
|
|
|
ERR("cannot set directory %s\n", debugstr_w(lpDirectory));
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
ZeroMemory(&startup, sizeof(STARTUPINFOW));
|
2011-05-15 15:55:49 +00:00
|
|
|
startup.cb = sizeof(STARTUPINFOW);
|
|
|
|
startup.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
startup.wShowWindow = psei->nShow;
|
2014-05-12 19:55:25 +00:00
|
|
|
dwCreationFlags = CREATE_UNICODE_ENVIRONMENT;
|
2014-05-24 16:39:55 +00:00
|
|
|
if (!(psei->fMask & SEE_MASK_NO_CONSOLE))
|
2014-05-31 16:58:03 +00:00
|
|
|
dwCreationFlags |= CREATE_NEW_CONSOLE;
|
[SHELL32]
Implement the usage of the STARTF_TITLEISLINKNAME flag (in a STARTUPINFO structure, it signals that the program was started from a shell link, and therefore its lpTitle member holds the path of the link).
What I do is that, in CShellLink::InvokeCommand (called when a shortcut is being executed), I initialize the SHELLEXECUTEINFO structure such that we know that we are starting from a shortcut (use the
SEE_MASK_HASLINKNAME flag), and to hold the path to the flag I use its lpClass member (which is not used for other things in this code path). Then the whole thing is passed to ShellExecuteExW which, in turn,
calls the SHELL_ExecuteW function. This function reads the SHELLEXECUTEINFO structure and, if it has the flag SEE_MASK_HASLINKNAME (or SEE_MASK_HASTITLE too, if somebody also uses lpClass to pass a particular
title for the startup), we use the forementioned lpClass member, holding the link path, as the title (lpTitle member) of a new STARTUPINFO object used when calling CreateProcess (and thus, launching the
new application). So that this application will be aware that she was launched via a link (therefore we become compliant with the STARTF_TITLEISLINKNAME documentation).
svn path=/branches/ros-csrss/; revision=58480
2013-03-13 01:35:46 +00:00
|
|
|
startup.lpTitle = (LPWSTR)(psei->fMask & (SEE_MASK_HASLINKNAME | SEE_MASK_HASTITLE) ? psei->lpClass : NULL);
|
|
|
|
|
|
|
|
if (psei->fMask & SEE_MASK_HASLINKNAME)
|
|
|
|
startup.dwFlags |= STARTF_TITLEISLINKNAME;
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env,
|
|
|
|
lpDirectory, &startup, &info))
|
|
|
|
{
|
|
|
|
/* Give 30 seconds to the app to come up, if desired. Probably only needed
|
|
|
|
when starting app immediately before making a DDE connection. */
|
|
|
|
if (shWait)
|
2012-01-05 18:34:35 +00:00
|
|
|
if (WaitForInputIdle(info.hProcess, 30000) == WAIT_FAILED)
|
2011-05-15 15:55:49 +00:00
|
|
|
WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
|
|
|
|
retval = 33;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
|
|
|
|
psei_out->hProcess = info.hProcess;
|
|
|
|
else
|
|
|
|
CloseHandle( info.hProcess );
|
|
|
|
CloseHandle( info.hThread );
|
|
|
|
}
|
|
|
|
else if ((retval = GetLastError()) >= 32)
|
|
|
|
{
|
2011-11-20 22:22:42 +00:00
|
|
|
WARN("CreateProcess returned error %ld\n", retval);
|
2011-05-15 15:55:49 +00:00
|
|
|
retval = ERROR_BAD_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("returning %lu\n", retval);
|
|
|
|
|
|
|
|
psei_out->hInstApp = (HINSTANCE)retval;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
if (gcdret)
|
|
|
|
if (!SetCurrentDirectoryW(curdir))
|
2011-05-15 15:55:49 +00:00
|
|
|
ERR("cannot return to directory %s\n", debugstr_w(curdir));
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* SHELL_BuildEnvW [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Build the environment for the new process, adding the specified
|
|
|
|
* path to the PATH variable. Returned pointer must be freed by caller.
|
|
|
|
*/
|
|
|
|
static LPWSTR SHELL_BuildEnvW( const WCHAR *path )
|
|
|
|
{
|
|
|
|
WCHAR *strings, *new_env;
|
|
|
|
WCHAR *p, *p2;
|
|
|
|
int total = wcslen(path) + 1;
|
|
|
|
BOOL got_path = FALSE;
|
|
|
|
|
|
|
|
if (!(strings = GetEnvironmentStringsW())) return NULL;
|
|
|
|
p = strings;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
int len = wcslen(p) + 1;
|
2022-01-09 21:38:31 +00:00
|
|
|
if (!_wcsnicmp( p, L"PATH=", 5 )) got_path = TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
total += len;
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
if (!got_path) total += 5; /* we need to create PATH */
|
|
|
|
total++; /* terminating null */
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
if (!(new_env = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, total * sizeof(WCHAR))))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
FreeEnvironmentStringsW(strings);
|
2011-05-15 15:55:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
p = strings;
|
|
|
|
p2 = new_env;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
int len = wcslen(p) + 1;
|
2012-01-05 18:34:35 +00:00
|
|
|
memcpy(p2, p, len * sizeof(WCHAR));
|
2022-01-09 21:38:31 +00:00
|
|
|
if (!_wcsnicmp( p, L"PATH=", 5 ))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
p2[len - 1] = ';';
|
|
|
|
wcscpy( p2 + len, path );
|
|
|
|
p2 += wcslen(path) + 1;
|
|
|
|
}
|
|
|
|
p += len;
|
|
|
|
p2 += len;
|
|
|
|
}
|
|
|
|
if (!got_path)
|
|
|
|
{
|
2022-01-09 21:38:31 +00:00
|
|
|
wcscpy(p2, L"PATH=");
|
2012-01-05 18:34:35 +00:00
|
|
|
wcscat(p2, path);
|
2011-05-15 15:55:49 +00:00
|
|
|
p2 += wcslen(p2) + 1;
|
|
|
|
}
|
|
|
|
*p2 = 0;
|
2012-01-05 18:34:35 +00:00
|
|
|
FreeEnvironmentStringsW(strings);
|
2011-05-15 15:55:49 +00:00
|
|
|
return new_env;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* SHELL_TryAppPathW [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Helper function for SHELL_FindExecutable
|
|
|
|
* @param lpResult - pointer to a buffer of size MAX_PATH
|
|
|
|
* On entry: szName is a filename (probably without path separators).
|
|
|
|
* On exit: if szName found in "App Path", place full path in lpResult, and return true
|
|
|
|
*/
|
|
|
|
static BOOL SHELL_TryAppPathW( LPCWSTR szName, LPWSTR lpResult, WCHAR **env)
|
|
|
|
{
|
2022-11-08 00:23:06 +00:00
|
|
|
HKEY hkApp = NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
WCHAR buffer[1024];
|
2022-11-08 00:23:06 +00:00
|
|
|
DWORD len, dwType;
|
2011-05-15 15:55:49 +00:00
|
|
|
LONG res;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
if (env) *env = NULL;
|
2012-01-05 18:34:35 +00:00
|
|
|
wcscpy(buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
|
2011-05-15 15:55:49 +00:00
|
|
|
wcscat(buffer, szName);
|
|
|
|
res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
|
2021-09-13 01:33:14 +00:00
|
|
|
if (res)
|
2016-11-09 22:18:33 +00:00
|
|
|
{
|
|
|
|
// Add ".exe" extension, if extension does not exists
|
2022-01-09 21:38:31 +00:00
|
|
|
if (PathAddExtensionW(buffer, L".exe"))
|
2016-11-09 22:18:33 +00:00
|
|
|
{
|
|
|
|
res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, buffer, 0, KEY_READ, &hkApp);
|
2021-09-13 01:33:14 +00:00
|
|
|
}
|
2016-11-09 22:18:33 +00:00
|
|
|
if (res) goto end;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
len = MAX_PATH * sizeof(WCHAR);
|
2022-11-08 00:23:06 +00:00
|
|
|
res = SHRegQueryValueExW(hkApp, NULL, NULL, &dwType, (LPBYTE)lpResult, &len);
|
|
|
|
if (res != ERROR_SUCCESS || dwType != REG_SZ)
|
|
|
|
goto end;
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
found = TRUE;
|
|
|
|
|
|
|
|
if (env)
|
|
|
|
{
|
2022-11-08 00:23:06 +00:00
|
|
|
len = sizeof(buffer);
|
|
|
|
res = SHRegQueryValueExW(hkApp, L"Path", NULL, &dwType, (LPBYTE)buffer, &len);
|
|
|
|
if (res == ERROR_SUCCESS && dwType == REG_SZ && buffer[0])
|
2012-01-05 18:34:35 +00:00
|
|
|
*env = SHELL_BuildEnvW(buffer);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (hkApp) RegCloseKey(hkApp);
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* SHELL_FindExecutableByVerb [Internal]
|
|
|
|
*
|
|
|
|
* called from SHELL_FindExecutable or SHELL_execute_class
|
|
|
|
* in/out:
|
|
|
|
* classname a buffer, big enough, to get the key name to do actually the
|
|
|
|
* command "WordPad.Document.1\\shell\\open\\command"
|
|
|
|
* passed as "WordPad.Document.1"
|
|
|
|
* in:
|
|
|
|
* lpVerb the operation on it (open)
|
|
|
|
* commandlen the size of command buffer (in bytes)
|
|
|
|
* out:
|
|
|
|
* command a buffer, to store the command to do the
|
|
|
|
* operation on the file
|
|
|
|
* key a buffer, big enough, to get the key name to do actually the
|
|
|
|
* command "WordPad.Document.1\\shell\\open\\command"
|
|
|
|
* Can be NULL
|
|
|
|
*/
|
|
|
|
static UINT SHELL_FindExecutableByVerb(LPCWSTR lpVerb, LPWSTR key, LPWSTR classname, LPWSTR command, LONG commandlen)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
HKEY hkeyClass;
|
|
|
|
WCHAR verb[MAX_PATH];
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, classname, 0, 0x02000000, &hkeyClass))
|
2011-05-15 15:55:49 +00:00
|
|
|
return SE_ERR_NOASSOC;
|
2022-01-09 21:38:31 +00:00
|
|
|
if (!HCR_GetDefaultVerbW(hkeyClass, lpVerb, verb, ARRAY_SIZE(verb)))
|
2011-05-15 15:55:49 +00:00
|
|
|
return SE_ERR_NOASSOC;
|
|
|
|
RegCloseKey(hkeyClass);
|
|
|
|
|
|
|
|
/* Looking for ...buffer\shell\<verb>\command */
|
2014-05-22 18:53:44 +00:00
|
|
|
wcscat(classname, L"\\shell\\");
|
|
|
|
wcscat(classname, verb);
|
2022-01-09 21:38:31 +00:00
|
|
|
wcscat(classname, L"\\command");
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, classname, command,
|
2011-05-15 15:55:49 +00:00
|
|
|
&commandlen) == ERROR_SUCCESS)
|
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
commandlen /= sizeof(WCHAR);
|
2014-05-22 18:53:44 +00:00
|
|
|
if (key) wcscpy(key, classname);
|
2011-05-15 15:55:49 +00:00
|
|
|
#if 0
|
|
|
|
LPWSTR tmp;
|
|
|
|
WCHAR param[256];
|
2011-09-03 15:37:09 +00:00
|
|
|
LONG paramlen = sizeof(param);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/* FIXME: it seems all Windows version don't behave the same here.
|
|
|
|
* the doc states that this ddeexec information can be found after
|
|
|
|
* the exec names.
|
|
|
|
* on Win98, it doesn't appear, but I think it does on Win2k
|
|
|
|
*/
|
2011-09-03 15:37:09 +00:00
|
|
|
/* Get the parameters needed by the application
|
|
|
|
from the associated ddeexec key */
|
2022-01-09 21:38:31 +00:00
|
|
|
tmp = strstrW(classname, L"\\command");
|
2011-09-03 15:37:09 +00:00
|
|
|
tmp[0] = '\0';
|
2014-05-22 18:53:44 +00:00
|
|
|
wcscat(classname, wDdeexec);
|
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, classname, param,
|
2011-09-03 15:37:09 +00:00
|
|
|
¶mlen) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
paramlen /= sizeof(WCHAR);
|
2022-01-09 21:38:31 +00:00
|
|
|
wcscat(command, L" ");
|
2011-05-15 15:55:49 +00:00
|
|
|
wcscat(command, param);
|
|
|
|
commandlen += paramlen;
|
2011-09-03 15:37:09 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
command[commandlen] = '\0';
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
return 33; /* FIXME see SHELL_FindExecutable() */
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SE_ERR_NOASSOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* SHELL_FindExecutable [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Utility for code sharing between FindExecutable and ShellExecute
|
|
|
|
* in:
|
|
|
|
* lpFile the name of a file
|
2014-05-22 18:53:44 +00:00
|
|
|
* lpVerb the operation on it (open)
|
2011-05-15 15:55:49 +00:00
|
|
|
* out:
|
|
|
|
* lpResult a buffer, big enough :-(, to store the command to do the
|
|
|
|
* operation on the file
|
|
|
|
* key a buffer, big enough, to get the key name to do actually the
|
|
|
|
* command (it'll be used afterwards for more information
|
|
|
|
* on the operation)
|
|
|
|
*/
|
2014-05-22 18:53:44 +00:00
|
|
|
static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb,
|
2012-01-05 18:34:35 +00:00
|
|
|
LPWSTR lpResult, DWORD resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WCHAR *extension = NULL; /* pointer to file extension */
|
2014-05-22 18:53:44 +00:00
|
|
|
WCHAR classname[256]; /* registry name for this file type */
|
|
|
|
LONG classnamelen = sizeof(classname); /* length of above */
|
2011-05-15 15:55:49 +00:00
|
|
|
WCHAR command[1024]; /* command from registry */
|
|
|
|
WCHAR wBuffer[256]; /* Used to GetProfileString */
|
|
|
|
UINT retval = SE_ERR_NOASSOC;
|
|
|
|
WCHAR *tok; /* token pointer */
|
|
|
|
WCHAR xlpFile[256]; /* result of SearchPath */
|
|
|
|
DWORD attribs; /* file attributes */
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(lpFile));
|
|
|
|
|
|
|
|
if (!lpResult)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
xlpFile[0] = '\0';
|
|
|
|
lpResult[0] = '\0'; /* Start off with an empty return string */
|
|
|
|
if (key) *key = '\0';
|
|
|
|
|
|
|
|
/* trap NULL parameters on entry */
|
|
|
|
if (!lpFile)
|
|
|
|
{
|
|
|
|
WARN("(lpFile=%s,lpResult=%s): NULL parameter\n",
|
|
|
|
debugstr_w(lpFile), debugstr_w(lpResult));
|
|
|
|
return ERROR_FILE_NOT_FOUND; /* File not found. Close enough, I guess. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SHELL_TryAppPathW( lpFile, lpResult, env ))
|
|
|
|
{
|
|
|
|
TRACE("found %s via App Paths\n", debugstr_w(lpResult));
|
|
|
|
return 33;
|
|
|
|
}
|
|
|
|
|
2022-01-09 21:38:31 +00:00
|
|
|
if (SearchPathW(lpPath, lpFile, L".exe", ARRAY_SIZE(xlpFile), xlpFile, NULL))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
TRACE("SearchPathW returned non-zero\n");
|
|
|
|
lpFile = xlpFile;
|
2014-05-22 18:53:44 +00:00
|
|
|
/* The file was found in the application-supplied default directory (or the system search path) */
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2022-01-09 21:38:31 +00:00
|
|
|
else if (lpPath && SearchPathW(NULL, lpFile, L".exe", ARRAY_SIZE(xlpFile), xlpFile, NULL))
|
2014-05-12 19:55:25 +00:00
|
|
|
{
|
|
|
|
TRACE("SearchPathW returned non-zero\n");
|
|
|
|
lpFile = xlpFile;
|
|
|
|
/* The file was found in one of the directories in the system-wide search path */
|
|
|
|
}
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
attribs = GetFileAttributesW(lpFile);
|
2012-01-05 18:34:35 +00:00
|
|
|
if (attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
wcscpy(classname, L"Folder");
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Did we get something? Anything? */
|
2012-01-05 18:34:35 +00:00
|
|
|
if (xlpFile[0] == 0)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
TRACE("Returning SE_ERR_FNF\n");
|
|
|
|
return SE_ERR_FNF;
|
|
|
|
}
|
|
|
|
/* First thing we need is the file's extension */
|
|
|
|
extension = wcsrchr(xlpFile, '.'); /* Assume last "." is the one; */
|
|
|
|
/* File->Run in progman uses */
|
|
|
|
/* .\FILE.EXE :( */
|
|
|
|
TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile), debugstr_w(extension));
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
if (extension == NULL || extension[1] == 0)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WARN("Returning SE_ERR_NOASSOC\n");
|
|
|
|
return SE_ERR_NOASSOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Three places to check: */
|
|
|
|
/* 1. win.ini, [windows], programs (NB no leading '.') */
|
2014-05-22 18:53:44 +00:00
|
|
|
/* 2. Registry, HKEY_CLASS_ROOT\<classname>\shell\open\command */
|
2011-05-15 15:55:49 +00:00
|
|
|
/* 3. win.ini, [extensions], extension (NB no leading '.' */
|
|
|
|
/* All I know of the order is that registry is checked before */
|
|
|
|
/* extensions; however, it'd make sense to check the programs */
|
|
|
|
/* section first, so that's what happens here. */
|
|
|
|
|
|
|
|
/* See if it's a program - if GetProfileString fails, we skip this
|
|
|
|
* section. Actually, if GetProfileString fails, we've probably
|
|
|
|
* got a lot more to worry about than running a program... */
|
2022-01-09 21:38:31 +00:00
|
|
|
if (GetProfileStringW(L"windows", L"programs", L"exe pif bat cmd com", wBuffer, ARRAY_SIZE(wBuffer)) > 0)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
CharLowerW(wBuffer);
|
|
|
|
tok = wBuffer;
|
|
|
|
while (*tok)
|
|
|
|
{
|
|
|
|
WCHAR *p = tok;
|
|
|
|
while (*p && *p != ' ' && *p != '\t') p++;
|
|
|
|
if (*p)
|
|
|
|
{
|
|
|
|
*p++ = 0;
|
|
|
|
while (*p == ' ' || *p == '\t') p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wcsicmp(tok, &extension[1]) == 0) /* have to skip the leading "." */
|
|
|
|
{
|
|
|
|
wcscpy(lpResult, xlpFile);
|
|
|
|
/* Need to perhaps check that the file has a path
|
|
|
|
* attached */
|
|
|
|
TRACE("found %s\n", debugstr_w(lpResult));
|
|
|
|
return 33;
|
|
|
|
/* Greater than 32 to indicate success */
|
|
|
|
}
|
|
|
|
tok = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check registry */
|
2014-05-22 18:53:44 +00:00
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, extension, classname,
|
|
|
|
&classnamelen) == ERROR_SUCCESS)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
classnamelen /= sizeof(WCHAR);
|
2022-01-09 21:38:31 +00:00
|
|
|
if (classnamelen == ARRAY_SIZE(classname))
|
2014-05-22 18:53:44 +00:00
|
|
|
classnamelen--;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
classname[classnamelen] = '\0';
|
|
|
|
TRACE("File type: %s\n", debugstr_w(classname));
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
*classname = '\0';
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
if (*classname)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
/* pass the verb string to SHELL_FindExecutableByVerb() */
|
|
|
|
retval = SHELL_FindExecutableByVerb(lpVerb, key, classname, command, sizeof(command));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
if (retval > 32)
|
|
|
|
{
|
|
|
|
DWORD finishedLen;
|
2018-07-12 15:45:43 +00:00
|
|
|
SHELL_ArgifyW(lpResult, resultLen, command, xlpFile, pidl, args, &finishedLen, lpPath);
|
2011-09-03 15:37:09 +00:00
|
|
|
if (finishedLen > resultLen)
|
|
|
|
ERR("Argify buffer not large enough.. truncated\n");
|
|
|
|
/* Remove double quotation marks and command line arguments */
|
|
|
|
if (*lpResult == '"')
|
|
|
|
{
|
|
|
|
WCHAR *p = lpResult;
|
|
|
|
while (*(p + 1) != '"')
|
|
|
|
{
|
|
|
|
*p = *(p + 1);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Truncate on first space */
|
2011-09-03 15:37:09 +00:00
|
|
|
WCHAR *p = lpResult;
|
|
|
|
while (*p != ' ' && *p != '\0')
|
2011-05-15 15:55:49 +00:00
|
|
|
p++;
|
2012-01-05 18:34:35 +00:00
|
|
|
*p = '\0';
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2011-09-03 15:37:09 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else /* Check win.ini */
|
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
/* Toss the leading dot */
|
|
|
|
extension++;
|
2022-01-09 21:38:31 +00:00
|
|
|
if (GetProfileStringW(L"extensions", extension, L"", command, ARRAY_SIZE(command)) > 0)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
if (wcslen(command) != 0)
|
|
|
|
{
|
|
|
|
wcscpy(lpResult, command);
|
|
|
|
tok = wcschr(lpResult, '^'); /* should be ^.extension? */
|
|
|
|
if (tok != NULL)
|
|
|
|
{
|
|
|
|
tok[0] = '\0';
|
|
|
|
wcscat(lpResult, xlpFile); /* what if no dir in xlpFile? */
|
|
|
|
tok = wcschr(command, '^'); /* see above */
|
2012-01-05 18:34:35 +00:00
|
|
|
if ((tok != NULL) && (wcslen(tok) > 5))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
wcscat(lpResult, &tok[5]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval = 33; /* FIXME - see above */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("returning %s\n", debugstr_w(lpResult));
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* dde_cb
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* callback for the DDE connection. not really useful
|
|
|
|
*/
|
|
|
|
static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
|
|
|
|
HSZ hsz1, HSZ hsz2, HDDEDATA hData,
|
|
|
|
ULONG_PTR dwData1, ULONG_PTR dwData2)
|
|
|
|
{
|
|
|
|
TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
|
2012-01-05 18:34:35 +00:00
|
|
|
uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
|
2011-05-15 15:55:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* dde_connect
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* ShellExecute helper. Used to do an operation with a DDE connection
|
|
|
|
*
|
|
|
|
* Handles both the direct connection (try #1), and if it fails,
|
|
|
|
* launching an application and trying (#2) to connect to it
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static unsigned dde_connect(const WCHAR* key, const WCHAR* start, WCHAR* ddeexec,
|
|
|
|
const WCHAR* lpFile, WCHAR *env,
|
2011-09-03 15:37:09 +00:00
|
|
|
LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc,
|
2011-05-15 15:55:49 +00:00
|
|
|
const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
|
|
|
|
{
|
|
|
|
WCHAR regkey[256];
|
|
|
|
WCHAR * endkey = regkey + wcslen(key);
|
2014-05-22 18:53:44 +00:00
|
|
|
WCHAR app[256], topic[256], ifexec[256], static_res[256];
|
|
|
|
WCHAR * dynamic_res=NULL;
|
|
|
|
WCHAR * res;
|
2011-05-15 15:55:49 +00:00
|
|
|
LONG applen, topiclen, ifexeclen;
|
|
|
|
WCHAR * exec;
|
|
|
|
DWORD ddeInst = 0;
|
|
|
|
DWORD tid;
|
2014-05-22 18:53:44 +00:00
|
|
|
DWORD resultLen, endkeyLen;
|
2011-05-15 15:55:49 +00:00
|
|
|
HSZ hszApp, hszTopic;
|
|
|
|
HCONV hConv;
|
|
|
|
HDDEDATA hDdeData;
|
|
|
|
unsigned ret = SE_ERR_NOASSOC;
|
|
|
|
BOOL unicode = !(GetVersion() & 0x80000000);
|
|
|
|
|
2022-01-09 21:38:31 +00:00
|
|
|
if (strlenW(key) + 1 > ARRAY_SIZE(regkey))
|
2014-05-22 18:53:44 +00:00
|
|
|
{
|
|
|
|
FIXME("input parameter %s larger than buffer\n", debugstr_w(key));
|
|
|
|
return 2;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
wcscpy(regkey, key);
|
2022-01-09 21:38:31 +00:00
|
|
|
endkeyLen = ARRAY_SIZE(regkey) - (endkey - regkey);
|
|
|
|
if (strlenW(L"\\application") + 1 > endkeyLen)
|
2014-05-22 18:53:44 +00:00
|
|
|
{
|
2022-01-09 21:38:31 +00:00
|
|
|
FIXME("endkey %s overruns buffer\n", debugstr_w(L"\\application"));
|
2014-05-22 18:53:44 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2022-01-09 21:38:31 +00:00
|
|
|
wcscpy(endkey, L"\\application");
|
2011-05-15 15:55:49 +00:00
|
|
|
applen = sizeof(app);
|
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, app, &applen) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WCHAR command[1024], fullpath[MAX_PATH];
|
|
|
|
LPWSTR ptr = NULL;
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
/* Get application command from start string and find filename of application */
|
|
|
|
if (*start == '"')
|
|
|
|
{
|
2022-01-09 21:38:31 +00:00
|
|
|
if (strlenW(start + 1) + 1 > ARRAY_SIZE(command))
|
2014-05-22 18:53:44 +00:00
|
|
|
{
|
|
|
|
FIXME("size of input parameter %s larger than buffer\n",
|
|
|
|
debugstr_w(start + 1));
|
|
|
|
return 2;
|
|
|
|
}
|
2012-01-05 18:34:35 +00:00
|
|
|
wcscpy(command, start + 1);
|
2011-05-15 15:55:49 +00:00
|
|
|
if ((ptr = wcschr(command, '"')))
|
2012-01-05 18:34:35 +00:00
|
|
|
* ptr = 0;
|
2022-01-09 21:38:31 +00:00
|
|
|
ret = SearchPathW(NULL, command, L".exe", ARRAY_SIZE(fullpath), fullpath, &ptr);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
LPCWSTR p;
|
|
|
|
LPWSTR space;
|
|
|
|
for (p = start; (space = const_cast<LPWSTR>(strchrW(p, ' '))); p = space + 1)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
int idx = space - start;
|
|
|
|
memcpy(command, start, idx * sizeof(WCHAR));
|
2011-05-15 15:55:49 +00:00
|
|
|
command[idx] = '\0';
|
2022-01-09 21:38:31 +00:00
|
|
|
if ((ret = SearchPathW(NULL, command, L".exe", ARRAY_SIZE(fullpath), fullpath, &ptr)))
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!ret)
|
2022-01-09 21:38:31 +00:00
|
|
|
ret = SearchPathW(NULL, start, L".exe", ARRAY_SIZE(fullpath), fullpath, &ptr);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
ERR("Unable to find application path for command %s\n", debugstr_w(start));
|
|
|
|
return ERROR_ACCESS_DENIED;
|
|
|
|
}
|
2022-01-09 21:38:31 +00:00
|
|
|
if (strlenW(ptr) + 1 > ARRAY_SIZE(app))
|
2014-05-22 18:53:44 +00:00
|
|
|
{
|
|
|
|
FIXME("size of found path %s larger than buffer\n", debugstr_w(ptr));
|
|
|
|
return 2;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
wcscpy(app, ptr);
|
|
|
|
|
|
|
|
/* Remove extensions (including .so) */
|
2022-01-09 21:38:31 +00:00
|
|
|
ptr = app + wcslen(app) - 3;
|
|
|
|
if (ptr > app && !wcscmp(ptr, L".so"))
|
2011-05-15 15:55:49 +00:00
|
|
|
*ptr = 0;
|
|
|
|
|
|
|
|
ptr = const_cast<LPWSTR>(strrchrW(app, '.'));
|
|
|
|
assert(ptr);
|
|
|
|
*ptr = 0;
|
|
|
|
}
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2022-01-09 21:38:31 +00:00
|
|
|
if (strlenW(L"\\topic") + 1 > endkeyLen)
|
2014-05-22 18:53:44 +00:00
|
|
|
{
|
2022-01-09 21:38:31 +00:00
|
|
|
FIXME("endkey %s overruns buffer\n", debugstr_w(L"\\topic"));
|
2014-05-22 18:53:44 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2022-01-09 21:38:31 +00:00
|
|
|
wcscpy(endkey, L"\\topic");
|
2011-05-15 15:55:49 +00:00
|
|
|
topiclen = sizeof(topic);
|
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, topic, &topiclen) != ERROR_SUCCESS)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
wcscpy(topic, L"System");
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unicode)
|
|
|
|
{
|
|
|
|
if (DdeInitializeW(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
hszApp = DdeCreateStringHandleW(ddeInst, app, CP_WINUNICODE);
|
|
|
|
hszTopic = DdeCreateStringHandleW(ddeInst, topic, CP_WINUNICODE);
|
|
|
|
|
|
|
|
hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
|
|
|
|
exec = ddeexec;
|
|
|
|
if (!hConv)
|
|
|
|
{
|
|
|
|
TRACE("Launching %s\n", debugstr_w(start));
|
|
|
|
ret = execfunc(start, env, TRUE, psei, psei_out);
|
|
|
|
if (ret <= 32)
|
|
|
|
{
|
|
|
|
TRACE("Couldn't launch\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2020-02-23 16:47:48 +00:00
|
|
|
/* if ddeexec is NULL, then we just need to exit here */
|
|
|
|
if (ddeexec == NULL)
|
|
|
|
{
|
|
|
|
TRACE("Exiting because ddeexec is NULL. ret=42.\n");
|
|
|
|
/* See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew */
|
|
|
|
/* for reason why we use 42 here and also "Shell32_apitest ShellExecuteW" regression test */
|
|
|
|
return 42;
|
|
|
|
}
|
|
|
|
/* if ddeexec is 'empty string', then we just need to exit here */
|
|
|
|
if (wcscmp(ddeexec, L"") == 0)
|
|
|
|
{
|
|
|
|
TRACE("Exiting because ddeexec is 'empty string'. ret=42.\n");
|
|
|
|
/* See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew */
|
|
|
|
/* for reason why we use 42 here and also "Shell32_apitest ShellExecuteW" regression test */
|
|
|
|
return 42;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
|
|
|
|
if (!hConv)
|
|
|
|
{
|
|
|
|
TRACE("Couldn't connect. ret=%d\n", ret);
|
|
|
|
DdeUninitialize(ddeInst);
|
|
|
|
SetLastError(ERROR_DDE_FAIL);
|
|
|
|
return 30; /* whatever */
|
|
|
|
}
|
2022-01-09 21:38:31 +00:00
|
|
|
if (strlenW(L"\\ifexec") + 1 > endkeyLen)
|
2014-05-22 18:53:44 +00:00
|
|
|
{
|
2022-01-09 21:38:31 +00:00
|
|
|
FIXME("endkey %s overruns buffer\n", debugstr_w(L"\\ifexec"));
|
2014-05-22 18:53:44 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2022-01-09 21:38:31 +00:00
|
|
|
strcpyW(endkey, L"\\ifexec");
|
2011-05-15 15:55:49 +00:00
|
|
|
ifexeclen = sizeof(ifexec);
|
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, ifexec, &ifexeclen) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
exec = ifexec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-09 21:38:31 +00:00
|
|
|
SHELL_ArgifyW(static_res, ARRAY_SIZE(static_res), exec, lpFile, pidl, szCommandline, &resultLen, NULL);
|
|
|
|
if (resultLen > ARRAY_SIZE(static_res))
|
2014-05-22 18:53:44 +00:00
|
|
|
{
|
|
|
|
res = dynamic_res = static_cast<WCHAR *>(HeapAlloc(GetProcessHeap(), 0, resultLen * sizeof(WCHAR)));
|
2018-07-12 15:45:43 +00:00
|
|
|
SHELL_ArgifyW(dynamic_res, resultLen, exec, lpFile, pidl, szCommandline, NULL, NULL);
|
2014-05-22 18:53:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
res = static_res;
|
2011-05-15 15:55:49 +00:00
|
|
|
TRACE("%s %s => %s\n", debugstr_w(exec), debugstr_w(lpFile), debugstr_w(res));
|
|
|
|
|
|
|
|
/* It's documented in the KB 330337 that IE has a bug and returns
|
|
|
|
* error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
|
|
|
|
*/
|
|
|
|
if (unicode)
|
2011-09-03 15:37:09 +00:00
|
|
|
hDdeData = DdeClientTransaction((LPBYTE)res, (strlenW(res) + 1) * sizeof(WCHAR), hConv, 0L, 0, XTYP_EXECUTE, 30000, &tid);
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD lenA = WideCharToMultiByte(CP_ACP, 0, res, -1, NULL, 0, NULL, NULL);
|
|
|
|
char *resA = (LPSTR)HeapAlloc(GetProcessHeap(), 0, lenA);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, res, -1, resA, lenA, NULL, NULL);
|
|
|
|
hDdeData = DdeClientTransaction( (LPBYTE)resA, lenA, hConv, 0L, 0,
|
|
|
|
XTYP_EXECUTE, 10000, &tid );
|
|
|
|
HeapFree(GetProcessHeap(), 0, resA);
|
|
|
|
}
|
|
|
|
if (hDdeData)
|
|
|
|
DdeFreeDataHandle(hDdeData);
|
|
|
|
else
|
|
|
|
WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst));
|
|
|
|
ret = 33;
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, dynamic_res);
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
DdeDisconnect(hConv);
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
error:
|
2011-05-15 15:55:49 +00:00
|
|
|
DdeUninitialize(ddeInst);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* execute_from_key [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2011-09-03 15:37:09 +00:00
|
|
|
static UINT_PTR execute_from_key(LPCWSTR key, LPCWSTR lpFile, WCHAR *env,
|
|
|
|
LPCWSTR szCommandline, LPCWSTR executable_name,
|
|
|
|
SHELL_ExecuteW32 execfunc,
|
|
|
|
LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WCHAR cmd[256], param[1024], ddeexec[256];
|
|
|
|
DWORD cmdlen = sizeof(cmd), ddeexeclen = sizeof(ddeexec);
|
|
|
|
UINT_PTR retval = SE_ERR_NOASSOC;
|
|
|
|
DWORD resultLen;
|
|
|
|
LPWSTR tmp;
|
|
|
|
|
|
|
|
TRACE("%s %s %s %s %s\n", debugstr_w(key), debugstr_w(lpFile), debugstr_w(env),
|
2012-01-05 18:34:35 +00:00
|
|
|
debugstr_w(szCommandline), debugstr_w(executable_name));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
cmd[0] = '\0';
|
|
|
|
param[0] = '\0';
|
|
|
|
|
|
|
|
/* Get the application from the registry */
|
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, key, cmd, (LONG *)&cmdlen) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
TRACE("got cmd: %s\n", debugstr_w(cmd));
|
|
|
|
|
|
|
|
/* Is there a replace() function anywhere? */
|
|
|
|
cmdlen /= sizeof(WCHAR);
|
2022-01-09 21:38:31 +00:00
|
|
|
if (cmdlen >= ARRAY_SIZE(cmd))
|
|
|
|
cmdlen = ARRAY_SIZE(cmd) - 1;
|
2011-05-15 15:55:49 +00:00
|
|
|
cmd[cmdlen] = '\0';
|
2022-01-09 21:38:31 +00:00
|
|
|
SHELL_ArgifyW(param, ARRAY_SIZE(param), cmd, lpFile, (LPITEMIDLIST)psei->lpIDList, szCommandline, &resultLen,
|
2018-07-12 15:45:43 +00:00
|
|
|
(psei->lpDirectory && *psei->lpDirectory) ? psei->lpDirectory : NULL);
|
2022-01-09 21:38:31 +00:00
|
|
|
if (resultLen > ARRAY_SIZE(param))
|
2011-05-15 15:55:49 +00:00
|
|
|
ERR("Argify buffer not large enough, truncating\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the parameters needed by the application
|
|
|
|
from the associated ddeexec key */
|
2012-01-05 18:34:35 +00:00
|
|
|
tmp = const_cast<LPWSTR>(strstrW(key, L"command"));
|
2011-05-15 15:55:49 +00:00
|
|
|
assert(tmp);
|
2012-01-05 18:34:35 +00:00
|
|
|
wcscpy(tmp, L"ddeexec");
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ddeexec, (LONG *)&ddeexeclen) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
TRACE("Got ddeexec %s => %s\n", debugstr_w(key), debugstr_w(ddeexec));
|
|
|
|
if (!param[0]) strcpyW(param, executable_name);
|
|
|
|
retval = dde_connect(key, param, ddeexec, lpFile, env, szCommandline, (LPITEMIDLIST)psei->lpIDList, execfunc, psei, psei_out);
|
|
|
|
}
|
|
|
|
else if (param[0])
|
|
|
|
{
|
|
|
|
TRACE("executing: %s\n", debugstr_w(param));
|
|
|
|
retval = execfunc(param, env, FALSE, psei, psei_out);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WARN("Nothing appropriate found for %s\n", debugstr_w(key));
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* FindExecutableA [SHELL32.@]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
|
|
|
HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
|
|
|
|
{
|
|
|
|
HINSTANCE retval;
|
|
|
|
WCHAR *wFile = NULL, *wDirectory = NULL;
|
|
|
|
WCHAR wResult[MAX_PATH];
|
|
|
|
|
|
|
|
if (lpFile) __SHCloneStrAtoW(&wFile, lpFile);
|
|
|
|
if (lpDirectory) __SHCloneStrAtoW(&wDirectory, lpDirectory);
|
|
|
|
|
|
|
|
retval = FindExecutableW(wFile, wDirectory, wResult);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, wResult, -1, lpResult, MAX_PATH, NULL, NULL);
|
2012-01-05 18:34:35 +00:00
|
|
|
SHFree(wFile);
|
|
|
|
SHFree(wDirectory);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
TRACE("returning %s\n", lpResult);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* FindExecutableW [SHELL32.@]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* This function returns the executable associated with the specified file
|
|
|
|
* for the default verb.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpFile [I] The file to find the association for. This must refer to
|
|
|
|
* an existing file otherwise FindExecutable fails and returns
|
|
|
|
* SE_ERR_FNF.
|
|
|
|
* lpResult [O] Points to a buffer into which the executable path is
|
|
|
|
* copied. This parameter must not be NULL otherwise
|
|
|
|
* FindExecutable() segfaults. The buffer must be of size at
|
|
|
|
* least MAX_PATH characters.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* A value greater than 32 on success, less than or equal to 32 otherwise.
|
|
|
|
* See the SE_ERR_* constants.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* On Windows XP and 2003, FindExecutable() seems to first convert the
|
|
|
|
* filename into 8.3 format, thus taking into account only the first three
|
|
|
|
* characters of the extension, and expects to find an association for those.
|
|
|
|
* However other Windows versions behave sanely.
|
|
|
|
*/
|
|
|
|
HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
|
|
|
|
{
|
|
|
|
UINT_PTR retval = SE_ERR_NOASSOC;
|
|
|
|
WCHAR old_dir[1024];
|
2017-06-19 15:04:20 +00:00
|
|
|
WCHAR res[MAX_PATH];
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
TRACE("File %s, Dir %s\n", debugstr_w(lpFile), debugstr_w(lpDirectory));
|
|
|
|
|
|
|
|
lpResult[0] = '\0'; /* Start off with an empty return string */
|
|
|
|
if (lpFile == NULL)
|
2011-09-03 15:37:09 +00:00
|
|
|
return (HINSTANCE)SE_ERR_FNF;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (lpDirectory)
|
|
|
|
{
|
2022-01-09 21:38:31 +00:00
|
|
|
GetCurrentDirectoryW(ARRAY_SIZE(old_dir), old_dir);
|
2011-05-15 15:55:49 +00:00
|
|
|
SetCurrentDirectoryW(lpDirectory);
|
|
|
|
}
|
|
|
|
|
2022-01-09 21:38:31 +00:00
|
|
|
retval = SHELL_FindExecutable(lpDirectory, lpFile, L"open", res, MAX_PATH, NULL, NULL, NULL, NULL);
|
2017-06-19 15:04:20 +00:00
|
|
|
if (retval > 32)
|
|
|
|
strcpyW(lpResult, res);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
TRACE("returning %s\n", debugstr_w(lpResult));
|
|
|
|
if (lpDirectory)
|
|
|
|
SetCurrentDirectoryW(old_dir);
|
|
|
|
return (HINSTANCE)retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: is this already implemented somewhere else? */
|
2012-01-05 18:34:35 +00:00
|
|
|
static HKEY ShellExecute_GetClassKey(const SHELLEXECUTEINFOW *sei)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPCWSTR ext = NULL, lpClass = NULL;
|
|
|
|
LPWSTR cls = NULL;
|
|
|
|
DWORD type = 0, sz = 0;
|
|
|
|
HKEY hkey = 0;
|
|
|
|
LONG r;
|
|
|
|
|
|
|
|
if (sei->fMask & SEE_MASK_CLASSALL)
|
|
|
|
return sei->hkeyClass;
|
|
|
|
|
|
|
|
if (sei->fMask & SEE_MASK_CLASSNAME)
|
|
|
|
lpClass = sei->lpClass;
|
|
|
|
else
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
ext = PathFindExtensionW(sei->lpFile);
|
|
|
|
TRACE("ext = %s\n", debugstr_w(ext));
|
2011-05-15 15:55:49 +00:00
|
|
|
if (!ext)
|
|
|
|
return hkey;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
r = RegOpenKeyW(HKEY_CLASSES_ROOT, ext, &hkey);
|
|
|
|
if (r != ERROR_SUCCESS)
|
2011-05-15 15:55:49 +00:00
|
|
|
return hkey;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
r = RegQueryValueExW(hkey, NULL, 0, &type, NULL, &sz);
|
|
|
|
if (r == ERROR_SUCCESS && type == REG_SZ)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
sz += sizeof (WCHAR);
|
2012-01-05 18:34:35 +00:00
|
|
|
cls = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sz);
|
2011-05-15 15:55:49 +00:00
|
|
|
cls[0] = 0;
|
2012-01-05 18:34:35 +00:00
|
|
|
RegQueryValueExW(hkey, NULL, 0, &type, (LPBYTE) cls, &sz);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
lpClass = cls;
|
|
|
|
}
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("class = %s\n", debugstr_w(lpClass));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
hkey = 0;
|
2012-01-05 18:34:35 +00:00
|
|
|
if (lpClass)
|
|
|
|
RegOpenKeyW( HKEY_CLASSES_ROOT, lpClass, &hkey);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, cls);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
return hkey;
|
|
|
|
}
|
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
static HRESULT shellex_get_dataobj( LPSHELLEXECUTEINFOW sei, CComPtr<IDataObject>& dataObj)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2022-02-03 20:54:12 +00:00
|
|
|
CComHeapPtr<ITEMIDLIST> allocatedPidl;
|
2011-05-15 15:55:49 +00:00
|
|
|
LPITEMIDLIST pidl = NULL;
|
|
|
|
|
|
|
|
if (sei->fMask & SEE_MASK_CLASSALL)
|
2022-02-03 20:54:12 +00:00
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
pidl = (LPITEMIDLIST)sei->lpIDList;
|
2022-02-03 20:54:12 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR fullpath[MAX_PATH];
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
fullpath[0] = 0;
|
2012-01-05 18:34:35 +00:00
|
|
|
ret = GetFullPathNameW(sei->lpFile, MAX_PATH, fullpath, NULL);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (!ret)
|
2022-02-03 20:54:12 +00:00
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
pidl = ILCreateFromPathW(fullpath);
|
2022-02-03 20:54:12 +00:00
|
|
|
allocatedPidl.Attach(pidl);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
CComPtr<IShellFolder> shf;
|
|
|
|
LPCITEMIDLIST pidllast = NULL;
|
|
|
|
HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &shf), &pidllast);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
return shf->GetUIObjectOf(NULL, 1, &pidllast, IID_NULL_PPV_ARG(IDataObject, &dataObj));
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
static HRESULT shellex_run_context_menu_default(IShellExtInit *obj,
|
|
|
|
LPSHELLEXECUTEINFOW sei)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-08-20 12:25:09 +00:00
|
|
|
CComPtr<IContextMenu> cm = NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
CMINVOKECOMMANDINFOEX ici;
|
|
|
|
MENUITEMINFOW info;
|
|
|
|
WCHAR string[0x80];
|
|
|
|
INT i, n, def = -1;
|
|
|
|
HMENU hmenu = 0;
|
|
|
|
HRESULT r;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("%p %p\n", obj, sei);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2014-04-28 21:59:02 +00:00
|
|
|
r = obj->QueryInterface(IID_PPV_ARG(IContextMenu, &cm));
|
2012-01-05 18:34:35 +00:00
|
|
|
if (FAILED(r))
|
2011-05-15 15:55:49 +00:00
|
|
|
return r;
|
|
|
|
|
|
|
|
hmenu = CreateMenu();
|
2012-01-05 18:34:35 +00:00
|
|
|
if (!hmenu)
|
2011-05-15 15:55:49 +00:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* the number of the last menu added is returned in r */
|
2012-01-05 18:34:35 +00:00
|
|
|
r = cm->QueryContextMenu(hmenu, 0, 0x20, 0x7fff, CMF_DEFAULTONLY);
|
|
|
|
if (FAILED(r))
|
2011-05-15 15:55:49 +00:00
|
|
|
goto end;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
n = GetMenuItemCount(hmenu);
|
|
|
|
for (i = 0; i < n; i++)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
memset(&info, 0, sizeof(info));
|
2011-05-15 15:55:49 +00:00
|
|
|
info.cbSize = sizeof info;
|
|
|
|
info.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE | MIIM_DATA | MIIM_ID;
|
|
|
|
info.dwTypeData = string;
|
|
|
|
info.cch = sizeof string;
|
|
|
|
string[0] = 0;
|
2012-01-05 18:34:35 +00:00
|
|
|
GetMenuItemInfoW(hmenu, i, TRUE, &info);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
TRACE("menu %d %s %08x %08lx %08x %08x\n", i, debugstr_w(string),
|
2012-01-05 18:34:35 +00:00
|
|
|
info.fState, info.dwItemData, info.fType, info.wID);
|
|
|
|
if ((!sei->lpVerb && (info.fState & MFS_DEFAULT)) ||
|
|
|
|
(sei->lpVerb && !lstrcmpiW(sei->lpVerb, string)))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
def = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r = E_FAIL;
|
2012-01-05 18:34:35 +00:00
|
|
|
if (def == -1)
|
2011-05-15 15:55:49 +00:00
|
|
|
goto end;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
memset(&ici, 0, sizeof ici);
|
2011-05-15 15:55:49 +00:00
|
|
|
ici.cbSize = sizeof ici;
|
2014-05-22 18:53:44 +00:00
|
|
|
ici.fMask = CMIC_MASK_UNICODE | (sei->fMask & (SEE_MASK_NO_CONSOLE | SEE_MASK_NOASYNC | SEE_MASK_ASYNCOK | SEE_MASK_FLAG_NO_UI));
|
2011-05-15 15:55:49 +00:00
|
|
|
ici.nShow = sei->nShow;
|
2012-01-05 18:34:35 +00:00
|
|
|
ici.lpVerb = MAKEINTRESOURCEA(def);
|
2011-05-15 15:55:49 +00:00
|
|
|
ici.hwnd = sei->hwnd;
|
|
|
|
ici.lpParametersW = sei->lpParameters;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
r = cm->InvokeCommand((LPCMINVOKECOMMANDINFO)&ici);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("invoke command returned %08x\n", r);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
end:
|
2012-01-05 18:34:35 +00:00
|
|
|
if (hmenu)
|
2011-05-15 15:55:49 +00:00
|
|
|
DestroyMenu( hmenu );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
static HRESULT shellex_load_object_and_run(HKEY hkey, LPCGUID guid, LPSHELLEXECUTEINFOW sei)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("%p %s %p\n", hkey, debugstr_guid(guid), sei);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
CCoInit coInit;
|
|
|
|
|
2022-10-23 19:16:56 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(coInit.hr))
|
|
|
|
return coInit.hr;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
CComPtr<IShellExtInit> obj;
|
|
|
|
HRESULT hr = CoCreateInstance(*guid, NULL, CLSCTX_INPROC_SERVER,
|
2013-11-11 16:42:16 +00:00
|
|
|
IID_PPV_ARG(IShellExtInit, &obj));
|
2022-02-03 20:54:12 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
CComPtr<IDataObject> dataobj;
|
|
|
|
hr = shellex_get_dataobj(sei, dataobj);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = obj->Initialize(NULL, dataobj, hkey);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
CComPtr<IObjectWithSite> ows;
|
|
|
|
hr = obj->QueryInterface(IID_PPV_ARG(IObjectWithSite, &ows));
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
ows->SetSite(NULL);
|
|
|
|
|
|
|
|
return shellex_run_context_menu_default(obj, sei);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT shellex_get_contextmenu(LPSHELLEXECUTEINFOW sei, CComPtr<IContextMenu>& cm)
|
|
|
|
{
|
|
|
|
CComHeapPtr<ITEMIDLIST> allocatedPidl;
|
|
|
|
LPITEMIDLIST pidl = NULL;
|
|
|
|
|
|
|
|
if (sei->lpIDList)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2022-02-03 20:54:12 +00:00
|
|
|
pidl = (LPITEMIDLIST)sei->lpIDList;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2022-02-03 20:54:12 +00:00
|
|
|
else
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2022-02-03 20:54:12 +00:00
|
|
|
SFGAOF sfga = 0;
|
|
|
|
HRESULT hr = SHParseDisplayName(sei->lpFile, NULL, &allocatedPidl, SFGAO_STORAGECAPMASK, &sfga);
|
|
|
|
if (FAILED(hr))
|
2022-02-03 22:22:37 +00:00
|
|
|
{
|
|
|
|
WCHAR Buffer[MAX_PATH] = {};
|
|
|
|
// FIXME: MAX_PATH.....
|
|
|
|
UINT retval = SHELL_FindExecutable(sei->lpDirectory, sei->lpFile, sei->lpVerb, Buffer, _countof(Buffer), NULL, NULL, NULL, sei->lpParameters);
|
|
|
|
if (retval <= 32)
|
|
|
|
return HRESULT_FROM_WIN32(retval);
|
|
|
|
|
|
|
|
hr = SHParseDisplayName(Buffer, NULL, &allocatedPidl, SFGAO_STORAGECAPMASK, &sfga);
|
|
|
|
// This should not happen, we found it...
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
2022-02-03 20:54:12 +00:00
|
|
|
|
|
|
|
pidl = allocatedPidl;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
CComPtr<IShellFolder> shf;
|
|
|
|
LPCITEMIDLIST pidllast = NULL;
|
|
|
|
HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &shf), &pidllast);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
return shf->GetUIObjectOf(NULL, 1, &pidllast, IID_NULL_PPV_ARG(IContextMenu, &cm));
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2022-02-06 20:08:52 +00:00
|
|
|
static HRESULT ShellExecute_ContextMenuVerb(LPSHELLEXECUTEINFOW sei)
|
2022-02-03 20:54:12 +00:00
|
|
|
{
|
|
|
|
TRACE("%p\n", sei);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
CCoInit coInit;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2022-10-23 19:16:56 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(coInit.hr))
|
|
|
|
return coInit.hr;
|
2022-02-03 20:54:12 +00:00
|
|
|
|
|
|
|
CComPtr<IContextMenu> cm;
|
|
|
|
HRESULT hr = shellex_get_contextmenu(sei, cm);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
CComHeapPtr<char> verb, parameters;
|
|
|
|
__SHCloneStrWtoA(&verb, sei->lpVerb);
|
|
|
|
__SHCloneStrWtoA(¶meters, sei->lpParameters);
|
|
|
|
|
|
|
|
CMINVOKECOMMANDINFOEX ici = {};
|
|
|
|
ici.cbSize = sizeof ici;
|
|
|
|
ici.fMask = (sei->fMask & (SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_FLAG_NO_UI));
|
|
|
|
ici.nShow = sei->nShow;
|
|
|
|
ici.lpVerb = verb;
|
|
|
|
ici.hwnd = sei->hwnd;
|
|
|
|
ici.lpParameters = parameters;
|
|
|
|
|
|
|
|
HMENU hMenu = CreatePopupMenu();
|
|
|
|
BOOL fDefault = !ici.lpVerb || !ici.lpVerb[0];
|
|
|
|
hr = cm->QueryContextMenu(hMenu, 0, 1, 0x7fff, fDefault ? CMF_DEFAULTONLY : 0);
|
|
|
|
if (!FAILED_UNEXPECTEDLY(hr))
|
|
|
|
{
|
|
|
|
if (fDefault)
|
|
|
|
{
|
|
|
|
INT uDefault = GetMenuDefaultItem(hMenu, FALSE, 0);
|
|
|
|
uDefault = (uDefault != -1) ? uDefault - 1 : 0;
|
|
|
|
ici.lpVerb = MAKEINTRESOURCEA(uDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = cm->InvokeCommand((LPCMINVOKECOMMANDINFO)&ici);
|
|
|
|
if (!FAILED_UNEXPECTEDLY(hr))
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyMenu(hMenu);
|
|
|
|
|
|
|
|
return hr;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* ShellExecute_FromContextMenu [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2022-02-06 20:08:52 +00:00
|
|
|
static LONG ShellExecute_FromContextMenuHandlers( LPSHELLEXECUTEINFOW sei )
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
HKEY hkey, hkeycm = 0;
|
|
|
|
WCHAR szguid[39];
|
|
|
|
HRESULT hr;
|
|
|
|
GUID guid;
|
|
|
|
DWORD i;
|
|
|
|
LONG r;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("%s\n", debugstr_w(sei->lpFile));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
hkey = ShellExecute_GetClassKey(sei);
|
|
|
|
if (!hkey)
|
2011-05-15 15:55:49 +00:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
r = RegOpenKeyW(hkey, L"shellex\\ContextMenuHandlers", &hkeycm);
|
|
|
|
if (r == ERROR_SUCCESS)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
i = 0;
|
2012-01-05 18:34:35 +00:00
|
|
|
while (1)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2022-01-09 21:38:31 +00:00
|
|
|
r = RegEnumKeyW(hkeycm, i++, szguid, ARRAY_SIZE(szguid));
|
2012-01-05 18:34:35 +00:00
|
|
|
if (r != ERROR_SUCCESS)
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
hr = CLSIDFromString(szguid, &guid);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
/* stop at the first one that succeeds in running */
|
2012-01-05 18:34:35 +00:00
|
|
|
hr = shellex_load_object_and_run(hkey, &guid, sei);
|
|
|
|
if (SUCCEEDED(hr))
|
2011-05-15 15:55:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 18:34:35 +00:00
|
|
|
RegCloseKey(hkeycm);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
if (hkey != sei->hkeyClass)
|
|
|
|
RegCloseKey(hkey);
|
2011-05-15 15:55:49 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
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);
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
static UINT_PTR SHELL_execute_class(LPCWSTR wszApplicationName, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
WCHAR execCmd[1024], classname[1024];
|
2011-05-15 15:55:49 +00:00
|
|
|
/* launch a document by fileclass like 'WordPad.Document.1' */
|
|
|
|
/* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
|
|
|
|
/* FIXME: wcmd should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
|
2012-01-05 18:34:35 +00:00
|
|
|
ULONG cmask = (psei->fMask & SEE_MASK_CLASSALL);
|
2011-05-15 15:55:49 +00:00
|
|
|
DWORD resultLen;
|
|
|
|
BOOL done;
|
2014-05-22 18:53:44 +00:00
|
|
|
UINT_PTR rslt;
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
/* FIXME: remove following block when SHELL_quote_and_execute supports hkeyClass parameter */
|
|
|
|
if (cmask != SEE_MASK_CLASSNAME)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
WCHAR wcmd[1024];
|
|
|
|
HCR_GetExecuteCommandW((cmask == SEE_MASK_CLASSKEY) ? psei->hkeyClass : NULL,
|
|
|
|
(cmask == SEE_MASK_CLASSNAME) ? psei->lpClass : NULL,
|
|
|
|
psei->lpVerb,
|
|
|
|
execCmd, sizeof(execCmd));
|
|
|
|
|
|
|
|
/* FIXME: get the extension of lpFile, check if it fits to the lpClass */
|
|
|
|
TRACE("SEE_MASK_CLASSNAME->%s, doc->%s\n", debugstr_w(execCmd), debugstr_w(wszApplicationName));
|
|
|
|
|
|
|
|
wcmd[0] = '\0';
|
2022-01-09 21:38:31 +00:00
|
|
|
done = SHELL_ArgifyW(wcmd, ARRAY_SIZE(wcmd), execCmd, wszApplicationName, (LPITEMIDLIST)psei->lpIDList, NULL, &resultLen,
|
2018-07-12 15:45:43 +00:00
|
|
|
(psei->lpDirectory && *psei->lpDirectory) ? psei->lpDirectory : NULL);
|
2014-05-22 18:53:44 +00:00
|
|
|
if (!done && wszApplicationName[0])
|
|
|
|
{
|
|
|
|
strcatW(wcmd, L" ");
|
|
|
|
if (*wszApplicationName != '"')
|
|
|
|
{
|
|
|
|
strcatW(wcmd, L"\"");
|
|
|
|
strcatW(wcmd, wszApplicationName);
|
|
|
|
strcatW(wcmd, L"\"");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcatW(wcmd, wszApplicationName);
|
|
|
|
}
|
2022-01-09 21:38:31 +00:00
|
|
|
if (resultLen > ARRAY_SIZE(wcmd))
|
2014-05-22 18:53:44 +00:00
|
|
|
ERR("Argify buffer not large enough... truncating\n");
|
|
|
|
return execfunc(wcmd, NULL, FALSE, psei, psei_out);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2014-05-31 16:58:03 +00:00
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
strcpyW(classname, psei->lpClass);
|
|
|
|
rslt = SHELL_FindExecutableByVerb(psei->lpVerb, NULL, classname, execCmd, sizeof(execCmd));
|
|
|
|
|
|
|
|
TRACE("SHELL_FindExecutableByVerb returned %u (%s, %s)\n", (unsigned int)rslt, debugstr_w(classname), debugstr_w(execCmd));
|
|
|
|
if (33 > rslt)
|
|
|
|
return rslt;
|
|
|
|
rslt = SHELL_quote_and_execute( execCmd, L"", classname,
|
|
|
|
wszApplicationName, NULL, psei,
|
|
|
|
psei_out, execfunc );
|
|
|
|
return rslt;
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
static BOOL SHELL_translate_idlist(LPSHELLEXECUTEINFOW sei, LPWSTR wszParameters, DWORD parametersLen, LPWSTR wszApplicationName, DWORD dwApplicationNameLen)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
BOOL appKnownSingular = FALSE;
|
|
|
|
|
|
|
|
/* last chance to translate IDList: now also allow CLSID paths */
|
2022-01-09 21:38:31 +00:00
|
|
|
if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW((LPCITEMIDLIST)sei->lpIDList, buffer, ARRAY_SIZE(buffer)))) {
|
2012-01-05 18:34:35 +00:00
|
|
|
if (buffer[0] == ':' && buffer[1] == ':') {
|
2011-05-15 15:55:49 +00:00
|
|
|
/* open shell folder for the specified class GUID */
|
|
|
|
if (strlenW(buffer) + 1 > parametersLen)
|
|
|
|
ERR("parameters len exceeds buffer size (%i > %i), truncating\n",
|
|
|
|
lstrlenW(buffer) + 1, parametersLen);
|
|
|
|
lstrcpynW(wszParameters, buffer, parametersLen);
|
2022-01-09 21:38:31 +00:00
|
|
|
if (strlenW(L"explorer.exe") > dwApplicationNameLen)
|
|
|
|
ERR("application len exceeds buffer size (%i), truncating\n",
|
|
|
|
dwApplicationNameLen);
|
|
|
|
lstrcpynW(wszApplicationName, L"explorer.exe", dwApplicationNameLen);
|
2011-05-15 15:55:49 +00:00
|
|
|
appKnownSingular = TRUE;
|
|
|
|
|
|
|
|
sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
|
|
|
|
} else {
|
|
|
|
WCHAR target[MAX_PATH];
|
|
|
|
DWORD attribs;
|
|
|
|
DWORD resultLen;
|
|
|
|
/* Check if we're executing a directory and if so use the
|
|
|
|
handler for the Folder class */
|
|
|
|
strcpyW(target, buffer);
|
|
|
|
attribs = GetFileAttributesW(buffer);
|
|
|
|
if (attribs != INVALID_FILE_ATTRIBUTES &&
|
2012-01-05 18:34:35 +00:00
|
|
|
(attribs & FILE_ATTRIBUTE_DIRECTORY) &&
|
2012-01-11 14:13:14 +00:00
|
|
|
HCR_GetExecuteCommandW(0, L"Folder",
|
2012-01-05 18:34:35 +00:00
|
|
|
sei->lpVerb,
|
|
|
|
buffer, sizeof(buffer))) {
|
2011-05-15 15:55:49 +00:00
|
|
|
SHELL_ArgifyW(wszApplicationName, dwApplicationNameLen,
|
2018-07-12 15:45:43 +00:00
|
|
|
buffer, target, (LPITEMIDLIST)sei->lpIDList, NULL, &resultLen,
|
|
|
|
(sei->lpDirectory && *sei->lpDirectory) ? sei->lpDirectory : NULL);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (resultLen > dwApplicationNameLen)
|
|
|
|
ERR("Argify buffer not large enough... truncating\n");
|
|
|
|
appKnownSingular = FALSE;
|
|
|
|
}
|
|
|
|
sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return appKnownSingular;
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
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)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
UINT_PTR retval;
|
|
|
|
DWORD len;
|
|
|
|
WCHAR *wszQuotedCmd;
|
|
|
|
|
|
|
|
/* Length of quotes plus length of command plus NULL terminator */
|
|
|
|
len = 2 + lstrlenW(wcmd) + 1;
|
|
|
|
if (wszParameters[0])
|
|
|
|
{
|
|
|
|
/* Length of space plus length of parameters */
|
|
|
|
len += 1 + lstrlenW(wszParameters);
|
|
|
|
}
|
|
|
|
wszQuotedCmd = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
/* Must quote to handle case where cmd contains spaces,
|
|
|
|
* else security hole if malicious user creates executable file "C:\\Program"
|
|
|
|
*/
|
2012-01-05 18:34:35 +00:00
|
|
|
strcpyW(wszQuotedCmd, L"\"");
|
2011-05-15 15:55:49 +00:00
|
|
|
strcatW(wszQuotedCmd, wcmd);
|
2012-01-05 18:34:35 +00:00
|
|
|
strcatW(wszQuotedCmd, L"\"");
|
2011-09-02 19:29:30 +00:00
|
|
|
if (wszParameters[0])
|
|
|
|
{
|
2012-05-13 17:47:49 +00:00
|
|
|
strcatW(wszQuotedCmd, L" ");
|
2011-05-15 15:55:49 +00:00
|
|
|
strcatW(wszQuotedCmd, wszParameters);
|
|
|
|
}
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(psei->lpVerb), debugstr_w(wszQuotedCmd), debugstr_w(wszKeyname));
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
if (*wszKeyname)
|
|
|
|
retval = execute_from_key(wszKeyname, wszApplicationName, env, psei->lpParameters, wcmd, execfunc, psei, psei_out);
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
|
|
|
retval = execfunc(wszQuotedCmd, env, FALSE, psei, psei_out);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszQuotedCmd);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
static UINT_PTR SHELL_execute_url(LPCWSTR lpFile, LPCWSTR wcmd, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
UINT_PTR retval;
|
|
|
|
WCHAR *lpstrProtocol;
|
|
|
|
LPCWSTR lpstrRes;
|
|
|
|
INT iSize;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
lpstrRes = strchrW(lpFile, ':');
|
|
|
|
if (lpstrRes)
|
|
|
|
iSize = lpstrRes - lpFile;
|
|
|
|
else
|
|
|
|
iSize = strlenW(lpFile);
|
|
|
|
|
|
|
|
TRACE("Got URL: %s\n", debugstr_w(lpFile));
|
2014-05-22 18:53:44 +00:00
|
|
|
/* Looking for ...<protocol>\shell\<lpVerb>\command */
|
2022-01-09 21:38:31 +00:00
|
|
|
len = iSize + lstrlenW(L"\\shell\\") + lstrlenW(L"\\command") + 1;
|
2014-05-22 18:53:44 +00:00
|
|
|
if (psei->lpVerb && *psei->lpVerb)
|
2011-05-15 15:55:49 +00:00
|
|
|
len += lstrlenW(psei->lpVerb);
|
|
|
|
else
|
2022-01-09 21:38:31 +00:00
|
|
|
len += lstrlenW(L"open");
|
2011-05-15 15:55:49 +00:00
|
|
|
lpstrProtocol = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2012-01-05 18:34:35 +00:00
|
|
|
memcpy(lpstrProtocol, lpFile, iSize * sizeof(WCHAR));
|
2011-05-15 15:55:49 +00:00
|
|
|
lpstrProtocol[iSize] = '\0';
|
2022-01-09 21:38:31 +00:00
|
|
|
strcatW(lpstrProtocol, L"\\shell\\");
|
|
|
|
strcatW(lpstrProtocol, psei->lpVerb && *psei->lpVerb ? psei->lpVerb : L"open");
|
|
|
|
strcatW(lpstrProtocol, L"\\command");
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
retval = execute_from_key(lpstrProtocol, lpFile, NULL, psei->lpParameters,
|
|
|
|
wcmd, execfunc, psei, psei_out);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpstrProtocol);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
static void do_error_dialog(UINT_PTR retval, HWND hwnd, WCHAR* filename)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
WCHAR msg[2048];
|
2011-05-26 21:11:36 +00:00
|
|
|
DWORD_PTR msgArguments[3] = { (DWORD_PTR)filename, 0, 0 };
|
2011-05-26 21:36:39 +00:00
|
|
|
DWORD error_code;
|
|
|
|
|
|
|
|
error_code = GetLastError();
|
2011-05-15 15:55:49 +00:00
|
|
|
if (retval == SE_ERR_NOASSOC)
|
2022-01-09 21:38:31 +00:00
|
|
|
LoadStringW(shell32_hInstance, IDS_SHLEXEC_NOASSOC, msg, ARRAY_SIZE(msg));
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
2011-05-26 21:11:36 +00:00
|
|
|
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
|
|
|
NULL,
|
|
|
|
error_code,
|
|
|
|
LANG_USER_DEFAULT,
|
|
|
|
msg,
|
2022-01-09 21:38:31 +00:00
|
|
|
ARRAY_SIZE(msg),
|
2011-05-26 21:11:36 +00:00
|
|
|
(va_list*)msgArguments);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
MessageBoxW(hwnd, msg, NULL, MB_ICONERROR);
|
|
|
|
}
|
|
|
|
|
2017-06-19 15:04:20 +00:00
|
|
|
static WCHAR *expand_environment( const WCHAR *str )
|
|
|
|
{
|
|
|
|
WCHAR *buf;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
len = ExpandEnvironmentStringsW(str, NULL, 0);
|
|
|
|
if (!len) return NULL;
|
|
|
|
|
|
|
|
buf = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!buf) return NULL;
|
|
|
|
|
|
|
|
len = ExpandEnvironmentStringsW(str, buf, len);
|
|
|
|
if (!len)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* SHELL_execute [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2014-05-22 18:53:44 +00:00
|
|
|
static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
static const DWORD unsupportedFlags =
|
2022-02-03 20:54:12 +00:00
|
|
|
SEE_MASK_ICON | SEE_MASK_HOTKEY |
|
2011-05-15 15:55:49 +00:00
|
|
|
SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
|
2023-02-10 14:56:13 +00:00
|
|
|
SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
WCHAR parametersBuffer[1024], dirBuffer[MAX_PATH], wcmdBuffer[1024];
|
|
|
|
WCHAR *wszApplicationName, *wszParameters, *wszDir, *wcmd;
|
2012-01-05 18:34:35 +00:00
|
|
|
DWORD dwApplicationNameLen = MAX_PATH + 2;
|
2022-01-09 21:38:31 +00:00
|
|
|
DWORD parametersLen = ARRAY_SIZE(parametersBuffer);
|
|
|
|
DWORD dirLen = ARRAY_SIZE(dirBuffer);
|
|
|
|
DWORD wcmdLen = ARRAY_SIZE(wcmdBuffer);
|
2011-05-15 15:55:49 +00:00
|
|
|
DWORD len;
|
2011-09-03 15:37:09 +00:00
|
|
|
SHELLEXECUTEINFOW sei_tmp; /* modifiable copy of SHELLEXECUTEINFO struct */
|
2011-05-15 15:55:49 +00:00
|
|
|
WCHAR wfileName[MAX_PATH];
|
|
|
|
WCHAR *env;
|
2014-05-22 18:53:44 +00:00
|
|
|
WCHAR wszKeyname[256];
|
2011-05-15 15:55:49 +00:00
|
|
|
LPCWSTR lpFile;
|
|
|
|
UINT_PTR retval = SE_ERR_NOASSOC;
|
|
|
|
BOOL appKnownSingular = FALSE;
|
|
|
|
|
|
|
|
/* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
|
|
|
|
sei_tmp = *sei;
|
|
|
|
|
|
|
|
TRACE("mask=0x%08x hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
|
2012-01-05 18:34:35 +00:00
|
|
|
sei_tmp.fMask, sei_tmp.hwnd, debugstr_w(sei_tmp.lpVerb),
|
|
|
|
debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters),
|
|
|
|
debugstr_w(sei_tmp.lpDirectory), sei_tmp.nShow,
|
|
|
|
((sei_tmp.fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME) ?
|
|
|
|
debugstr_w(sei_tmp.lpClass) : "not used");
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
sei->hProcess = NULL;
|
|
|
|
|
|
|
|
/* make copies of all path/command strings */
|
|
|
|
if (!sei_tmp.lpFile)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
wszApplicationName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen * sizeof(WCHAR));
|
2011-05-15 15:55:49 +00:00
|
|
|
*wszApplicationName = '\0';
|
|
|
|
}
|
2017-06-19 15:04:20 +00:00
|
|
|
else if (*sei_tmp.lpFile == '\"' && sei_tmp.lpFile[(len = strlenW(sei_tmp.lpFile))-1] == '\"')
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2017-06-19 15:04:20 +00:00
|
|
|
if(len-1 >= dwApplicationNameLen)
|
|
|
|
dwApplicationNameLen = len;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
wszApplicationName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen * sizeof(WCHAR));
|
2017-06-19 15:04:20 +00:00
|
|
|
memcpy(wszApplicationName, sei_tmp.lpFile + 1, len * sizeof(WCHAR));
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2017-06-19 15:04:20 +00:00
|
|
|
if(len > 2)
|
|
|
|
wszApplicationName[len-2] = '\0';
|
2011-05-15 15:55:49 +00:00
|
|
|
appKnownSingular = TRUE;
|
2011-09-03 15:37:09 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("wszApplicationName=%s\n", debugstr_w(wszApplicationName));
|
2011-09-02 19:29:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
DWORD l = strlenW(sei_tmp.lpFile) + 1;
|
|
|
|
if(l > dwApplicationNameLen) dwApplicationNameLen = l + 1;
|
|
|
|
wszApplicationName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen * sizeof(WCHAR));
|
|
|
|
memcpy(wszApplicationName, sei_tmp.lpFile, l * sizeof(WCHAR));
|
2020-04-25 02:01:20 +00:00
|
|
|
|
|
|
|
if (wszApplicationName[2] == 0 && wszApplicationName[1] == L':' &&
|
|
|
|
((L'A' <= wszApplicationName[0] && wszApplicationName[0] <= L'Z') ||
|
|
|
|
(L'a' <= wszApplicationName[0] && wszApplicationName[0] <= L'z')))
|
|
|
|
{
|
|
|
|
// 'C:' --> 'C:\'
|
|
|
|
PathAddBackslashW(wszApplicationName);
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wszParameters = parametersBuffer;
|
|
|
|
if (sei_tmp.lpParameters)
|
|
|
|
{
|
|
|
|
len = lstrlenW(sei_tmp.lpParameters) + 1;
|
|
|
|
if (len > parametersLen)
|
|
|
|
{
|
|
|
|
wszParameters = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
parametersLen = len;
|
|
|
|
}
|
2011-09-03 15:37:09 +00:00
|
|
|
strcpyW(wszParameters, sei_tmp.lpParameters);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else
|
2012-01-05 18:34:35 +00:00
|
|
|
*wszParameters = L'\0';
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
wszDir = dirBuffer;
|
|
|
|
if (sei_tmp.lpDirectory)
|
|
|
|
{
|
|
|
|
len = lstrlenW(sei_tmp.lpDirectory) + 1;
|
|
|
|
if (len > dirLen)
|
|
|
|
{
|
|
|
|
wszDir = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
dirLen = len;
|
|
|
|
}
|
2011-09-03 15:37:09 +00:00
|
|
|
strcpyW(wszDir, sei_tmp.lpDirectory);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else
|
2012-01-05 18:34:35 +00:00
|
|
|
*wszDir = L'\0';
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/* adjust string pointers to point to the new buffers */
|
|
|
|
sei_tmp.lpFile = wszApplicationName;
|
|
|
|
sei_tmp.lpParameters = wszParameters;
|
|
|
|
sei_tmp.lpDirectory = wszDir;
|
|
|
|
|
|
|
|
if (sei_tmp.fMask & unsupportedFlags)
|
|
|
|
{
|
2022-02-03 20:54:12 +00:00
|
|
|
FIXME("flags ignored: 0x%08x\n", sei_tmp.fMask & unsupportedFlags);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* process the IDList */
|
2022-02-03 20:54:12 +00:00
|
|
|
if (sei_tmp.fMask & SEE_MASK_IDLIST &&
|
|
|
|
(sei_tmp.fMask & SEE_MASK_INVOKEIDLIST) != SEE_MASK_INVOKEIDLIST)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-08-20 00:39:40 +00:00
|
|
|
CComPtr<IShellExecuteHookW> pSEH;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2013-11-11 16:42:16 +00:00
|
|
|
HRESULT hr = SHBindToParent((LPCITEMIDLIST)sei_tmp.lpIDList, IID_PPV_ARG(IShellExecuteHookW, &pSEH), NULL);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = pSEH->Execute(&sei_tmp);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
if (hr == S_OK)
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
2011-05-15 15:55:49 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
if (wszParameters != parametersBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszParameters);
|
|
|
|
if (wszDir != dirBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDir);
|
2011-09-03 15:37:09 +00:00
|
|
|
return TRUE;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2011-09-03 15:37:09 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
SHGetPathFromIDListW((LPCITEMIDLIST)sei_tmp.lpIDList, wszApplicationName);
|
|
|
|
appKnownSingular = TRUE;
|
|
|
|
TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, debugstr_w(wszApplicationName));
|
|
|
|
}
|
|
|
|
|
2017-06-19 15:04:20 +00:00
|
|
|
if (sei_tmp.fMask & SEE_MASK_DOENVSUBST)
|
|
|
|
{
|
|
|
|
WCHAR *tmp;
|
|
|
|
|
|
|
|
tmp = expand_environment(sei_tmp.lpFile);
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
sei_tmp.lpFile = wszApplicationName = tmp;
|
|
|
|
|
|
|
|
tmp = expand_environment(sei_tmp.lpDirectory);
|
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (wszDir != dirBuffer) HeapFree(GetProcessHeap(), 0, wszDir);
|
|
|
|
sei_tmp.lpDirectory = wszDir = tmp;
|
|
|
|
}
|
|
|
|
|
2022-02-03 20:54:12 +00:00
|
|
|
if ((sei_tmp.fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST)
|
|
|
|
{
|
2022-02-06 20:08:52 +00:00
|
|
|
HRESULT hr = ShellExecute_ContextMenuVerb(&sei_tmp);
|
2022-02-03 20:54:12 +00:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
sei->hInstApp = (HINSTANCE)42;
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
if (wszParameters != parametersBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszParameters);
|
|
|
|
if (wszDir != dirBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDir);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-06 20:08:52 +00:00
|
|
|
if (ERROR_SUCCESS == ShellExecute_FromContextMenuHandlers(&sei_tmp))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
sei->hInstApp = (HINSTANCE) 33;
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
if (wszParameters != parametersBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszParameters);
|
|
|
|
if (wszDir != dirBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDir);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sei_tmp.fMask & SEE_MASK_CLASSALL)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
retval = SHELL_execute_class(wszApplicationName, &sei_tmp, sei, execfunc);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (retval <= 32 && !(sei_tmp.fMask & SEE_MASK_FLAG_NO_UI))
|
|
|
|
{
|
|
|
|
OPENASINFO Info;
|
|
|
|
|
|
|
|
//FIXME
|
|
|
|
// need full path
|
|
|
|
|
|
|
|
Info.pcszFile = wszApplicationName;
|
|
|
|
Info.pcszClass = NULL;
|
|
|
|
Info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
|
|
|
|
|
|
|
|
//if (SHOpenWithDialog(sei_tmp.hwnd, &Info) != S_OK)
|
2014-05-31 16:58:03 +00:00
|
|
|
DBG_UNREFERENCED_LOCAL_VARIABLE(Info);
|
2012-01-05 18:34:35 +00:00
|
|
|
do_error_dialog(retval, sei_tmp.hwnd, wszApplicationName);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
if (wszParameters != parametersBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszParameters);
|
|
|
|
if (wszDir != dirBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDir);
|
|
|
|
return retval > 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Has the IDList not yet been translated? */
|
|
|
|
if (sei_tmp.fMask & SEE_MASK_IDLIST)
|
|
|
|
{
|
|
|
|
appKnownSingular = SHELL_translate_idlist( &sei_tmp, wszParameters,
|
2012-01-05 18:34:35 +00:00
|
|
|
parametersLen,
|
|
|
|
wszApplicationName,
|
|
|
|
dwApplicationNameLen );
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
/* convert file URLs */
|
|
|
|
if (UrlIsFileUrlW(sei_tmp.lpFile))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
LPWSTR buf;
|
2014-05-22 18:53:44 +00:00
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
size = MAX_PATH;
|
|
|
|
buf = static_cast<LPWSTR>(HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)));
|
|
|
|
if (!buf || FAILED(PathCreateFromUrlW(sei_tmp.lpFile, buf, &size, 0)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return SE_ERR_OOM;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
wszApplicationName = buf;
|
|
|
|
sei_tmp.lpFile = wszApplicationName;
|
|
|
|
}
|
2014-05-22 18:53:44 +00:00
|
|
|
else /* or expand environment strings (not both!) */
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
len = ExpandEnvironmentStringsW(sei_tmp.lpFile, NULL, 0);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
LPWSTR buf;
|
2014-05-22 18:53:44 +00:00
|
|
|
buf = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
ExpandEnvironmentStringsW(sei_tmp.lpFile, buf, len + 1);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
wszApplicationName = buf;
|
|
|
|
/* appKnownSingular unmodified */
|
|
|
|
|
|
|
|
sei_tmp.lpFile = wszApplicationName;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*sei_tmp.lpDirectory)
|
|
|
|
{
|
|
|
|
len = ExpandEnvironmentStringsW(sei_tmp.lpDirectory, NULL, 0);
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
LPWSTR buf;
|
|
|
|
len++;
|
2012-01-05 18:34:35 +00:00
|
|
|
buf = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2011-05-15 15:55:49 +00:00
|
|
|
ExpandEnvironmentStringsW(sei_tmp.lpDirectory, buf, len);
|
|
|
|
if (wszDir != dirBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDir);
|
|
|
|
wszDir = buf;
|
|
|
|
sei_tmp.lpDirectory = wszDir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Else, try to execute the filename */
|
2012-01-05 18:34:35 +00:00
|
|
|
TRACE("execute: %s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/* separate out command line arguments from executable file name */
|
2011-09-02 19:29:30 +00:00
|
|
|
if (!*sei_tmp.lpParameters && !appKnownSingular)
|
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
/* If the executable path is quoted, handle the rest of the command line as parameters. */
|
2012-01-05 18:34:35 +00:00
|
|
|
if (sei_tmp.lpFile[0] == L'"')
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1;
|
|
|
|
LPWSTR dst = wfileName;
|
|
|
|
LPWSTR end;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-03 15:37:09 +00:00
|
|
|
/* copy the unquoted executable path to 'wfileName' */
|
2012-01-05 18:34:35 +00:00
|
|
|
while(*src && *src != L'"')
|
|
|
|
*dst++ = *src++;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
*dst = L'\0';
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
if (*src == L'"')
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
2011-09-03 15:37:09 +00:00
|
|
|
end = ++src;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2017-06-19 15:04:20 +00:00
|
|
|
while(isspaceW(*src))
|
2011-09-03 15:37:09 +00:00
|
|
|
++src;
|
|
|
|
}
|
2011-09-02 19:29:30 +00:00
|
|
|
else
|
2011-09-03 15:37:09 +00:00
|
|
|
end = src;
|
|
|
|
|
|
|
|
/* copy the parameter string to 'wszParameters' */
|
|
|
|
strcpyW(wszParameters, src);
|
|
|
|
|
|
|
|
/* terminate previous command string after the quote character */
|
2012-01-05 18:34:35 +00:00
|
|
|
*end = L'\0';
|
2014-05-22 18:53:44 +00:00
|
|
|
lpFile = wfileName;
|
2011-09-03 15:37:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
lpFile = sei_tmp.lpFile;
|
2011-09-03 15:37:09 +00:00
|
|
|
}
|
2011-09-02 19:29:30 +00:00
|
|
|
}
|
|
|
|
else
|
2014-05-22 18:53:44 +00:00
|
|
|
lpFile = sei_tmp.lpFile;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
wcmd = wcmdBuffer;
|
|
|
|
|
2022-02-15 23:54:20 +00:00
|
|
|
/* Only execute if it has an executable extension */
|
|
|
|
if (PathIsExeW(lpFile))
|
2011-09-02 19:29:30 +00:00
|
|
|
{
|
2022-02-15 23:54:20 +00:00
|
|
|
len = lstrlenW(wszApplicationName) + 3;
|
|
|
|
if (sei_tmp.lpParameters[0])
|
|
|
|
len += 1 + lstrlenW(wszParameters);
|
|
|
|
if (len > wcmdLen)
|
|
|
|
{
|
|
|
|
wcmd = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
wcmdLen = len;
|
|
|
|
}
|
|
|
|
swprintf(wcmd, L"\"%s\"", wszApplicationName);
|
|
|
|
if (sei_tmp.lpParameters[0])
|
|
|
|
{
|
|
|
|
strcatW(wcmd, L" ");
|
|
|
|
strcatW(wcmd, wszParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
|
|
|
|
if (retval > 32)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
if (wszParameters != parametersBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszParameters);
|
|
|
|
if (wszDir != dirBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDir);
|
|
|
|
if (wcmd != wcmdBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wcmd);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Else, try to find the executable */
|
2012-01-05 18:34:35 +00:00
|
|
|
wcmd[0] = L'\0';
|
2014-05-22 18:53:44 +00:00
|
|
|
retval = SHELL_FindExecutable(sei_tmp.lpDirectory, lpFile, sei_tmp.lpVerb, wcmd, wcmdLen, wszKeyname, &env, (LPITEMIDLIST)sei_tmp.lpIDList, sei_tmp.lpParameters);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (retval > 32) /* Found */
|
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
retval = SHELL_quote_and_execute(wcmd, wszParameters, wszKeyname,
|
2012-01-05 18:34:35 +00:00
|
|
|
wszApplicationName, env, &sei_tmp,
|
|
|
|
sei, execfunc);
|
|
|
|
HeapFree(GetProcessHeap(), 0, env);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else if (PathIsDirectoryW(lpFile))
|
|
|
|
{
|
|
|
|
WCHAR wExec[MAX_PATH];
|
2012-01-05 18:34:35 +00:00
|
|
|
WCHAR * lpQuotedFile = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (strlenW(lpFile) + 3));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (lpQuotedFile)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
retval = SHELL_FindExecutable(sei_tmp.lpDirectory, L"explorer",
|
2022-01-09 21:38:31 +00:00
|
|
|
L"open", wExec, MAX_PATH,
|
2012-01-05 18:34:35 +00:00
|
|
|
NULL, &env, NULL, NULL);
|
2011-05-15 15:55:49 +00:00
|
|
|
if (retval > 32)
|
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
swprintf(lpQuotedFile, L"\"%s\"", lpFile);
|
|
|
|
retval = SHELL_quote_and_execute(wExec, lpQuotedFile,
|
2014-05-22 18:53:44 +00:00
|
|
|
wszKeyname,
|
2012-01-05 18:34:35 +00:00
|
|
|
wszApplicationName, env,
|
|
|
|
&sei_tmp, sei, execfunc);
|
|
|
|
HeapFree(GetProcessHeap(), 0, env);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2012-01-05 18:34:35 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpQuotedFile);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
retval = 0; /* Out of memory */
|
|
|
|
}
|
|
|
|
else if (PathIsURLW(lpFile)) /* File not found, check for URL */
|
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
retval = SHELL_execute_url(lpFile, wcmd, &sei_tmp, sei, execfunc );
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
/* Check if file specified is in the form www.??????.*** */
|
2012-01-05 18:34:35 +00:00
|
|
|
else if (!strncmpiW(lpFile, L"www", 3))
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2014-05-22 18:53:44 +00:00
|
|
|
/* if so, prefix lpFile with http:// and call ShellExecute */
|
2011-05-15 15:55:49 +00:00
|
|
|
WCHAR lpstrTmpFile[256];
|
2012-01-05 18:34:35 +00:00
|
|
|
strcpyW(lpstrTmpFile, L"http://");
|
2011-05-15 15:55:49 +00:00
|
|
|
strcatW(lpstrTmpFile, lpFile);
|
|
|
|
retval = (UINT_PTR)ShellExecuteW(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("retval %lu\n", retval);
|
|
|
|
|
|
|
|
if (retval <= 32 && !(sei_tmp.fMask & SEE_MASK_FLAG_NO_UI))
|
|
|
|
{
|
|
|
|
OPENASINFO Info;
|
|
|
|
|
|
|
|
//FIXME
|
|
|
|
// need full path
|
|
|
|
|
|
|
|
Info.pcszFile = wszApplicationName;
|
|
|
|
Info.pcszClass = NULL;
|
|
|
|
Info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
|
|
|
|
|
|
|
|
//if (SHOpenWithDialog(sei_tmp.hwnd, &Info) != S_OK)
|
2014-05-31 16:58:03 +00:00
|
|
|
DBG_UNREFERENCED_LOCAL_VARIABLE(Info);
|
2012-01-05 18:34:35 +00:00
|
|
|
do_error_dialog(retval, sei_tmp.hwnd, wszApplicationName);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszApplicationName);
|
|
|
|
if (wszParameters != parametersBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszParameters);
|
|
|
|
if (wszDir != dirBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wszDir);
|
|
|
|
if (wcmd != wcmdBuffer)
|
|
|
|
HeapFree(GetProcessHeap(), 0, wcmd);
|
|
|
|
|
|
|
|
sei->hInstApp = (HINSTANCE)(retval > 32 ? 33 : retval);
|
|
|
|
|
|
|
|
return retval > 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* ShellExecuteA [SHELL32.290]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2014-05-22 18:53:44 +00:00
|
|
|
HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpVerb, LPCSTR lpFile,
|
2012-01-05 18:34:35 +00:00
|
|
|
LPCSTR lpParameters, LPCSTR lpDirectory, INT iShowCmd)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
SHELLEXECUTEINFOA sei;
|
|
|
|
|
|
|
|
TRACE("%p,%s,%s,%s,%s,%d\n",
|
2014-05-22 18:53:44 +00:00
|
|
|
hWnd, debugstr_a(lpVerb), debugstr_a(lpFile),
|
2011-05-15 15:55:49 +00:00
|
|
|
debugstr_a(lpParameters), debugstr_a(lpDirectory), iShowCmd);
|
|
|
|
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.fMask = SEE_MASK_FLAG_NO_UI;
|
|
|
|
sei.hwnd = hWnd;
|
2014-05-22 18:53:44 +00:00
|
|
|
sei.lpVerb = lpVerb;
|
2011-05-15 15:55:49 +00:00
|
|
|
sei.lpFile = lpFile;
|
|
|
|
sei.lpParameters = lpParameters;
|
|
|
|
sei.lpDirectory = lpDirectory;
|
|
|
|
sei.nShow = iShowCmd;
|
|
|
|
sei.lpIDList = 0;
|
|
|
|
sei.lpClass = 0;
|
|
|
|
sei.hkeyClass = 0;
|
|
|
|
sei.dwHotKey = 0;
|
|
|
|
sei.hProcess = 0;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
ShellExecuteExA(&sei);
|
2011-05-15 15:55:49 +00:00
|
|
|
return sei.hInstApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* ShellExecuteExA [SHELL32.292]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
*/
|
2014-03-05 12:12:05 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
DECLSPEC_HOTPATCH
|
|
|
|
ShellExecuteExA(LPSHELLEXECUTEINFOA sei)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
SHELLEXECUTEINFOW seiW;
|
|
|
|
BOOL ret;
|
|
|
|
WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL, *wClass = NULL;
|
|
|
|
|
|
|
|
TRACE("%p\n", sei);
|
|
|
|
|
|
|
|
memcpy(&seiW, sei, sizeof(SHELLEXECUTEINFOW));
|
|
|
|
|
|
|
|
if (sei->lpVerb)
|
2011-09-03 15:37:09 +00:00
|
|
|
seiW.lpVerb = __SHCloneStrAtoW(&wVerb, sei->lpVerb);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (sei->lpFile)
|
|
|
|
seiW.lpFile = __SHCloneStrAtoW(&wFile, sei->lpFile);
|
|
|
|
|
|
|
|
if (sei->lpParameters)
|
|
|
|
seiW.lpParameters = __SHCloneStrAtoW(&wParameters, sei->lpParameters);
|
|
|
|
|
|
|
|
if (sei->lpDirectory)
|
|
|
|
seiW.lpDirectory = __SHCloneStrAtoW(&wDirectory, sei->lpDirectory);
|
|
|
|
|
|
|
|
if ((sei->fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME && sei->lpClass)
|
|
|
|
seiW.lpClass = __SHCloneStrAtoW(&wClass, sei->lpClass);
|
|
|
|
else
|
|
|
|
seiW.lpClass = NULL;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
ret = SHELL_execute(&seiW, SHELL_ExecuteW);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
sei->hInstApp = seiW.hInstApp;
|
|
|
|
|
|
|
|
if (sei->fMask & SEE_MASK_NOCLOSEPROCESS)
|
|
|
|
sei->hProcess = seiW.hProcess;
|
|
|
|
|
|
|
|
SHFree(wVerb);
|
|
|
|
SHFree(wFile);
|
|
|
|
SHFree(wParameters);
|
|
|
|
SHFree(wDirectory);
|
|
|
|
SHFree(wClass);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* ShellExecuteExW [SHELL32.293]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
*/
|
2014-03-05 12:12:05 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
DECLSPEC_HOTPATCH
|
|
|
|
ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2012-01-05 18:34:35 +00:00
|
|
|
return SHELL_execute(sei, SHELL_ExecuteW);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* ShellExecuteW [SHELL32.294]
|
2011-05-15 15:55:49 +00:00
|
|
|
* from shellapi.h
|
2014-05-22 18:53:44 +00:00
|
|
|
* WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpVerb,
|
2011-05-15 15:55:49 +00:00
|
|
|
* LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
|
|
|
|
*/
|
2014-05-22 18:53:44 +00:00
|
|
|
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile,
|
2011-05-15 15:55:49 +00:00
|
|
|
LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
|
|
|
|
{
|
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.fMask = SEE_MASK_FLAG_NO_UI;
|
|
|
|
sei.hwnd = hwnd;
|
2014-05-22 18:53:44 +00:00
|
|
|
sei.lpVerb = lpVerb;
|
2011-05-15 15:55:49 +00:00
|
|
|
sei.lpFile = lpFile;
|
|
|
|
sei.lpParameters = lpParameters;
|
|
|
|
sei.lpDirectory = lpDirectory;
|
|
|
|
sei.nShow = nShowCmd;
|
|
|
|
sei.lpIDList = 0;
|
|
|
|
sei.lpClass = 0;
|
|
|
|
sei.hkeyClass = 0;
|
|
|
|
sei.dwHotKey = 0;
|
|
|
|
sei.hProcess = 0;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
SHELL_execute(&sei, SHELL_ExecuteW);
|
2011-05-15 15:55:49 +00:00
|
|
|
return sei.hInstApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2011-09-03 15:37:09 +00:00
|
|
|
* WOWShellExecute [SHELL32.@]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* FIXME: the callback function most likely doesn't work the same way on Windows.
|
|
|
|
*/
|
2014-05-22 18:53:44 +00:00
|
|
|
EXTERN_C HINSTANCE WINAPI WOWShellExecute(HWND hWnd, LPCSTR lpVerb, LPCSTR lpFile,
|
2012-01-05 18:34:35 +00:00
|
|
|
LPCSTR lpParameters, LPCSTR lpDirectory, INT iShowCmd, void *callback)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
SHELLEXECUTEINFOW seiW;
|
|
|
|
WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL;
|
|
|
|
HANDLE hProcess = 0;
|
|
|
|
|
2014-05-22 18:53:44 +00:00
|
|
|
seiW.lpVerb = lpVerb ? __SHCloneStrAtoW(&wVerb, lpVerb) : NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
seiW.lpFile = lpFile ? __SHCloneStrAtoW(&wFile, lpFile) : NULL;
|
|
|
|
seiW.lpParameters = lpParameters ? __SHCloneStrAtoW(&wParameters, lpParameters) : NULL;
|
|
|
|
seiW.lpDirectory = lpDirectory ? __SHCloneStrAtoW(&wDirectory, lpDirectory) : NULL;
|
|
|
|
|
|
|
|
seiW.cbSize = sizeof(seiW);
|
|
|
|
seiW.fMask = 0;
|
|
|
|
seiW.hwnd = hWnd;
|
|
|
|
seiW.nShow = iShowCmd;
|
|
|
|
seiW.lpIDList = 0;
|
|
|
|
seiW.lpClass = 0;
|
|
|
|
seiW.hkeyClass = 0;
|
|
|
|
seiW.dwHotKey = 0;
|
|
|
|
seiW.hProcess = hProcess;
|
|
|
|
|
2012-01-05 18:34:35 +00:00
|
|
|
SHELL_execute(&seiW, (SHELL_ExecuteW32)callback);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
SHFree(wVerb);
|
|
|
|
SHFree(wFile);
|
|
|
|
SHFree(wParameters);
|
|
|
|
SHFree(wDirectory);
|
|
|
|
return seiW.hInstApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2018-06-24 17:46:06 +00:00
|
|
|
* OpenAs_RunDLLW [SHELL32.@]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2018-06-24 17:46:06 +00:00
|
|
|
EXTERN_C void WINAPI
|
|
|
|
OpenAs_RunDLLW(HWND hwnd, HINSTANCE hinst, LPCWSTR cmdline, int cmdshow)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2018-06-24 17:46:06 +00:00
|
|
|
OPENASINFO info;
|
|
|
|
TRACE("%p, %p, %s, %d\n", hwnd, hinst, debugstr_w(cmdline), cmdshow);
|
|
|
|
|
|
|
|
ZeroMemory(&info, sizeof(info));
|
|
|
|
info.pcszFile = cmdline;
|
|
|
|
info.pcszClass = NULL;
|
|
|
|
info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_REGISTER_EXT | OAIF_EXEC;
|
|
|
|
|
|
|
|
SHOpenWithDialog(hwnd, &info);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2018-06-24 17:46:06 +00:00
|
|
|
* OpenAs_RunDLLA [SHELL32.@]
|
2011-05-15 15:55:49 +00:00
|
|
|
*/
|
2018-06-24 17:46:06 +00:00
|
|
|
EXTERN_C void WINAPI
|
|
|
|
OpenAs_RunDLLA(HWND hwnd, HINSTANCE hinst, LPCSTR cmdline, int cmdshow)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2018-06-24 17:46:06 +00:00
|
|
|
LPWSTR pszCmdLineW = NULL;
|
|
|
|
TRACE("%p, %p, %s, %d\n", hwnd, hinst, debugstr_a(cmdline), cmdshow);
|
|
|
|
|
2018-07-06 19:43:57 +00:00
|
|
|
if (cmdline)
|
|
|
|
__SHCloneStrAtoW(&pszCmdLineW, cmdline);
|
2018-06-24 17:46:06 +00:00
|
|
|
OpenAs_RunDLLW(hwnd, hinst, pszCmdLineW, cmdshow);
|
|
|
|
SHFree(pszCmdLineW);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
2018-08-05 11:39:17 +00:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
static LPCWSTR
|
|
|
|
SplitParams(LPCWSTR psz, LPWSTR pszArg0, size_t cchArg0)
|
|
|
|
{
|
|
|
|
LPCWSTR pch;
|
|
|
|
size_t ich = 0;
|
|
|
|
if (*psz == L'"')
|
|
|
|
{
|
|
|
|
// 1st argument is quoted. the string in quotes is quoted 1st argument.
|
|
|
|
// [pch] --> [pszArg0+ich]
|
|
|
|
for (pch = psz + 1; *pch && ich + 1 < cchArg0; ++ich, ++pch)
|
|
|
|
{
|
|
|
|
if (*pch == L'"' && pch[1] == L'"')
|
|
|
|
{
|
|
|
|
// doubled double quotations found!
|
|
|
|
pszArg0[ich] = L'"';
|
|
|
|
}
|
|
|
|
else if (*pch == L'"')
|
|
|
|
{
|
|
|
|
// single double quotation found!
|
|
|
|
++pch;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// otherwise
|
|
|
|
pszArg0[ich] = *pch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 1st argument is unquoted. non-space sequence is 1st argument.
|
|
|
|
// [pch] --> [pszArg0+ich]
|
|
|
|
for (pch = psz; *pch && !iswspace(*pch) && ich + 1 < cchArg0; ++ich, ++pch)
|
|
|
|
{
|
|
|
|
pszArg0[ich] = *pch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pszArg0[ich] = 0;
|
|
|
|
|
|
|
|
// skip space
|
|
|
|
while (iswspace(*pch))
|
|
|
|
++pch;
|
|
|
|
|
|
|
|
return pch;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI ShellExecCmdLine(
|
|
|
|
HWND hwnd,
|
|
|
|
LPCWSTR pwszCommand,
|
|
|
|
LPCWSTR pwszStartDir,
|
|
|
|
int nShow,
|
|
|
|
LPVOID pUnused,
|
|
|
|
DWORD dwSeclFlags)
|
|
|
|
{
|
|
|
|
SHELLEXECUTEINFOW info;
|
|
|
|
DWORD dwSize, dwError, dwType, dwFlags = SEE_MASK_DOENVSUBST | SEE_MASK_NOASYNC;
|
|
|
|
LPCWSTR pszVerb = NULL;
|
|
|
|
WCHAR szFile[MAX_PATH], szFile2[MAX_PATH];
|
|
|
|
HRESULT hr;
|
|
|
|
LPCWSTR pchParams;
|
|
|
|
LPWSTR lpCommand = NULL;
|
|
|
|
|
|
|
|
if (pwszCommand == NULL)
|
|
|
|
RaiseException(EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE,
|
|
|
|
1, (ULONG_PTR*)pwszCommand);
|
|
|
|
|
|
|
|
__SHCloneStrW(&lpCommand, pwszCommand);
|
|
|
|
StrTrimW(lpCommand, L" \t");
|
|
|
|
|
|
|
|
if (dwSeclFlags & SECL_NO_UI)
|
|
|
|
dwFlags |= SEE_MASK_FLAG_NO_UI;
|
|
|
|
if (dwSeclFlags & SECL_LOG_USAGE)
|
|
|
|
dwFlags |= SEE_MASK_FLAG_LOG_USAGE;
|
|
|
|
if (dwSeclFlags & SECL_USE_IDLIST)
|
|
|
|
dwFlags |= SEE_MASK_INVOKEIDLIST;
|
|
|
|
|
|
|
|
if (dwSeclFlags & SECL_RUNAS)
|
|
|
|
{
|
|
|
|
dwSize = 0;
|
|
|
|
hr = AssocQueryStringW(0, ASSOCSTR_COMMAND, lpCommand, L"RunAs", NULL, &dwSize);
|
|
|
|
if (SUCCEEDED(hr) && dwSize != 0)
|
|
|
|
{
|
|
|
|
pszVerb = L"runas";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 13:37:51 +00:00
|
|
|
if (PathIsURLW(lpCommand) || UrlIsW(lpCommand, URLIS_APPLIABLE))
|
2018-08-05 11:39:17 +00:00
|
|
|
{
|
|
|
|
StringCchCopyW(szFile, _countof(szFile), lpCommand);
|
|
|
|
pchParams = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-10 15:05:11 +00:00
|
|
|
PCWSTR apPathList[2];
|
|
|
|
|
2018-08-05 11:39:17 +00:00
|
|
|
pchParams = SplitParams(lpCommand, szFile, _countof(szFile));
|
2018-12-17 13:42:18 +00:00
|
|
|
if (szFile[0] != UNICODE_NULL && szFile[1] == L':' &&
|
|
|
|
szFile[2] == UNICODE_NULL)
|
|
|
|
{
|
|
|
|
PathAddBackslashW(szFile);
|
|
|
|
}
|
2020-03-01 10:32:33 +00:00
|
|
|
|
|
|
|
WCHAR szCurDir[MAX_PATH];
|
|
|
|
GetCurrentDirectoryW(_countof(szCurDir), szCurDir);
|
|
|
|
if (pwszStartDir)
|
|
|
|
{
|
|
|
|
SetCurrentDirectoryW(pwszStartDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PathIsRelativeW(szFile) &&
|
|
|
|
GetFullPathNameW(szFile, _countof(szFile2), szFile2, NULL) &&
|
|
|
|
PathFileExistsW(szFile2))
|
|
|
|
{
|
|
|
|
StringCchCopyW(szFile, _countof(szFile), szFile2);
|
|
|
|
}
|
2018-08-05 11:39:17 +00:00
|
|
|
|
2023-02-10 15:05:11 +00:00
|
|
|
apPathList[0] = pwszStartDir;
|
|
|
|
apPathList[1] = NULL;
|
|
|
|
PathFindOnPathExW(szFile, apPathList, WHICH_DEFAULT);
|
2020-03-01 10:32:33 +00:00
|
|
|
|
2018-08-05 11:39:17 +00:00
|
|
|
if (!(dwSeclFlags & SECL_ALLOW_NONEXE))
|
|
|
|
{
|
|
|
|
if (!GetBinaryTypeW(szFile, &dwType))
|
|
|
|
{
|
|
|
|
SHFree(lpCommand);
|
|
|
|
|
|
|
|
if (!(dwSeclFlags & SECL_NO_UI))
|
|
|
|
{
|
|
|
|
WCHAR szText[128 + MAX_PATH], szFormat[128];
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILE_NOT_FOUND, szFormat, _countof(szFormat));
|
|
|
|
StringCchPrintfW(szText, _countof(szText), szFormat, szFile);
|
|
|
|
MessageBoxW(hwnd, szText, NULL, MB_ICONERROR);
|
|
|
|
}
|
|
|
|
return CO_E_APPNOTFOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (GetFileAttributesW(szFile) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
SHFree(lpCommand);
|
|
|
|
|
|
|
|
if (!(dwSeclFlags & SECL_NO_UI))
|
|
|
|
{
|
|
|
|
WCHAR szText[128 + MAX_PATH], szFormat[128];
|
|
|
|
LoadStringW(shell32_hInstance, IDS_FILE_NOT_FOUND, szFormat, _countof(szFormat));
|
|
|
|
StringCchPrintfW(szText, _countof(szText), szFormat, szFile);
|
|
|
|
MessageBoxW(hwnd, szText, NULL, MB_ICONERROR);
|
|
|
|
}
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroMemory(&info, sizeof(info));
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
info.fMask = dwFlags;
|
|
|
|
info.hwnd = hwnd;
|
|
|
|
info.lpVerb = pszVerb;
|
|
|
|
info.lpFile = szFile;
|
|
|
|
info.lpParameters = (pchParams && *pchParams) ? pchParams : NULL;
|
|
|
|
info.lpDirectory = pwszStartDir;
|
|
|
|
info.nShow = nShow;
|
|
|
|
if (ShellExecuteExW(&info))
|
|
|
|
{
|
|
|
|
if (info.lpIDList)
|
|
|
|
CoTaskMemFree(info.lpIDList);
|
|
|
|
|
|
|
|
SHFree(lpCommand);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwError = GetLastError();
|
|
|
|
|
|
|
|
SHFree(lpCommand);
|
|
|
|
|
|
|
|
return HRESULT_FROM_WIN32(dwError);
|
|
|
|
}
|