ReactOS  0.4.14-dev-77-gd9e7c48
shlexec.cpp File Reference
#include "precomp.h"
#include <undocshell.h>
Include dependency graph for shlexec.cpp:

Go to the source code of this file.

Macros

#define SEE_MASK_CLASSALL   (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
 

Typedefs

typedef UINT_PTR(* SHELL_ExecuteW32) (const WCHAR *lpCmd, WCHAR *env, BOOL shWait, const SHELLEXECUTEINFOW *sei, LPSHELLEXECUTEINFOW sei_out)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (exec)
 
static void ParseNoTildeEffect (PWSTR &res, LPCWSTR &args, DWORD &len, DWORD &used, int argNum)
 
static void ParseTildeEffect (PWSTR &res, LPCWSTR &args, DWORD &len, DWORD &used, int argNum)
 
static BOOL SHELL_ArgifyW (WCHAR *out, DWORD len, const WCHAR *fmt, const WCHAR *lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD *out_len, const WCHAR *lpDir)
 
static HRESULT SHELL_GetPathFromIDListForExecuteW (LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
 
static UINT_PTR SHELL_ExecuteW (const WCHAR *lpCmd, WCHAR *env, BOOL shWait, const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
 
static LPWSTR SHELL_BuildEnvW (const WCHAR *path)
 
static BOOL SHELL_TryAppPathW (LPCWSTR szName, LPWSTR lpResult, WCHAR **env)
 
static UINT SHELL_FindExecutableByVerb (LPCWSTR lpVerb, LPWSTR key, LPWSTR classname, LPWSTR command, LONG commandlen)
 
static UINT SHELL_FindExecutable (LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb, LPWSTR lpResult, DWORD resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
 
static HDDEDATA CALLBACK dde_cb (UINT uType, UINT uFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, ULONG_PTR dwData1, ULONG_PTR dwData2)
 
static unsigned dde_connect (const WCHAR *key, const WCHAR *start, WCHAR *ddeexec, const WCHAR *lpFile, WCHAR *env, LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc, const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
 
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)
 
HINSTANCE WINAPI FindExecutableA (LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
 
HINSTANCE WINAPI FindExecutableW (LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
 
static HKEY ShellExecute_GetClassKey (const SHELLEXECUTEINFOW *sei)
 
static IDataObjectshellex_get_dataobj (LPSHELLEXECUTEINFOW sei)
 
static HRESULT shellex_run_context_menu_default (IShellExtInit *obj, LPSHELLEXECUTEINFOW sei)
 
static HRESULT shellex_load_object_and_run (HKEY hkey, LPCGUID guid, LPSHELLEXECUTEINFOW sei)
 
static LONG ShellExecute_FromContextMenu (LPSHELLEXECUTEINFOW sei)
 
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)
 
static UINT_PTR SHELL_execute_class (LPCWSTR wszApplicationName, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc)
 
static BOOL SHELL_translate_idlist (LPSHELLEXECUTEINFOW sei, LPWSTR wszParameters, DWORD parametersLen, LPWSTR wszApplicationName, DWORD dwApplicationNameLen)
 
static UINT_PTR SHELL_execute_url (LPCWSTR lpFile, LPCWSTR wcmd, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc)
 
static void do_error_dialog (UINT_PTR retval, HWND hwnd, WCHAR *filename)
 
static WCHARexpand_environment (const WCHAR *str)
 
static BOOL SHELL_execute (LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
 
HINSTANCE WINAPI ShellExecuteA (HWND hWnd, LPCSTR lpVerb, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT iShowCmd)
 
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
 
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
 
HINSTANCE WINAPI ShellExecuteW (HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
 
EXTERN_C HINSTANCE WINAPI WOWShellExecute (HWND hWnd, LPCSTR lpVerb, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT iShowCmd, void *callback)
 
EXTERN_C void WINAPI OpenAs_RunDLLW (HWND hwnd, HINSTANCE hinst, LPCWSTR cmdline, int cmdshow)
 
EXTERN_C void WINAPI OpenAs_RunDLLA (HWND hwnd, HINSTANCE hinst, LPCSTR cmdline, int cmdshow)
 
static LPCWSTR SplitParams (LPCWSTR psz, LPWSTR pszArg0, size_t cchArg0)
 
HRESULT WINAPI ShellExecCmdLine (HWND hwnd, LPCWSTR pwszCommand, LPCWSTR pwszStartDir, int nShow, LPVOID pUnused, DWORD dwSeclFlags)
 

Variables

static const WCHAR wszOpen [] = L"open"
 
static const WCHAR wszExe [] = L".exe"
 
static const WCHAR wszCom [] = L".com"
 

Macro Definition Documentation

◆ SEE_MASK_CLASSALL

#define SEE_MASK_CLASSALL   (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)

Definition at line 32 of file shlexec.cpp.

Typedef Documentation

◆ SHELL_ExecuteW32

typedef UINT_PTR(* SHELL_ExecuteW32) (const WCHAR *lpCmd, WCHAR *env, BOOL shWait, const SHELLEXECUTEINFOW *sei, LPSHELLEXECUTEINFOW sei_out)

Definition at line 34 of file shlexec.cpp.

Function Documentation

◆ dde_cb()

static HDDEDATA CALLBACK dde_cb ( UINT  uType,
UINT  uFmt,
HCONV  hConv,
HSZ  hsz1,
HSZ  hsz2,
HDDEDATA  hData,
ULONG_PTR  dwData1,
ULONG_PTR  dwData2 
)
static

Definition at line 892 of file shlexec.cpp.

895 {
896  TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
897  uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
898  return NULL;
899 }
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by dde_connect().

◆ dde_connect()

static unsigned dde_connect ( const WCHAR key,
const WCHAR start,
WCHAR ddeexec,
const WCHAR lpFile,
WCHAR env,
LPCWSTR  szCommandline,
LPITEMIDLIST  pidl,
SHELL_ExecuteW32  execfunc,
const SHELLEXECUTEINFOW psei,
LPSHELLEXECUTEINFOW  psei_out 
)
static

Definition at line 910 of file shlexec.cpp.

914 {
915  WCHAR regkey[256];
916  WCHAR * endkey = regkey + wcslen(key);
917  WCHAR app[256], topic[256], ifexec[256], static_res[256];
918  WCHAR * dynamic_res=NULL;
919  WCHAR * res;
920  LONG applen, topiclen, ifexeclen;
921  WCHAR * exec;
922  DWORD ddeInst = 0;
923  DWORD tid;
924  DWORD resultLen, endkeyLen;
925  HSZ hszApp, hszTopic;
926  HCONV hConv;
927  HDDEDATA hDdeData;
928  unsigned ret = SE_ERR_NOASSOC;
929  BOOL unicode = !(GetVersion() & 0x80000000);
930 
931  if (strlenW(key) + 1 > sizeof(regkey) / sizeof(regkey[0]))
932  {
933  FIXME("input parameter %s larger than buffer\n", debugstr_w(key));
934  return 2;
935  }
936  wcscpy(regkey, key);
937  static const WCHAR wApplication[] = L"\\application";
938  endkeyLen = sizeof(regkey) / sizeof(regkey[0]) - (endkey - regkey);
939  if (strlenW(wApplication) + 1 > endkeyLen)
940  {
941  FIXME("endkey %s overruns buffer\n", debugstr_w(wApplication));
942  return 2;
943  }
944  wcscpy(endkey, wApplication);
945  applen = sizeof(app);
946  if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, app, &applen) != ERROR_SUCCESS)
947  {
948  WCHAR command[1024], fullpath[MAX_PATH];
949  static const WCHAR wSo[] = L".so";
950  DWORD sizeSo = sizeof(wSo) / sizeof(WCHAR);
951  LPWSTR ptr = NULL;
952  DWORD ret = 0;
953 
954  /* Get application command from start string and find filename of application */
955  if (*start == '"')
956  {
957  if (strlenW(start + 1) + 1 > sizeof(command) / sizeof(command[0]))
958  {
959  FIXME("size of input parameter %s larger than buffer\n",
960  debugstr_w(start + 1));
961  return 2;
962  }
963  wcscpy(command, start + 1);
964  if ((ptr = wcschr(command, '"')))
965  * ptr = 0;
966  ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath) / sizeof(WCHAR), fullpath, &ptr);
967  }
968  else
969  {
970  LPCWSTR p;
971  LPWSTR space;
972  for (p = start; (space = const_cast<LPWSTR>(strchrW(p, ' '))); p = space + 1)
973  {
974  int idx = space - start;
975  memcpy(command, start, idx * sizeof(WCHAR));
976  command[idx] = '\0';
977  if ((ret = SearchPathW(NULL, command, wszExe, sizeof(fullpath) / sizeof(WCHAR), fullpath, &ptr)))
978  break;
979  }
980  if (!ret)
981  ret = SearchPathW(NULL, start, wszExe, sizeof(fullpath) / sizeof(WCHAR), fullpath, &ptr);
982  }
983 
984  if (!ret)
985  {
986  ERR("Unable to find application path for command %s\n", debugstr_w(start));
987  return ERROR_ACCESS_DENIED;
988  }
989  if (strlenW(ptr) + 1 > sizeof(app) / sizeof(app[0]))
990  {
991  FIXME("size of found path %s larger than buffer\n", debugstr_w(ptr));
992  return 2;
993  }
994  wcscpy(app, ptr);
995 
996  /* Remove extensions (including .so) */
997  ptr = app + wcslen(app) - (sizeSo - 1);
998  if (wcslen(app) >= sizeSo &&
999  !wcscmp(ptr, wSo))
1000  *ptr = 0;
1001 
1002  ptr = const_cast<LPWSTR>(strrchrW(app, '.'));
1003  assert(ptr);
1004  *ptr = 0;
1005  }
1006 
1007  static const WCHAR wTopic[] = L"\\topic";
1008  if (strlenW(wTopic) + 1 > endkeyLen)
1009  {
1010  FIXME("endkey %s overruns buffer\n", debugstr_w(wTopic));
1011  return 2;
1012  }
1013  wcscpy(endkey, wTopic);
1014  topiclen = sizeof(topic);
1015  if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, topic, &topiclen) != ERROR_SUCCESS)
1016  {
1017  wcscpy(topic, L"System");
1018  }
1019 
1020  if (unicode)
1021  {
1023  return 2;
1024  }
1025  else
1026  {
1028  return 2;
1029  }
1030 
1033 
1034  hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
1035  exec = ddeexec;
1036  if (!hConv)
1037  {
1038  TRACE("Launching %s\n", debugstr_w(start));
1039  ret = execfunc(start, env, TRUE, psei, psei_out);
1040  if (ret <= 32)
1041  {
1042  TRACE("Couldn't launch\n");
1043  goto error;
1044  }
1045  hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
1046  if (!hConv)
1047  {
1048  TRACE("Couldn't connect. ret=%d\n", ret);
1051  return 30; /* whatever */
1052  }
1053  static const WCHAR wIfexec[] = L"\\ifexec";
1054  if (strlenW(wIfexec) + 1 > endkeyLen)
1055  {
1056  FIXME("endkey %s overruns buffer\n", debugstr_w(wIfexec));
1057  return 2;
1058  }
1059  strcpyW(endkey, wIfexec);
1060  ifexeclen = sizeof(ifexec);
1061  if (RegQueryValueW(HKEY_CLASSES_ROOT, regkey, ifexec, &ifexeclen) == ERROR_SUCCESS)
1062  {
1063  exec = ifexec;
1064  }
1065  }
1066 
1067  SHELL_ArgifyW(static_res, sizeof(static_res)/sizeof(WCHAR), exec, lpFile, pidl, szCommandline, &resultLen, NULL);
1068  if (resultLen > sizeof(static_res)/sizeof(WCHAR))
1069  {
1070  res = dynamic_res = static_cast<WCHAR *>(HeapAlloc(GetProcessHeap(), 0, resultLen * sizeof(WCHAR)));
1071  SHELL_ArgifyW(dynamic_res, resultLen, exec, lpFile, pidl, szCommandline, NULL, NULL);
1072  }
1073  else
1074  res = static_res;
1075  TRACE("%s %s => %s\n", debugstr_w(exec), debugstr_w(lpFile), debugstr_w(res));
1076 
1077  /* It's documented in the KB 330337 that IE has a bug and returns
1078  * error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
1079  */
1080  if (unicode)
1081  hDdeData = DdeClientTransaction((LPBYTE)res, (strlenW(res) + 1) * sizeof(WCHAR), hConv, 0L, 0, XTYP_EXECUTE, 30000, &tid);
1082  else
1083  {
1084  DWORD lenA = WideCharToMultiByte(CP_ACP, 0, res, -1, NULL, 0, NULL, NULL);
1085  char *resA = (LPSTR)HeapAlloc(GetProcessHeap(), 0, lenA);
1086  WideCharToMultiByte(CP_ACP, 0, res, -1, resA, lenA, NULL, NULL);
1087  hDdeData = DdeClientTransaction( (LPBYTE)resA, lenA, hConv, 0L, 0,
1088  XTYP_EXECUTE, 10000, &tid );
1089  HeapFree(GetProcessHeap(), 0, resA);
1090  }
1091  if (hDdeData)
1092  DdeFreeDataHandle(hDdeData);
1093  else
1094  WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst));
1095  ret = 33;
1096 
1097  HeapFree(GetProcessHeap(), 0, dynamic_res);
1098 
1099  DdeDisconnect(hConv);
1100 
1101 error:
1103 
1104  return ret;
1105 }
#define TRUE
Definition: types.h:120
HCONV WINAPI DdeConnect(DWORD, HSZ, HSZ, PCONVCONTEXT)
Definition: ddeclient.c:84
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
#define error(str)
Definition: mkdosfs.c:1605
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
UINT WINAPI DdeGetLastError(DWORD)
Definition: ddemisc.c:253
static BOOL SHELL_ArgifyW(WCHAR *out, DWORD len, const WCHAR *fmt, const WCHAR *lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD *out_len, const WCHAR *lpDir)
Definition: shlexec.cpp:184
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
#define CP_ACP
Definition: compat.h:99
#define XTYP_EXECUTE
Definition: ddeml.h:185
#define WARN(fmt,...)
Definition: debug.h:111
#define assert(x)
Definition: debug.h:53
char * LPSTR
Definition: xmlstorage.h:182
BOOL WINAPI DdeFreeDataHandle(HDDEDATA)
Definition: ddemisc.c:1461
static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, ULONG_PTR dwData1, ULONG_PTR dwData2)
Definition: shlexec.cpp:892
HDDEDATA WINAPI DdeClientTransaction(LPBYTE, DWORD, HCONV, HSZ, UINT, UINT, DWORD, LPDWORD)
Definition: ddeclient.c:1122
DWORD WINAPI GetVersion(VOID)
Definition: version.c:22
#define ERROR_DDE_FAIL
Definition: winerror.h:678
unsigned char * LPBYTE
Definition: typedefs.h:52
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
#define DMLERR_NO_ERROR
Definition: ddeml.h:242
#define FIXME(fmt,...)
Definition: debug.h:110
static PVOID ptr
Definition: dispmode.c:27
unsigned int idx
Definition: utils.c:41
BOOL WINAPI DdeUninitialize(DWORD)
Definition: ddemisc.c:1112
smooth NULL
Definition: ftsmooth.c:416
static DWORD ddeInst
Definition: shlexec.c:154
#define TRACE(s)
Definition: solgame.cpp:4
BOOL WINAPI DdeDisconnect(HCONV)
Definition: ddeclient.c:1363
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define APPCMD_CLIENTONLY
Definition: ddeml.h:122
__wchar_t WCHAR
Definition: xmlstorage.h:180
LSTATUS WINAPI RegQueryValueW(HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count)
Definition: reg.c:4254
#define MAX_PATH
Definition: compat.h:26
static const WCHAR wszExe[]
Definition: shlexec.cpp:29
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
int ret
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static HSZ hszTopic
Definition: shlexec.c:155
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
WINE_UNICODE_INLINE WCHAR * strrchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:254
#define ERR(fmt,...)
Definition: debug.h:109
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
GLuint start
Definition: gl.h:1545
static const char topic[]
Definition: propsys.c:43
#define CP_WINUNICODE
Definition: ddeml.h:33
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
int command(const char *fmt,...)
Definition: ftp.c:266
GLuint res
Definition: glext.h:9613
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SE_ERR_NOASSOC
Definition: shellapi.h:132
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HSZ WINAPI DdeCreateStringHandleW(DWORD, LPCWSTR, INT)
Definition: ddemisc.c:608
UINT WINAPI DdeInitializeW(LPDWORD, PFNCALLBACK, DWORD, DWORD)
Definition: ddemisc.c:1095
static TfClientId tid
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
UINT WINAPI DdeInitializeA(LPDWORD, PFNCALLBACK, DWORD, DWORD)
Definition: ddemisc.c:1075
Definition: path.c:42

Referenced by execute_from_key().

◆ do_error_dialog()

static void do_error_dialog ( UINT_PTR  retval,
HWND  hwnd,
WCHAR filename 
)
static

Definition at line 1669 of file shlexec.cpp.

1670 {
1671  WCHAR msg[2048];
1672  DWORD_PTR msgArguments[3] = { (DWORD_PTR)filename, 0, 0 };
1673  DWORD error_code;
1674 
1676  if (retval == SE_ERR_NOASSOC)
1678  else
1680  NULL,
1681  error_code,
1683  msg,
1684  sizeof(msg) / sizeof(WCHAR),
1685  (va_list*)msgArguments);
1686 
1688 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define DWORD_PTR
Definition: treelist.c:76
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
const char * filename
Definition: ioapi.h:135
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
static int error_code[8]
Definition: odbccp32.c:62
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define IDS_SHLEXEC_NOASSOC
Definition: shresdef.h:174
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MB_ICONERROR
Definition: winuser.h:781
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define msg(x)
Definition: auth_time.c:54
#define SE_ERR_NOASSOC
Definition: shellapi.h:132
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

Referenced by SHELL_execute().

◆ execute_from_key()

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 
)
static

Definition at line 1110 of file shlexec.cpp.

1114 {
1115  WCHAR cmd[256], param[1024], ddeexec[256];
1116  DWORD cmdlen = sizeof(cmd), ddeexeclen = sizeof(ddeexec);
1117  UINT_PTR retval = SE_ERR_NOASSOC;
1118  DWORD resultLen;
1119  LPWSTR tmp;
1120 
1121  TRACE("%s %s %s %s %s\n", debugstr_w(key), debugstr_w(lpFile), debugstr_w(env),
1122  debugstr_w(szCommandline), debugstr_w(executable_name));
1123 
1124  cmd[0] = '\0';
1125  param[0] = '\0';
1126 
1127  /* Get the application from the registry */
1128  if (RegQueryValueW(HKEY_CLASSES_ROOT, key, cmd, (LONG *)&cmdlen) == ERROR_SUCCESS)
1129  {
1130  TRACE("got cmd: %s\n", debugstr_w(cmd));
1131 
1132  /* Is there a replace() function anywhere? */
1133  cmdlen /= sizeof(WCHAR);
1134  if (cmdlen >= sizeof(cmd) / sizeof(WCHAR))
1135  cmdlen = sizeof(cmd) / sizeof(WCHAR) - 1;
1136  cmd[cmdlen] = '\0';
1137  SHELL_ArgifyW(param, sizeof(param) / sizeof(WCHAR), cmd, lpFile, (LPITEMIDLIST)psei->lpIDList, szCommandline, &resultLen,
1138  (psei->lpDirectory && *psei->lpDirectory) ? psei->lpDirectory : NULL);
1139  if (resultLen > sizeof(param) / sizeof(WCHAR))
1140  ERR("Argify buffer not large enough, truncating\n");
1141  }
1142 
1143  /* Get the parameters needed by the application
1144  from the associated ddeexec key */
1145  tmp = const_cast<LPWSTR>(strstrW(key, L"command"));
1146  assert(tmp);
1147  wcscpy(tmp, L"ddeexec");
1148 
1149  if (RegQueryValueW(HKEY_CLASSES_ROOT, key, ddeexec, (LONG *)&ddeexeclen) == ERROR_SUCCESS)
1150  {
1151  TRACE("Got ddeexec %s => %s\n", debugstr_w(key), debugstr_w(ddeexec));
1152  if (!param[0]) strcpyW(param, executable_name);
1153  retval = dde_connect(key, param, ddeexec, lpFile, env, szCommandline, (LPITEMIDLIST)psei->lpIDList, execfunc, psei, psei_out);
1154  }
1155  else if (param[0])
1156  {
1157  TRACE("executing: %s\n", debugstr_w(param));
1158  retval = execfunc(param, env, FALSE, psei, psei_out);
1159  }
1160  else
1161  WARN("Nothing appropriate found for %s\n", debugstr_w(key));
1162 
1163  return retval;
1164 }
#define ERROR_SUCCESS
Definition: deptool.c:10
Definition: ftp_var.h:139
static BOOL SHELL_ArgifyW(WCHAR *out, DWORD len, const WCHAR *fmt, const WCHAR *lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD *out_len, const WCHAR *lpDir)
Definition: shlexec.cpp:184
#define WARN(fmt,...)
Definition: debug.h:111
#define assert(x)
Definition: debug.h:53
char * cmd
Definition: vfdcmd.c:85
static unsigned dde_connect(const WCHAR *key, const WCHAR *start, WCHAR *ddeexec, const WCHAR *lpFile, WCHAR *env, LPCWSTR szCommandline, LPITEMIDLIST pidl, SHELL_ExecuteW32 execfunc, const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
Definition: shlexec.cpp:910
long LONG
Definition: pedump.c:60
LPCWSTR lpDirectory
Definition: shellapi.h:332
#define debugstr_w
Definition: kernel32.h:32
#define strstrW(d, s)
Definition: unicode.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLfloat param
Definition: glext.h:5796
LSTATUS WINAPI RegQueryValueW(HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count)
Definition: reg.c:4254
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:109
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SE_ERR_NOASSOC
Definition: shellapi.h:132
WCHAR * LPWSTR
Definition: xmlstorage.h:184
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
Definition: path.c:42

Referenced by SHELL_execute_url(), and SHELL_quote_and_execute().

◆ expand_environment()

static WCHAR* expand_environment ( const WCHAR str)
static

Definition at line 1690 of file shlexec.cpp.

1691 {
1692  WCHAR *buf;
1693  DWORD len;
1694 
1696  if (!len) return NULL;
1697 
1698  buf = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1699  if (!buf) return NULL;
1700 
1702  if (!len)
1703  {
1704  HeapFree(GetProcessHeap(), 0, buf);
1705  return NULL;
1706  }
1707  return buf;
1708 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by SHELL_execute().

◆ FindExecutableA()

HINSTANCE WINAPI FindExecutableA ( LPCSTR  lpFile,
LPCSTR  lpDirectory,
LPSTR  lpResult 
)

Definition at line 1169 of file shlexec.cpp.

1170 {
1171  HINSTANCE retval;
1172  WCHAR *wFile = NULL, *wDirectory = NULL;
1173  WCHAR wResult[MAX_PATH];
1174 
1175  if (lpFile) __SHCloneStrAtoW(&wFile, lpFile);
1176  if (lpDirectory) __SHCloneStrAtoW(&wDirectory, lpDirectory);
1177 
1178  retval = FindExecutableW(wFile, wDirectory, wResult);
1179  WideCharToMultiByte(CP_ACP, 0, wResult, -1, lpResult, MAX_PATH, NULL, NULL);
1180  SHFree(wFile);
1181  SHFree(wDirectory);
1182 
1183  TRACE("returning %s\n", lpResult);
1184  return retval;
1185 }
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:482
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
Definition: shlexec.cpp:1212
static __inline LPWSTR __SHCloneStrAtoW(WCHAR **target, const char *source)
Definition: shell32_main.h:160
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331

Referenced by START_TEST(), test_fileurls(), and test_find_executable().

◆ FindExecutableW()

HINSTANCE WINAPI FindExecutableW ( LPCWSTR  lpFile,
LPCWSTR  lpDirectory,
LPWSTR  lpResult 
)

Definition at line 1212 of file shlexec.cpp.

1213 {
1214  UINT_PTR retval = SE_ERR_NOASSOC;
1215  WCHAR old_dir[1024];
1216  WCHAR res[MAX_PATH];
1217 
1218  TRACE("File %s, Dir %s\n", debugstr_w(lpFile), debugstr_w(lpDirectory));
1219 
1220  lpResult[0] = '\0'; /* Start off with an empty return string */
1221  if (lpFile == NULL)
1222  return (HINSTANCE)SE_ERR_FNF;
1223 
1224  if (lpDirectory)
1225  {
1226  GetCurrentDirectoryW(sizeof(old_dir) / sizeof(WCHAR), old_dir);
1228  }
1229 
1231  if (retval > 32)
1232  strcpyW(lpResult, res);
1233 
1234  TRACE("returning %s\n", debugstr_w(lpResult));
1235  if (lpDirectory)
1236  SetCurrentDirectoryW(old_dir);
1237  return (HINSTANCE)retval;
1238 }
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:413
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb, LPWSTR lpResult, DWORD resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
Definition: shlexec.cpp:697
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:482
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
static const WCHAR wszOpen[]
Definition: shlexec.cpp:28
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
#define SE_ERR_FNF
Definition: shellapi.h:122
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248
GLuint res
Definition: glext.h:9613
#define SE_ERR_NOASSOC
Definition: shellapi.h:132

Referenced by ExtractAssociatedIconW(), FindExecutableA(), and CShellLink::OnCommand().

◆ OpenAs_RunDLLA()

EXTERN_C void WINAPI OpenAs_RunDLLA ( HWND  hwnd,
HINSTANCE  hinst,
LPCSTR  cmdline,
int  cmdshow 
)

Definition at line 2289 of file shlexec.cpp.

2290 {
2291  LPWSTR pszCmdLineW = NULL;
2292  TRACE("%p, %p, %s, %d\n", hwnd, hinst, debugstr_a(cmdline), cmdshow);
2293 
2294  if (cmdline)
2295  __SHCloneStrAtoW(&pszCmdLineW, cmdline);
2296  OpenAs_RunDLLW(hwnd, hinst, pszCmdLineW, cmdshow);
2297  SHFree(pszCmdLineW);
2298 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
EXTERN_C void WINAPI OpenAs_RunDLLW(HWND hwnd, HINSTANCE hinst, LPCWSTR cmdline, int cmdshow)
Definition: shlexec.cpp:2272
TCHAR * cmdline
Definition: stretchblt.cpp:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
static __inline LPWSTR __SHCloneStrAtoW(WCHAR **target, const char *source)
Definition: shell32_main.h:160
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331
static HINSTANCE hinst
Definition: edit.c:551
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ OpenAs_RunDLLW()

EXTERN_C void WINAPI OpenAs_RunDLLW ( HWND  hwnd,
HINSTANCE  hinst,
LPCWSTR  cmdline,
int  cmdshow 
)

Definition at line 2272 of file shlexec.cpp.

2273 {
2274  OPENASINFO info;
2275  TRACE("%p, %p, %s, %d\n", hwnd, hinst, debugstr_w(cmdline), cmdshow);
2276 
2277  ZeroMemory(&info, sizeof(info));
2278  info.pcszFile = cmdline;
2279  info.pcszClass = NULL;
2281 
2283 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define ZeroMemory
Definition: winbase.h:1635
TCHAR * cmdline
Definition: stretchblt.cpp:32
struct _test_info info[]
Definition: SetCursorPos.c:19
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SHOpenWithDialog(HWND hwndParent, const OPENASINFO *poainfo)
static HINSTANCE hinst
Definition: edit.c:551

Referenced by OpenAs_RunDLLA().

◆ ParseNoTildeEffect()

static void ParseNoTildeEffect ( PWSTR res,
LPCWSTR args,
DWORD len,
DWORD used,
int  argNum 
)
static

Definition at line 37 of file shlexec.cpp.

38 {
39  bool firstCharQuote = false;
40  bool quotes_opened = false;
41  bool backslash_encountered = false;
42 
43  for (int curArg = 0; curArg <= argNum && *args; ++curArg)
44  {
45  firstCharQuote = false;
46  if (*args == '"')
47  {
48  quotes_opened = true;
49  firstCharQuote = true;
50  args++;
51  }
52 
53  while(*args)
54  {
55  if (*args == '\\')
56  {
57  // if we found a backslash then flip the variable
58  backslash_encountered = !backslash_encountered;
59  }
60  else if (*args == '"')
61  {
62  if (quotes_opened)
63  {
64  if (*(args + 1) != '"')
65  {
66  quotes_opened = false;
67  args++;
68  break;
69  }
70  else
71  {
72  args++;
73  }
74  }
75  else
76  {
77  quotes_opened = true;
78  }
79 
80  backslash_encountered = false;
81  }
82  else
83  {
84  backslash_encountered = false;
85  if (*args == ' ' && !firstCharQuote)
86  break;
87  }
88 
89  if (curArg == argNum)
90  {
91  used++;
92  if (used < len)
93  *res++ = *args;
94  }
95 
96  args++;
97  }
98 
99  while(*args == ' ')
100  ++args;
101  }
102 }
Definition: match.c:390
c used
Definition: write.c:2877
GLenum GLsizei len
Definition: glext.h:6722
GLuint res
Definition: glext.h:9613
#define args
Definition: format.c:66

Referenced by SHELL_ArgifyW().

◆ ParseTildeEffect()

static void ParseTildeEffect ( PWSTR res,
LPCWSTR args,
DWORD len,
DWORD used,
int  argNum 
)
static

Definition at line 104 of file shlexec.cpp.

105 {
106  bool quotes_opened = false;
107  bool backslash_encountered = false;
108 
109  for (int curArg = 0; curArg <= argNum && *args; ++curArg)
110  {
111  while(*args)
112  {
113  if (*args == '\\')
114  {
115  // if we found a backslash then flip the variable
116  backslash_encountered = !backslash_encountered;
117  }
118  else if (*args == '"')
119  {
120  if (quotes_opened)
121  {
122  if (*(args + 1) != '"')
123  {
124  quotes_opened = false;
125  }
126  else
127  {
128  args++;
129  }
130  }
131  else
132  {
133  quotes_opened = true;
134  }
135 
136  backslash_encountered = false;
137  }
138  else
139  {
140  backslash_encountered = false;
141  if (*args == ' ' && !quotes_opened && curArg != argNum)
142  break;
143  }
144 
145  if (curArg == argNum)
146  {
147  used++;
148  if (used < len)
149  *res++ = *args;
150  }
151 
152  args++;
153  }
154  }
155 }
Definition: match.c:390
c used
Definition: write.c:2877
GLenum GLsizei len
Definition: glext.h:6722
GLuint res
Definition: glext.h:9613
#define args
Definition: format.c:66

Referenced by SHELL_ArgifyW().

◆ SHELL_ArgifyW()

static BOOL SHELL_ArgifyW ( WCHAR out,
DWORD  len,
const WCHAR fmt,
const WCHAR lpFile,
LPITEMIDLIST  pidl,
LPCWSTR  args,
DWORD out_len,
const WCHAR lpDir 
)
static

Definition at line 184 of file shlexec.cpp.

185 {
186  WCHAR xlpFile[1024];
187  BOOL done = FALSE;
188  BOOL found_p1 = FALSE;
189  PWSTR res = out;
190  PCWSTR cmd;
191  DWORD used = 0;
192  bool tildeEffect = false;
193 
194  TRACE("Before parsing: %p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
195  debugstr_w(lpFile), pidl, args);
196 
197  while (*fmt)
198  {
199  if (*fmt == '%')
200  {
201  switch (*++fmt)
202  {
203  case '\0':
204  case '%':
205  {
206  used++;
207  if (used < len)
208  *res++ = '%';
209  };
210  break;
211 
212  case '*':
213  {
214  if (args)
215  {
216  if (*fmt == '*')
217  {
218  used++;
219  while(*args)
220  {
221  used++;
222  if (used < len)
223  *res++ = *args++;
224  else
225  args++;
226  }
227  used++;
228  break;
229  }
230  }
231  };
232  break;
233 
234  case '~':
235 
236  case '2':
237  case '3':
238  case '4':
239  case '5':
240  case '6':
241  case '7':
242  case '8':
243  case '9':
244  //case '0':
245  {
246  if (*fmt == '~')
247  {
248  fmt++;
249  tildeEffect = true;
250  }
251 
252  if (args)
253  {
254  if (tildeEffect)
255  {
256  ParseTildeEffect(res, args, len, used, *fmt - '2');
257  tildeEffect = false;
258  }
259  else
260  {
261  ParseNoTildeEffect(res, args, len, used, *fmt - '2');
262  }
263  }
264  };
265  break;
266 
267  case '1':
268  if (!done || (*fmt == '1'))
269  {
270  /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
271  if (SearchPathW(lpDir, lpFile, wszExe, sizeof(xlpFile) / sizeof(WCHAR), xlpFile, NULL))
272  cmd = xlpFile;
273  else
274  cmd = lpFile;
275 
276  used += wcslen(cmd);
277  if (used < len)
278  {
279  wcscpy(res, cmd);
280  res += wcslen(cmd);
281  }
282  }
283  found_p1 = TRUE;
284  break;
285 
286  /*
287  * IE uses this a lot for activating things such as windows media
288  * player. This is not verified to be fully correct but it appears
289  * to work just fine.
290  */
291  case 'l':
292  case 'L':
293  if (lpFile)
294  {
295  used += wcslen(lpFile);
296  if (used < len)
297  {
298  wcscpy(res, lpFile);
299  res += wcslen(lpFile);
300  }
301  }
302  found_p1 = TRUE;
303  break;
304 
305  case 'i':
306  case 'I':
307  if (pidl)
308  {
309  DWORD chars = 0;
310  /* %p should not exceed 8, maybe 16 when looking forward to 64bit.
311  * allowing a buffer of 100 should more than exceed all needs */
312  WCHAR buf[100];
313  LPVOID pv;
314  HGLOBAL hmem = SHAllocShared(pidl, ILGetSize(pidl), 0);
315  pv = SHLockShared(hmem, 0);
316  chars = swprintf(buf, L":%p", pv);
317 
318  if (chars >= sizeof(buf) / sizeof(WCHAR))
319  ERR("pidl format buffer too small!\n");
320 
321  used += chars;
322 
323  if (used < len)
324  {
325  wcscpy(res, buf);
326  res += chars;
327  }
328  SHUnlockShared(pv);
329  }
330  found_p1 = TRUE;
331  break;
332 
333  default:
334  /*
335  * Check if this is an env-variable here...
336  */
337 
338  /* Make sure that we have at least one more %.*/
339  if (strchrW(fmt, '%'))
340  {
341  WCHAR tmpBuffer[1024];
342  PWSTR tmpB = tmpBuffer;
343  WCHAR tmpEnvBuff[MAX_PATH];
344  DWORD envRet;
345 
346  while (*fmt != '%')
347  *tmpB++ = *fmt++;
348  *tmpB++ = 0;
349 
350  TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer));
351 
352  envRet = GetEnvironmentVariableW(tmpBuffer, tmpEnvBuff, MAX_PATH);
353  if (envRet == 0 || envRet > MAX_PATH)
354  {
355  used += wcslen(tmpBuffer);
356  if (used < len)
357  {
358  wcscpy( res, tmpBuffer );
359  res += wcslen(tmpBuffer);
360  }
361  }
362  else
363  {
364  used += wcslen(tmpEnvBuff);
365  if (used < len)
366  {
367  wcscpy( res, tmpEnvBuff );
368  res += wcslen(tmpEnvBuff);
369  }
370  }
371  }
372  done = TRUE;
373  break;
374  }
375  /* Don't skip past terminator (catch a single '%' at the end) */
376  if (*fmt != '\0')
377  {
378  fmt++;
379  }
380  }
381  else
382  {
383  used ++;
384  if (used < len)
385  *res++ = *fmt++;
386  else
387  fmt++;
388  }
389  }
390 
391  used++;
392  if (res - out < static_cast<int>(len))
393  *res = '\0';
394  else
395  out[len-1] = '\0';
396 
397  TRACE("used %i of %i space\n", used, len);
398  if (out_len)
399  *out_len = used;
400 
401  TRACE("After parsing: %p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt),
402  debugstr_w(lpFile), pidl, args);
403 
404  return found_p1;
405 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: ftp_var.h:139
uint16_t * PWSTR
Definition: typedefs.h:54
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
char * cmd
Definition: vfdcmd.c:85
Definition: match.c:390
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
static void ParseNoTildeEffect(PWSTR &res, LPCWSTR &args, DWORD &len, DWORD &used, int argNum)
Definition: shlexec.cpp:37
c used
Definition: write.c:2877
#define TRACE(s)
Definition: solgame.cpp:4
HANDLE WINAPI SHAllocShared(LPCVOID lpvData, DWORD dwSize, DWORD dwProcId)
Definition: ordinal.c:162
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR wszExe[]
Definition: shlexec.cpp:29
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
#define ERR(fmt,...)
Definition: debug.h:109
PVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
Definition: ordinal.c:210
#define ILGetSize
Definition: shellclasses.h:638
GLuint res
Definition: glext.h:9613
BOOL WINAPI SHUnlockShared(LPVOID lpView)
Definition: ordinal.c:242
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:412
Definition: dsound.c:943
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static void ParseTildeEffect(PWSTR &res, LPCWSTR &args, DWORD &len, DWORD &used, int argNum)
Definition: shlexec.cpp:104

Referenced by dde_connect(), execute_from_key(), SHELL_execute_class(), SHELL_FindExecutable(), and SHELL_translate_idlist().

◆ SHELL_BuildEnvW()

static LPWSTR SHELL_BuildEnvW ( const WCHAR path)
static

Definition at line 510 of file shlexec.cpp.

511 {
512  static const WCHAR wPath[] = L"PATH=";
513  WCHAR *strings, *new_env;
514  WCHAR *p, *p2;
515  int total = wcslen(path) + 1;
516  BOOL got_path = FALSE;
517 
518  if (!(strings = GetEnvironmentStringsW())) return NULL;
519  p = strings;
520  while (*p)
521  {
522  int len = wcslen(p) + 1;
523  if (!_wcsnicmp( p, wPath, 5 )) got_path = TRUE;
524  total += len;
525  p += len;
526  }
527  if (!got_path) total += 5; /* we need to create PATH */
528  total++; /* terminating null */
529 
530  if (!(new_env = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, total * sizeof(WCHAR))))
531  {
533  return NULL;
534  }
535  p = strings;
536  p2 = new_env;
537  while (*p)
538  {
539  int len = wcslen(p) + 1;
540  memcpy(p2, p, len * sizeof(WCHAR));
541  if (!_wcsnicmp( p, wPath, 5 ))
542  {
543  p2[len - 1] = ';';
544  wcscpy( p2 + len, path );
545  p2 += wcslen(path) + 1;
546  }
547  p += len;
548  p2 += len;
549  }
550  if (!got_path)
551  {
552  wcscpy(p2, wPath);
553  wcscat(p2, path);
554  p2 += wcslen(p2) + 1;
555  }
556  *p2 = 0;
558  return new_env;
559 }
#define TRUE
Definition: types.h:120
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
BOOL WINAPI FreeEnvironmentStringsW(IN LPWSTR EnvironmentStrings)
Definition: environ.c:389
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLsizei const GLchar *const * strings
Definition: glext.h:7622
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
Definition: services.c:325
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
LPWSTR WINAPI GetEnvironmentStringsW(VOID)
Definition: environ.c:344
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by SHELL_TryAppPathW().

◆ SHELL_execute()

static BOOL SHELL_execute ( LPSHELLEXECUTEINFOW  sei,
SHELL_ExecuteW32  execfunc 
)
static

Definition at line 1713 of file shlexec.cpp.

1714 {
1715  static const DWORD unsupportedFlags =
1719 
1720  WCHAR parametersBuffer[1024], dirBuffer[MAX_PATH], wcmdBuffer[1024];
1721  WCHAR *wszApplicationName, *wszParameters, *wszDir, *wcmd;
1722  DWORD dwApplicationNameLen = MAX_PATH + 2;
1723  DWORD parametersLen = sizeof(parametersBuffer) / sizeof(WCHAR);
1724  DWORD dirLen = sizeof(dirBuffer) / sizeof(WCHAR);
1725  DWORD wcmdLen = sizeof(wcmdBuffer) / sizeof(WCHAR);
1726  DWORD len;
1727  SHELLEXECUTEINFOW sei_tmp; /* modifiable copy of SHELLEXECUTEINFO struct */
1728  WCHAR wfileName[MAX_PATH];
1729  WCHAR *env;
1730  WCHAR wszKeyname[256];
1731  LPCWSTR lpFile;
1732  UINT_PTR retval = SE_ERR_NOASSOC;
1733  BOOL appKnownSingular = FALSE;
1734 
1735  /* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
1736  sei_tmp = *sei;
1737 
1738  TRACE("mask=0x%08x hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
1739  sei_tmp.fMask, sei_tmp.hwnd, debugstr_w(sei_tmp.lpVerb),
1740  debugstr_w(sei_tmp.lpFile), debugstr_w(sei_tmp.lpParameters),
1741  debugstr_w(sei_tmp.lpDirectory), sei_tmp.nShow,
1742  ((sei_tmp.fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME) ?
1743  debugstr_w(sei_tmp.lpClass) : "not used");
1744 
1745  sei->hProcess = NULL;
1746 
1747  /* make copies of all path/command strings */
1748  if (!sei_tmp.lpFile)
1749  {
1750  wszApplicationName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen * sizeof(WCHAR));
1751  *wszApplicationName = '\0';
1752  }
1753  else if (*sei_tmp.lpFile == '\"' && sei_tmp.lpFile[(len = strlenW(sei_tmp.lpFile))-1] == '\"')
1754  {
1755  if(len-1 >= dwApplicationNameLen)
1756  dwApplicationNameLen = len;
1757 
1758  wszApplicationName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen * sizeof(WCHAR));
1759  memcpy(wszApplicationName, sei_tmp.lpFile + 1, len * sizeof(WCHAR));
1760 
1761  if(len > 2)
1762  wszApplicationName[len-2] = '\0';
1763  appKnownSingular = TRUE;
1764 
1765  TRACE("wszApplicationName=%s\n", debugstr_w(wszApplicationName));
1766  }
1767  else
1768  {
1769  DWORD l = strlenW(sei_tmp.lpFile) + 1;
1770  if(l > dwApplicationNameLen) dwApplicationNameLen = l + 1;
1771  wszApplicationName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dwApplicationNameLen * sizeof(WCHAR));
1772  memcpy(wszApplicationName, sei_tmp.lpFile, l * sizeof(WCHAR));
1773  }
1774 
1775  wszParameters = parametersBuffer;
1776  if (sei_tmp.lpParameters)
1777  {
1778  len = lstrlenW(sei_tmp.lpParameters) + 1;
1779  if (len > parametersLen)
1780  {
1781  wszParameters = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1782  parametersLen = len;
1783  }
1784  strcpyW(wszParameters, sei_tmp.lpParameters);
1785  }
1786  else
1787  *wszParameters = L'\0';
1788 
1789  wszDir = dirBuffer;
1790  if (sei_tmp.lpDirectory)
1791  {
1792  len = lstrlenW(sei_tmp.lpDirectory) + 1;
1793  if (len > dirLen)
1794  {
1795  wszDir = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1796  dirLen = len;
1797  }
1798  strcpyW(wszDir, sei_tmp.lpDirectory);
1799  }
1800  else
1801  *wszDir = L'\0';
1802 
1803  /* adjust string pointers to point to the new buffers */
1804  sei_tmp.lpFile = wszApplicationName;
1805  sei_tmp.lpParameters = wszParameters;
1806  sei_tmp.lpDirectory = wszDir;
1807 
1808  if (sei_tmp.fMask & unsupportedFlags)
1809  {
1810  FIXME("flags ignored: 0x%08x\n", sei_tmp.fMask & unsupportedFlags);
1811  }
1812 
1813  /* process the IDList */
1814  if (sei_tmp.fMask & SEE_MASK_IDLIST)
1815  {
1817 
1819 
1820  if (SUCCEEDED(hr))
1821  {
1822  hr = pSEH->Execute(&sei_tmp);
1823 
1824  if (hr == S_OK)
1825  {
1826  HeapFree(GetProcessHeap(), 0, wszApplicationName);
1827  if (wszParameters != parametersBuffer)
1828  HeapFree(GetProcessHeap(), 0, wszParameters);
1829  if (wszDir != dirBuffer)
1830  HeapFree(GetProcessHeap(), 0, wszDir);
1831  return TRUE;
1832  }
1833  }
1834 
1835  SHGetPathFromIDListW((LPCITEMIDLIST)sei_tmp.lpIDList, wszApplicationName);
1836  appKnownSingular = TRUE;
1837  TRACE("-- idlist=%p (%s)\n", sei_tmp.lpIDList, debugstr_w(wszApplicationName));
1838  }
1839 
1840  if (sei_tmp.fMask & SEE_MASK_DOENVSUBST)
1841  {
1842  WCHAR *tmp;
1843 
1844  tmp = expand_environment(sei_tmp.lpFile);
1845  if (!tmp)
1846  {
1847  return FALSE;
1848  }
1849  HeapFree(GetProcessHeap(), 0, wszApplicationName);
1850  sei_tmp.lpFile = wszApplicationName = tmp;
1851 
1852  tmp = expand_environment(sei_tmp.lpDirectory);
1853  if (!tmp)
1854  {
1855  return FALSE;
1856  }
1857  if (wszDir != dirBuffer) HeapFree(GetProcessHeap(), 0, wszDir);
1858  sei_tmp.lpDirectory = wszDir = tmp;
1859  }
1860 
1862  {
1863  sei->hInstApp = (HINSTANCE) 33;
1864  HeapFree(GetProcessHeap(), 0, wszApplicationName);
1865  if (wszParameters != parametersBuffer)
1866  HeapFree(GetProcessHeap(), 0, wszParameters);
1867  if (wszDir != dirBuffer)
1868  HeapFree(GetProcessHeap(), 0, wszDir);
1869  return TRUE;
1870  }
1871 
1872  if (sei_tmp.fMask & SEE_MASK_CLASSALL)
1873  {
1874  retval = SHELL_execute_class(wszApplicationName, &sei_tmp, sei, execfunc);
1875  if (retval <= 32 && !(sei_tmp.fMask & SEE_MASK_FLAG_NO_UI))
1876  {
1877  OPENASINFO Info;
1878 
1879  //FIXME
1880  // need full path
1881 
1882  Info.pcszFile = wszApplicationName;
1883  Info.pcszClass = NULL;
1884  Info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
1885 
1886  //if (SHOpenWithDialog(sei_tmp.hwnd, &Info) != S_OK)
1888  do_error_dialog(retval, sei_tmp.hwnd, wszApplicationName);
1889  }
1890  HeapFree(GetProcessHeap(), 0, wszApplicationName);
1891  if (wszParameters != parametersBuffer)
1892  HeapFree(GetProcessHeap(), 0, wszParameters);
1893  if (wszDir != dirBuffer)
1894  HeapFree(GetProcessHeap(), 0, wszDir);
1895  return retval > 32;
1896  }
1897 
1898  /* Has the IDList not yet been translated? */
1899  if (sei_tmp.fMask & SEE_MASK_IDLIST)
1900  {
1901  appKnownSingular = SHELL_translate_idlist( &sei_tmp, wszParameters,
1902  parametersLen,
1903  wszApplicationName,
1904  dwApplicationNameLen );
1905  }
1906 
1907  /* convert file URLs */
1908  if (UrlIsFileUrlW(sei_tmp.lpFile))
1909  {
1910  LPWSTR buf;
1911  DWORD size;
1912 
1913  size = MAX_PATH;
1914  buf = static_cast<LPWSTR>(HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)));
1915  if (!buf || FAILED(PathCreateFromUrlW(sei_tmp.lpFile, buf, &size, 0)))
1916  {
1917  HeapFree(GetProcessHeap(), 0, buf);
1918  return SE_ERR_OOM;
1919  }
1920 
1921  HeapFree(GetProcessHeap(), 0, wszApplicationName);
1922  wszApplicationName = buf;
1923  sei_tmp.lpFile = wszApplicationName;
1924  }
1925  else /* or expand environment strings (not both!) */
1926  {
1927  len = ExpandEnvironmentStringsW(sei_tmp.lpFile, NULL, 0);
1928  if (len > 0)
1929  {
1930  LPWSTR buf;
1931  buf = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
1932 
1933  ExpandEnvironmentStringsW(sei_tmp.lpFile, buf, len + 1);
1934  HeapFree(GetProcessHeap(), 0, wszApplicationName);
1935  wszApplicationName = buf;
1936  /* appKnownSingular unmodified */
1937 
1938  sei_tmp.lpFile = wszApplicationName;
1939  }
1940  }
1941 
1942  if (*sei_tmp.lpDirectory)
1943  {
1945  if (len > 0)
1946  {
1947  LPWSTR buf;
1948  len++;
1949  buf = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1951  if (wszDir != dirBuffer)
1952  HeapFree(GetProcessHeap(), 0, wszDir);
1953  wszDir = buf;
1954  sei_tmp.lpDirectory = wszDir;
1955  }
1956  }
1957 
1958  /* Else, try to execute the filename */
1959  TRACE("execute: %s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir));
1960 
1961  /* separate out command line arguments from executable file name */
1962  if (!*sei_tmp.lpParameters && !appKnownSingular)
1963  {
1964  /* If the executable path is quoted, handle the rest of the command line as parameters. */
1965  if (sei_tmp.lpFile[0] == L'"')
1966  {
1967  LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1;
1968  LPWSTR dst = wfileName;
1969  LPWSTR end;
1970 
1971  /* copy the unquoted executable path to 'wfileName' */
1972  while(*src && *src != L'"')
1973  *dst++ = *src++;
1974 
1975  *dst = L'\0';
1976 
1977  if (*src == L'"')
1978  {
1979  end = ++src;
1980 
1981  while(isspaceW(*src))
1982  ++src;
1983  }
1984  else
1985  end = src;
1986 
1987  /* copy the parameter string to 'wszParameters' */
1988  strcpyW(wszParameters, src);
1989 
1990  /* terminate previous command string after the quote character */
1991  *end = L'\0';
1992  lpFile = wfileName;
1993  }
1994  else
1995  {
1996  lpFile = sei_tmp.lpFile;
1997  }
1998  }
1999  else
2000  lpFile = sei_tmp.lpFile;
2001 
2002  wcmd = wcmdBuffer;
2003  len = lstrlenW(wszApplicationName) + 3;
2004  if (sei_tmp.lpParameters[0])
2005  len += 1 + lstrlenW(wszParameters);
2006  if (len > wcmdLen)
2007  {
2008  wcmd = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2009  wcmdLen = len;
2010  }
2011  swprintf(wcmd, L"\"%s\"", wszApplicationName);
2012  if (sei_tmp.lpParameters[0])
2013  {
2014  strcatW(wcmd, L" ");
2015  strcatW(wcmd, wszParameters);
2016  }
2017 
2018  retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
2019  if (retval > 32)
2020  {
2021  HeapFree(GetProcessHeap(), 0, wszApplicationName);
2022  if (wszParameters != parametersBuffer)
2023  HeapFree(GetProcessHeap(), 0, wszParameters);
2024  if (wszDir != dirBuffer)
2025  HeapFree(GetProcessHeap(), 0, wszDir);
2026  if (wcmd != wcmdBuffer)
2027  HeapFree(GetProcessHeap(), 0, wcmd);
2028  return TRUE;
2029  }
2030 
2031  /* Else, try to find the executable */
2032  wcmd[0] = L'\0';
2033  retval = SHELL_FindExecutable(sei_tmp.lpDirectory, lpFile, sei_tmp.lpVerb, wcmd, wcmdLen, wszKeyname, &env, (LPITEMIDLIST)sei_tmp.lpIDList, sei_tmp.lpParameters);
2034  if (retval > 32) /* Found */
2035  {
2036  retval = SHELL_quote_and_execute(wcmd, wszParameters, wszKeyname,
2037  wszApplicationName, env, &sei_tmp,
2038  sei, execfunc);
2039  HeapFree(GetProcessHeap(), 0, env);
2040  }
2041  else if (PathIsDirectoryW(lpFile))
2042  {
2043  WCHAR wExec[MAX_PATH];
2044  WCHAR * lpQuotedFile = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (strlenW(lpFile) + 3));
2045 
2046  if (lpQuotedFile)
2047  {
2048  retval = SHELL_FindExecutable(sei_tmp.lpDirectory, L"explorer",
2049  wszOpen, wExec, MAX_PATH,
2050  NULL, &env, NULL, NULL);
2051  if (retval > 32)
2052  {
2053  swprintf(lpQuotedFile, L"\"%s\"", lpFile);
2054  retval = SHELL_quote_and_execute(wExec, lpQuotedFile,
2055  wszKeyname,
2056  wszApplicationName, env,
2057  &sei_tmp, sei, execfunc);
2058  HeapFree(GetProcessHeap(), 0, env);
2059  }
2060  HeapFree(GetProcessHeap(), 0, lpQuotedFile);
2061  }
2062  else
2063  retval = 0; /* Out of memory */
2064  }
2065  else if (PathIsURLW(lpFile)) /* File not found, check for URL */
2066  {
2067  retval = SHELL_execute_url(lpFile, wcmd, &sei_tmp, sei, execfunc );
2068  }
2069  /* Check if file specified is in the form www.??????.*** */
2070  else if (!strncmpiW(lpFile, L"www", 3))
2071  {
2072  /* if so, prefix lpFile with http:// and call ShellExecute */
2073  WCHAR lpstrTmpFile[256];
2074  strcpyW(lpstrTmpFile, L"http://");
2075  strcatW(lpstrTmpFile, lpFile);
2076  retval = (UINT_PTR)ShellExecuteW(sei_tmp.hwnd, sei_tmp.lpVerb, lpstrTmpFile, NULL, NULL, 0);
2077  }
2078 
2079  TRACE("retval %lu\n", retval);
2080 
2081  if (retval <= 32 && !(sei_tmp.fMask & SEE_MASK_FLAG_NO_UI))
2082  {
2083  OPENASINFO Info;
2084 
2085  //FIXME
2086  // need full path
2087 
2088  Info.pcszFile = wszApplicationName;
2089  Info.pcszClass = NULL;
2090  Info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
2091 
2092  //if (SHOpenWithDialog(sei_tmp.hwnd, &Info) != S_OK)
2094  do_error_dialog(retval, sei_tmp.hwnd, wszApplicationName);
2095  }
2096 
2097  HeapFree(GetProcessHeap(), 0, wszApplicationName);
2098  if (wszParameters != parametersBuffer)
2099  HeapFree(GetProcessHeap(), 0, wszParameters);
2100  if (wszDir != dirBuffer)
2101  HeapFree(GetProcessHeap(), 0, wszDir);
2102  if (wcmd != wcmdBuffer)
2103  HeapFree(GetProcessHeap(), 0, wcmd);
2104 
2105  sei->hInstApp = (HINSTANCE)(retval > 32 ? 33 : retval);
2106 
2107  return retval > 32;
2108 }
HINSTANCE hInstApp
Definition: shellapi.h:334
unsigned __int3264 UINT_PTR
Definition: activex.cpp:275
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1702
static UINT_PTR SHELL_execute_url(LPCWSTR lpFile, LPCWSTR wcmd, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc)
Definition: shlexec.cpp:1633
HRESULT WINAPI PathCreateFromUrlW(LPCWSTR pszUrl, LPWSTR pszPath, LPDWORD pcchPath, DWORD dwReserved)
Definition: path.c:3334
#define SEE_MASK_FLAG_DDEWAIT
Definition: shellapi.h:34
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)
Definition: shlexec.cpp:1597
#define TRUE
Definition: types.h:120
static WCHAR * expand_environment(const WCHAR *str)
Definition: shlexec.cpp:1690
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
WINE_UNICODE_INLINE int isspaceW(WCHAR wc)
Definition: unicode.h:165
#define SE_ERR_OOM
Definition: shellapi.h:125
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
#define SEE_MASK_ASYNCOK
Definition: shellapi.h:52
GLuint GLuint end
Definition: gl.h:1545
#define strncmpiW(s1, s2, n)
Definition: unicode.h:40
#define lstrlenW
Definition: compat.h:407
#define IID_PPV_ARG(Itype, ppType)
struct TraceInfo Info
BOOL WINAPI PathIsURLW(LPCWSTR lpstrPath)
Definition: url.c:2432
#define SEE_MASK_CONNECTNETDRV
Definition: shellapi.h:32
unsigned int BOOL
Definition: ntddk_ex.h:94
LPCWSTR lpDirectory
Definition: shellapi.h:332
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
static UINT_PTR SHELL_execute_class(LPCWSTR wszApplicationName, LPSHELLEXECUTEINFOW psei, LPSHELLEXECUTEINFOW psei_out, SHELL_ExecuteW32 execfunc)
Definition: shlexec.cpp:1494
smooth NULL
Definition: ftsmooth.c:416
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:36
static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb, LPWSTR lpResult, DWORD resultLen, LPWSTR key, WCHAR **env, LPITEMIDLIST pidl, LPCWSTR args)
Definition: shlexec.cpp:697
static LONG ShellExecute_FromContextMenu(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:1450
r l[0]
Definition: byte_order.h:167
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
#define TRACE(s)
Definition: solgame.cpp:4
#define SEE_MASK_CLASSNAME
Definition: shellapi.h:25
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define SEE_MASK_DOENVSUBST
Definition: shellapi.h:35
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
HANDLE HINSTANCE
Definition: typedefs.h:75
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define SEE_MASK_HOTKEY
Definition: shellapi.h:30
GLenum src
Definition: glext.h:6340
#define SEE_MASK_UNICODE
Definition: shellapi.h:37
#define UrlIsFileUrlW(x)
Definition: shlwapi.h:1377
static const WCHAR wszOpen[]
Definition: shlexec.cpp:28
#define S_OK
Definition: intsafe.h:59
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1323
LPCWSTR lpParameters
Definition: shellapi.h:331
GLenum GLenum dst
Definition: glext.h:6340
WINE_UNICODE_INLINE WCHAR * strcatW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:242
#define SEE_MASK_IDLIST
Definition: shellapi.h:27
#define SEE_MASK_HMONITOR
Definition: shellapi.h:53
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2208
#define SEE_MASK_INVOKEIDLIST
Definition: shellapi.h:28
#define SE_ERR_NOASSOC
Definition: shellapi.h:132
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static void do_error_dialog(UINT_PTR retval, HWND hwnd, WCHAR *filename)
Definition: shlexec.cpp:1669
#define SEE_MASK_CLASSALL
Definition: shlexec.cpp:32
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define SEE_MASK_ICON
Definition: shellapi.h:29
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57
static BOOL SHELL_translate_idlist(LPSHELLEXECUTEINFOW sei, LPWSTR wszParameters, DWORD parametersLen, LPWSTR wszApplicationName, DWORD dwApplicationNameLen)
Definition: shlexec.cpp:1550

Referenced by ShellExecuteExA(), ShellExecuteExW(), ShellExecuteW(), and WOWShellExecute().

◆ SHELL_execute_class()

static UINT_PTR SHELL_execute_class ( LPCWSTR  wszApplicationName,
LPSHELLEXECUTEINFOW  psei,
LPSHELLEXECUTEINFOW  psei_out,
SHELL_ExecuteW32  execfunc 
)
static

Definition at line 1494 of file shlexec.cpp.

1495 {
1496  WCHAR execCmd[1024], classname[1024];
1497  /* launch a document by fileclass like 'WordPad.Document.1' */
1498  /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
1499  /* FIXME: wcmd should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
1500  ULONG cmask = (psei->fMask & SEE_MASK_CLASSALL);
1501  DWORD resultLen;
1502  BOOL done;
1503  UINT_PTR rslt;
1504 
1505  /* FIXME: remove following block when SHELL_quote_and_execute supports hkeyClass parameter */
1506  if (cmask != SEE_MASK_CLASSNAME)
1507  {
1508  WCHAR wcmd[1024];
1510  (cmask == SEE_MASK_CLASSNAME) ? psei->lpClass : NULL,
1511  psei->lpVerb,
1512  execCmd, sizeof(execCmd));
1513 
1514  /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
1515  TRACE("SEE_MASK_CLASSNAME->%s, doc->%s\n", debugstr_w(execCmd), debugstr_w(wszApplicationName));
1516 
1517  wcmd[0] = '\0';
1518  done = SHELL_ArgifyW(wcmd, sizeof(wcmd) / sizeof(WCHAR), execCmd, wszApplicationName, (LPITEMIDLIST)psei->lpIDList, NULL, &resultLen,
1519  (psei->lpDirectory && *psei->lpDirectory) ? psei->lpDirectory : NULL);
1520  if (!done && wszApplicationName[0])
1521  {
1522  strcatW(wcmd, L" ");
1523  if (*wszApplicationName != '"')
1524  {
1525  strcatW(wcmd, L"\"");
1526  strcatW(wcmd, wszApplicationName);
1527  strcatW(wcmd, L"\"");
1528  }
1529  else
1530  strcatW(wcmd, wszApplicationName);
1531  }
1532  if (resultLen > sizeof(wcmd) / sizeof(WCHAR))
1533  ERR("Argify buffer not large enough... truncating\n");
1534  return execfunc(wcmd, NULL, FALSE, psei, psei_out);
1535  }
1536 
1537  strcpyW(classname, psei->lpClass);
1538  rslt = SHELL_FindExecutableByVerb(psei->lpVerb, NULL, classname, execCmd, sizeof(execCmd));
1539 
1540  TRACE("SHELL_FindExecutableByVerb returned %u (%s, %s)\n", (unsigned int)rslt, debugstr_w(classname), debugstr_w(execCmd));
1541  if (33 > rslt)
1542  return rslt;
1543  rslt = SHELL_quote_and_execute( execCmd, L"", classname,
1544  wszApplicationName, NULL, psei,
1545  psei_out, execfunc );
1546  return rslt;
1547 
1548 }
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)
Definition: shlexec.cpp:1597
#define SEE_MASK_CLASSKEY
Definition: shellapi.h:26
static BOOL SHELL_ArgifyW(WCHAR *out, DWORD len, const WCHAR *fmt, const WCHAR *lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD *out_len, const WCHAR *lpDir)
Definition: shlexec.cpp:184
WCHAR classname[128]
Definition: startup.c:15
unsigned int BOOL
Definition: ntddk_ex.h:94
LPCWSTR lpDirectory
Definition: shellapi.h:332
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
static UINT SHELL_FindExecutableByVerb(LPCWSTR lpVerb, LPWSTR key, LPWSTR classname, LPWSTR command, LONG commandlen)
Definition: shlexec.cpp:627
#define TRACE(s)
Definition: solgame.cpp:4
#define SEE_MASK_CLASSNAME
Definition: shellapi.h:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:109
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
WINE_UNICODE_INLINE WCHAR * strcatW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:242
BOOL HCR_GetExecuteCommandW(HKEY hkeyClass, LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
Definition: classes.c:200
unsigned int ULONG
Definition: retypes.h:1
#define SEE_MASK_CLASSALL
Definition: shlexec.cpp:32
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

Referenced by SHELL_execute().

◆ SHELL_execute_url()

static UINT_PTR SHELL_execute_url ( LPCWSTR  lpFile,
LPCWSTR  wcmd,
LPSHELLEXECUTEINFOW  psei,
LPSHELLEXECUTEINFOW  psei_out,
SHELL_ExecuteW32  execfunc 
)
static

Definition at line 1633 of file shlexec.cpp.

1634 {
1635  static const WCHAR wShell[] = L"\\shell\\";
1636  static const WCHAR wCommand[] = L"\\command";
1637  UINT_PTR retval;
1638  WCHAR *lpstrProtocol;
1639  LPCWSTR lpstrRes;
1640  INT iSize;
1641  DWORD len;
1642 
1643  lpstrRes = strchrW(lpFile, ':');
1644  if (lpstrRes)
1645  iSize = lpstrRes - lpFile;
1646  else
1647  iSize = strlenW(lpFile);
1648 
1649  TRACE("Got URL: %s\n", debugstr_w(lpFile));
1650  /* Looking for ...<protocol>\shell<lpVerb>\command */
1651  len = iSize + lstrlenW(wShell) + lstrlenW(wCommand) + 1;
1652  if (psei->lpVerb && *psei->lpVerb)
1653  len += lstrlenW(psei->lpVerb);
1654  else
1655  len += lstrlenW(wszOpen);
1656  lpstrProtocol = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1657  memcpy(lpstrProtocol, lpFile, iSize * sizeof(WCHAR));
1658  lpstrProtocol[iSize] = '\0';
1659  strcatW(lpstrProtocol, wShell);
1660  strcatW(lpstrProtocol, psei->lpVerb && *psei->lpVerb ? psei->lpVerb : wszOpen);
1661  strcatW(lpstrProtocol, wCommand);
1662 
1663  retval = execute_from_key(lpstrProtocol, lpFile, NULL, psei->lpParameters,
1664  wcmd, execfunc, psei, psei_out);
1665  HeapFree(GetProcessHeap(), 0, lpstrProtocol);
1666  return retval;
1667 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
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)
Definition: shlexec.cpp:1110
#define lstrlenW
Definition: compat.h:407
int32_t INT
Definition: typedefs.h:56
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
static const WCHAR wszOpen[]
Definition: shlexec.cpp:28
LPCWSTR lpParameters
Definition: shellapi.h:331
WINE_UNICODE_INLINE WCHAR * strcatW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:242
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by SHELL_execute().

◆ SHELL_ExecuteW()

static UINT_PTR SHELL_ExecuteW ( const WCHAR lpCmd,
WCHAR env,
BOOL  shWait,
const SHELLEXECUTEINFOW psei,
LPSHELLEXECUTEINFOW  psei_out 
)
static

Definition at line 429 of file shlexec.cpp.

431 {
434  UINT_PTR retval = SE_ERR_NOASSOC;
435  UINT gcdret = 0;
436  WCHAR curdir[MAX_PATH];
437  DWORD dwCreationFlags;
438  const WCHAR *lpDirectory = NULL;
439 
440  TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd), debugstr_w(psei->lpDirectory));
441 
442  /* make sure we don't fail the CreateProcess if the calling app passes in
443  * a bad working directory */
444  if (psei->lpDirectory && psei->lpDirectory[0])
445  {
448  lpDirectory = psei->lpDirectory;
449  }
450 
451  /* ShellExecute specifies the command from psei->lpDirectory
452  * if present. Not from the current dir as CreateProcess does */
453  if (lpDirectory)
454  if ((gcdret = GetCurrentDirectoryW( MAX_PATH, curdir)))
456  ERR("cannot set directory %s\n", debugstr_w(lpDirectory));
457 
458  ZeroMemory(&startup, sizeof(STARTUPINFOW));
459  startup.cb = sizeof(STARTUPINFOW);
460  startup.dwFlags = STARTF_USESHOWWINDOW;
461  startup.wShowWindow = psei->nShow;
462  dwCreationFlags = CREATE_UNICODE_ENVIRONMENT;
463  if (!(psei->fMask & SEE_MASK_NO_CONSOLE))
464  dwCreationFlags |= CREATE_NEW_CONSOLE;
465  startup.lpTitle = (LPWSTR)(psei->fMask & (SEE_MASK_HASLINKNAME | SEE_MASK_HASTITLE) ? psei->lpClass : NULL);
466 
467  if (psei->fMask & SEE_MASK_HASLINKNAME)
468  startup.dwFlags |= STARTF_TITLEISLINKNAME;
469 
470  if (CreateProcessW(NULL, (LPWSTR)lpCmd, NULL, NULL, FALSE, dwCreationFlags, env,
471  lpDirectory, &startup, &info))
472  {
473  /* Give 30 seconds to the app to come up, if desired. Probably only needed
474  when starting app immediately before making a DDE connection. */
475  if (shWait)
476  if (WaitForInputIdle(info.hProcess, 30000) == WAIT_FAILED)
477  WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
478  retval = 33;
479 
480  if (psei->fMask & SEE_MASK_NOCLOSEPROCESS)
481  psei_out->hProcess = info.hProcess;
482  else
483  CloseHandle( info.hProcess );
484  CloseHandle( info.hThread );
485  }
486  else if ((retval = GetLastError()) >= 32)
487  {
488  WARN("CreateProcess returned error %ld\n", retval);
489  retval = ERROR_BAD_FORMAT;
490  }
491 
492  TRACE("returning %lu\n", retval);
493 
494  psei_out->hInstApp = (HINSTANCE)retval;
495 
496  if (gcdret)
497  if (!SetCurrentDirectoryW(curdir))
498  ERR("cannot return to directory %s\n", debugstr_w(curdir));
499 
500  return retval;
501 }
HINSTANCE hInstApp
Definition: shellapi.h:334
#define ERROR_BAD_FORMAT
Definition: winerror.h:114
#define CloseHandle
Definition: compat.h:398
#define CREATE_UNICODE_ENVIRONMENT
Definition: winbase.h:186
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:31
#define SEE_MASK_HASTITLE
Definition: shellapi.h:49
#define SEE_MASK_NO_CONSOLE
Definition: shellapi.h:38
struct _STARTUPINFOW STARTUPINFOW
#define WARN(fmt,...)
Definition: debug.h:111
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:413
#define SEE_MASK_HASLINKNAME
Definition: shellapi.h:48
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
int startup(int argc, const char *argv[])
Definition: startup.c:430
struct _test_info info[]
Definition: SetCursorPos.c:19
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
LPCWSTR lpDirectory
Definition: shellapi.h:332
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4593
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:482
#define TRACE(s)
Definition: solgame.cpp:4
#define CREATE_NEW_CONSOLE
Definition: winbase.h:180
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_FAILED
Definition: winbase.h:394
Definition: cookie.c:170
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
HANDLE HINSTANCE
Definition: typedefs.h:75
#define ERR(fmt,...)
Definition: debug.h:109
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2248
unsigned int UINT
Definition: ndis.h:50
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
DWORD WINAPI WaitForInputIdle(_In_ HANDLE, _In_ DWORD)
#define SE_ERR_NOASSOC
Definition: shellapi.h:132
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by ShellExecuteExA(), ShellExecuteExW(), and ShellExecuteW().

◆ SHELL_FindExecutable()

static UINT SHELL_FindExecutable ( LPCWSTR  lpPath,
LPCWSTR  lpFile,
LPCWSTR  lpVerb,
LPWSTR  lpResult,
DWORD  resultLen,
LPWSTR  key,
WCHAR **  env,
LPITEMIDLIST  pidl,
LPCWSTR  args 
)
static

Definition at line 697 of file shlexec.cpp.

699 {
700  WCHAR *extension = NULL; /* pointer to file extension */
701  WCHAR classname[256]; /* registry name for this file type */
702  LONG classnamelen = sizeof(classname); /* length of above */
703  WCHAR command[1024]; /* command from registry */
704  WCHAR wBuffer[256]; /* Used to GetProfileString */
705  UINT retval = SE_ERR_NOASSOC;
706  WCHAR *tok; /* token pointer */
707  WCHAR xlpFile[256]; /* result of SearchPath */
708  DWORD attribs; /* file attributes */
709 
710  TRACE("%s\n", debugstr_w(lpFile));
711 
712  if (!lpResult)
714 
715  xlpFile[0] = '\0';
716  lpResult[0] = '\0'; /* Start off with an empty return string */
717  if (key) *key = '\0';
718 
719  /* trap NULL parameters on entry */
720  if (!lpFile)
721  {
722  WARN("(lpFile=%s,lpResult=%s): NULL parameter\n",
723  debugstr_w(lpFile), debugstr_w(lpResult));
724  return ERROR_FILE_NOT_FOUND; /* File not found. Close enough, I guess. */
725  }
726 
727  if (SHELL_TryAppPathW( lpFile, lpResult, env ))
728  {
729  TRACE("found %s via App Paths\n", debugstr_w(lpResult));
730  return 33;
731  }
732 
733  if (SearchPathW(lpPath, lpFile, wszExe, sizeof(xlpFile) / sizeof(WCHAR), xlpFile, NULL))
734  {
735  TRACE("SearchPathW returned non-zero\n");
736  lpFile = xlpFile;
737  /* The file was found in the application-supplied default directory (or the system search path) */
738  }
739  else if (lpPath && SearchPathW(NULL, lpFile, wszExe, sizeof(xlpFile)/sizeof(WCHAR), xlpFile, NULL))
740  {
741  TRACE("SearchPathW returned non-zero\n");
742  lpFile = xlpFile;
743  /* The file was found in one of the directories in the system-wide search path */
744  }
745 
746  attribs = GetFileAttributesW(lpFile);
748  {
749  wcscpy(classname, L"Folder");
750  }
751  else
752  {
753  /* Did we get something? Anything? */
754  if (xlpFile[0] == 0)
755  {
756  TRACE("Returning SE_ERR_FNF\n");
757  return SE_ERR_FNF;
758  }
759  /* First thing we need is the file's extension */
760  extension = wcsrchr(xlpFile, '.'); /* Assume last "." is the one; */
761  /* File->Run in progman uses */
762  /* .\FILE.EXE :( */
763  TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile), debugstr_w(extension));
764 
765  if (extension == NULL || extension[1] == 0)
766  {
767  WARN("Returning SE_ERR_NOASSOC\n");
768  return SE_ERR_NOASSOC;
769  }
770 
771  /* Three places to check: */
772  /* 1. win.ini, [windows], programs (NB no leading '.') */
773  /* 2. Registry, HKEY_CLASS_ROOT<classname>\shell\open\command */
774  /* 3. win.ini, [extensions], extension (NB no leading '.' */
775  /* All I know of the order is that registry is checked before */
776  /* extensions; however, it'd make sense to check the programs */
777  /* section first, so that's what happens here. */
778 
779  /* See if it's a program - if GetProfileString fails, we skip this
780  * section. Actually, if GetProfileString fails, we've probably
781  * got a lot more to worry about than running a program... */
782  if (GetProfileStringW(L"windows", L"programs", L"exe pif bat cmd com", wBuffer, sizeof(wBuffer) / sizeof(WCHAR)) > 0)
783  {
784  CharLowerW(wBuffer);
785  tok = wBuffer;
786  while (*tok)
787  {
788  WCHAR *p = tok;
789  while (*p && *p != ' ' && *p != '\t') p++;
790  if (*p)
791  {
792  *p++ = 0;
793  while (*p == ' ' || *p == '\t') p++;
794  }
795 
796  if (wcsicmp(tok, &extension[1]) == 0) /* have to skip the leading "." */
797  {
798  wcscpy(lpResult, xlpFile);
799  /* Need to perhaps check that the file has a path
800  * attached */
801  TRACE("found %s\n", debugstr_w(lpResult));
802  return 33;
803  /* Greater than 32 to indicate success */
804  }
805  tok = p;
806  }
807  }
808 
809  /* Check registry */
811  &classnamelen) == ERROR_SUCCESS)
812  {
813  classnamelen /= sizeof(WCHAR);
814  if (classnamelen == sizeof(classname) / sizeof(WCHAR))
815  classnamelen--;
816 
817  classname[classnamelen] = '\0';
818  TRACE("File type: %s\n", debugstr_w(classname));
819  }
820  else
821  {
822  *classname = '\0';
823  }
824  }
825 
826  if (*classname)
827  {
828  /* pass the verb string to SHELL_FindExecutableByVerb() */
829  retval = SHELL_FindExecutableByVerb(lpVerb, key, classname, command, sizeof(command));
830 
831  if (retval > 32)
832  {
833  DWORD finishedLen;
834  SHELL_ArgifyW(lpResult, resultLen, command, xlpFile, pidl, args, &finishedLen, lpPath);
835  if (finishedLen > resultLen)
836  ERR("Argify buffer not large enough.. truncated\n");
837  /* Remove double quotation marks and command line arguments */
838  if (*lpResult == '"')
839  {
840  WCHAR *p = lpResult;
841  while (*(p + 1) != '"')
842  {
843  *p = *(p + 1);
844  p++;
845  }
846  *p = '\0';
847  }
848  else
849  {
850  /* Truncate on first space */
851  WCHAR *p = lpResult;
852  while (*p != ' ' && *p != '\0')
853  p++;
854  *p = '\0';
855  }
856  }
857  }
858  else /* Check win.ini */
859  {
860  /* Toss the leading dot */
861  extension++;
862  if (GetProfileStringW(L"extensions", extension, L"", command, sizeof(command) / sizeof(WCHAR)) > 0)
863  {
864  if (wcslen(command) != 0)
865  {
866  wcscpy(lpResult, command);
867  tok = wcschr(lpResult, '^'); /* should be ^.extension? */
868  if (tok != NULL)
869  {
870  tok[0] = '\0';
871  wcscat(lpResult, xlpFile); /* what if no dir in xlpFile? */
872  tok = wcschr(command, '^'); /* see above */
873  if ((tok != NULL) && (wcslen(tok) > 5))
874  {
875  wcscat(lpResult, &tok[5]);
876  }
877  }
878  retval = 33; /* FIXME - see above */
879  }
880  }
881  }
882 
883  TRACE("returning %s\n", debugstr_w(lpResult));
884  return retval;
885 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_SUCCESS
Definition: deptool.c:10
static BOOL SHELL_ArgifyW(WCHAR *out, DWORD len, const WCHAR *fmt, const WCHAR *lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD *out_len, const WCHAR *lpDir)
Definition: shlexec.cpp:184
const GLint * attribs
Definition: glext.h:10538
#define WARN(fmt,...)
Definition: debug.h:111
LPWSTR WINAPI CharLowerW(_Inout_ LPWSTR)
WCHAR classname[128]
Definition: startup.c:15
Definition: match.c:390
long LONG
Definition: pedump.c:60
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
static UINT SHELL_FindExecutableByVerb(LPCWSTR lpVerb, LPWSTR key, LPWSTR classname, LPWSTR command, LONG commandlen)
Definition: shlexec.cpp:627
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define TRACE(s)
Definition: solgame.cpp:4
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LSTATUS WINAPI RegQueryValueW(HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count)
Definition: reg.c:4254
static const WCHAR wszExe[]
Definition: shlexec.cpp:29
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
INT WINAPI GetProfileStringW(LPCWSTR section, LPCWSTR entry, LPCWSTR def_val, LPWSTR buffer, UINT len)
Definition: profile.c:1267
#define wcsicmp
Definition: string.h:1152
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
#define ERR(fmt,...)
Definition: debug.h:109
#define SE_ERR_FNF
Definition: shellapi.h:122
static BOOL SHELL_TryAppPathW(LPCWSTR szName, LPWSTR lpResult, WCHAR **env)
Definition: shlexec.cpp:570
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
unsigned int UINT
Definition: ndis.h:50
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SE_ERR_NOASSOC
Definition: shellapi.h:132
GLfloat GLfloat p
Definition: glext.h:8902
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
Definition: path.c:42

Referenced by FindExecutableW(), and SHELL_execute().

◆ SHELL_FindExecutableByVerb()

static UINT SHELL_FindExecutableByVerb ( LPCWSTR  lpVerb,
LPWSTR  key,
LPWSTR  classname,
LPWSTR  command,
LONG  commandlen 
)
static

Definition at line 627 of file shlexec.cpp.

628 {
629  static const WCHAR wCommand[] = L"\\command";
630  HKEY hkeyClass;
631  WCHAR verb[MAX_PATH];
632 
633  if (RegOpenKeyExW(HKEY_CLASSES_ROOT, classname, 0, 0x02000000, &hkeyClass))
634  return SE_ERR_NOASSOC;
635  if (!HCR_GetDefaultVerbW(hkeyClass, lpVerb, verb, sizeof(verb) / sizeof(verb[0])))
636  return SE_ERR_NOASSOC;
637  RegCloseKey(hkeyClass);
638 
639  /* Looking for ...buffer\shell<verb>\command */
640  wcscat(classname, L"\\shell\\");
641  wcscat(classname, verb);
642  wcscat(classname, wCommand);
643 
645  &commandlen) == ERROR_SUCCESS)
646  {
647  commandlen /= sizeof(WCHAR);
648  if (key) wcscpy(key, classname);
649 #if 0
650  LPWSTR tmp;
651  WCHAR param[256];
652  LONG paramlen = sizeof(param);
653  static const WCHAR wSpace[] = {' ', 0};
654 
655  /* FIXME: it seems all Windows version don't behave the same here.
656  * the doc states that this ddeexec information can be found after
657  * the exec names.
658  * on Win98, it doesn't appear, but I think it does on Win2k
659  */
660  /* Get the parameters needed by the application
661  from the associated ddeexec key */
662  tmp = strstrW(classname, wCommand);
663  tmp[0] = '\0';
664  wcscat(classname, wDdeexec);
666  &paramlen) == ERROR_SUCCESS)
667  {
668  paramlen /= sizeof(WCHAR);
669  wcscat(command, wSpace);
670  wcscat(command, param);
671  commandlen += paramlen;
672  }
673 #endif
674 
675  command[commandlen] = '\0';
676 
677  return 33; /* FIXME see SHELL_FindExecutable() */
678  }
679 
680  return SE_ERR_NOASSOC;
681 }
#define ERROR_SUCCESS
Definition: deptool.c:10
WCHAR classname[128]
Definition: startup.c:15
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
#define strstrW(d, s)
Definition: unicode.h:32
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLfloat param
Definition: glext.h:5796
LSTATUS WINAPI RegQueryValueW(HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count)
Definition: reg.c:4254
#define MAX_PATH
Definition: compat.h:26
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
BOOL HCR_GetDefaultVerbW(HKEY hkeyClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
Definition: classes.c:134
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SE_ERR_NOASSOC
Definition: shellapi.h:132
WCHAR * LPWSTR
Definition: xmlstorage.h:184
Definition: path.c:42

Referenced by SHELL_execute_class(), and SHELL_FindExecutable().

◆ SHELL_GetPathFromIDListForExecuteW()

static HRESULT SHELL_GetPathFromIDListForExecuteW ( LPCITEMIDLIST  pidl,
LPWSTR  pszPath,
UINT  uOutSize 
)
static

Definition at line 407 of file shlexec.cpp.

408 {
409  STRRET strret;
410  CComPtr<IShellFolder> desktop;
411 
412  HRESULT hr = SHGetDesktopFolder(&desktop);
413 
414  if (SUCCEEDED(hr))
415  {
416  hr = desktop->GetDisplayNameOf(pidl, SHGDN_FORPARSING, &strret);
417 
418  if (SUCCEEDED(hr))
419  StrRetToStrNW(pszPath, uOutSize, &strret, pidl);
420  }
421 
422  return hr;
423 }
HRESULT hr
Definition: shlfolder.c:183
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
LONG HRESULT
Definition: typedefs.h:77
BOOL WINAPI StrRetToStrNW(LPWSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
Definition: shellstring.c:84
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SHELL_translate_idlist().

◆ SHELL_quote_and_execute()

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 
)
static

Definition at line 1597 of file shlexec.cpp.

1598 {
1599  UINT_PTR retval;
1600  DWORD len;
1601  WCHAR *wszQuotedCmd;
1602 
1603  /* Length of quotes plus length of command plus NULL terminator */
1604  len = 2 + lstrlenW(wcmd) + 1;
1605  if (wszParameters[0])
1606  {
1607  /* Length of space plus length of parameters */
1608  len += 1 + lstrlenW(wszParameters);
1609  }
1610  wszQuotedCmd = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1611  /* Must quote to handle case where cmd contains spaces,
1612  * else security hole if malicious user creates executable file "C:\\Program"
1613  */
1614  strcpyW(wszQuotedCmd, L"\"");
1615  strcatW(wszQuotedCmd, wcmd);
1616  strcatW(wszQuotedCmd, L"\"");
1617  if (wszParameters[0])
1618  {
1619  strcatW(wszQuotedCmd, L" ");
1620  strcatW(wszQuotedCmd, wszParameters);
1621  }
1622 
1623  TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName), debugstr_w(psei->lpVerb), debugstr_w(wszQuotedCmd), debugstr_w(wszKeyname));
1624 
1625  if (*wszKeyname)
1626  retval = execute_from_key(wszKeyname, wszApplicationName, env, psei->lpParameters, wcmd, execfunc, psei, psei_out);
1627  else
1628  retval = execfunc(wszQuotedCmd, env, FALSE, psei, psei_out);
1629  HeapFree(GetProcessHeap(), 0, wszQuotedCmd);
1630  return retval;
1631 }
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)
Definition: shlexec.cpp:1110
#define lstrlenW
Definition: compat.h:407
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
LPCWSTR lpParameters
Definition: shellapi.h:331
WINE_UNICODE_INLINE WCHAR * strcatW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:242
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by SHELL_execute(), and SHELL_execute_class().

◆ SHELL_translate_idlist()

static BOOL SHELL_translate_idlist ( LPSHELLEXECUTEINFOW  sei,
LPWSTR  wszParameters,
DWORD  parametersLen,
LPWSTR  wszApplicationName,
DWORD  dwApplicationNameLen 
)
static

Definition at line 1550 of file shlexec.cpp.

1551 {
1552  static const WCHAR wExplorer[] = L"explorer.exe";
1554  BOOL appKnownSingular = FALSE;
1555 
1556  /* last chance to translate IDList: now also allow CLSID paths */
1558  if (buffer[0] == ':' && buffer[1] == ':') {
1559  /* open shell folder for the specified class GUID */
1560  if (strlenW(buffer) + 1 > parametersLen)
1561  ERR("parameters len exceeds buffer size (%i > %i), truncating\n",
1562  lstrlenW(buffer) + 1, parametersLen);
1563  lstrcpynW(wszParameters, buffer, parametersLen);
1564  if (strlenW(wExplorer) > dwApplicationNameLen)
1565  ERR("application len exceeds buffer size (%i > %i), truncating\n",
1566  lstrlenW(wExplorer) + 1, dwApplicationNameLen);
1567  lstrcpynW(wszApplicationName, wExplorer, dwApplicationNameLen);
1568  appKnownSingular = TRUE;
1569 
1570  sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
1571  } else {
1573  DWORD attribs;
1574  DWORD resultLen;
1575  /* Check if we're executing a directory and if so use the
1576  handler for the Folder class */
1577  strcpyW(target, buffer);
1581  HCR_GetExecuteCommandW(0, L"Folder",
1582  sei->lpVerb,
1583  buffer, sizeof(buffer))) {
1584  SHELL_ArgifyW(wszApplicationName, dwApplicationNameLen,
1585  buffer, target, (LPITEMIDLIST)sei->lpIDList, NULL, &resultLen,
1586  (sei->lpDirectory && *sei->lpDirectory) ? sei->lpDirectory : NULL);
1587  if (resultLen > dwApplicationNameLen)
1588  ERR("Argify buffer not large enough... truncating\n");
1589  appKnownSingular = FALSE;
1590  }
1591  sei->fMask &= ~SEE_MASK_INVOKEIDLIST;
1592  }
1593  }
1594  return appKnownSingular;
1595 }
#define TRUE
Definition: types.h:120
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
static BOOL SHELL_ArgifyW(WCHAR *out, DWORD len, const WCHAR *fmt, const WCHAR *lpFile, LPITEMIDLIST pidl, LPCWSTR args, DWORD *out_len, const WCHAR *lpDir)
Definition: shlexec.cpp:184
const GLint * attribs
Definition: glext.h:10538
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
GLuint buffer
Definition: glext.h:5915
#define lstrlenW
Definition: compat.h:407
#define lstrcpynW
Definition: compat.h:397
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
LPCWSTR lpDirectory
Definition: shellapi.h:332
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1250
#define ERR(fmt,...)
Definition: debug.h:109
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
BOOL HCR_GetExecuteCommandW(HKEY hkeyClass, LPCWSTR szClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
Definition: classes.c:200
GLenum target
Definition: glext.h:7315
#define SEE_MASK_INVOKEIDLIST
Definition: shellapi.h:28
static HRESULT SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl, LPWSTR pszPath, UINT uOutSize)
Definition: shlexec.cpp:407
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SHELL_execute().

◆ SHELL_TryAppPathW()

static BOOL SHELL_TryAppPathW ( LPCWSTR  szName,
LPWSTR  lpResult,
WCHAR **  env 
)
static

Definition at line 570 of file shlexec.cpp.

571 {
572  HKEY hkApp = 0;
573  WCHAR buffer[1024];
574  LONG len;
575  LONG res;
576  BOOL found = FALSE;
577 
578  if (env) *env = NULL;
579  wcscpy(buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
580  wcscat(buffer, szName);
582  if (res)
583  {
584  // Add ".exe" extension, if extension does not exists
586  {
588  }
589  if (res) goto end;
590  }
591 
592  len = MAX_PATH * sizeof(WCHAR);
593  res = RegQueryValueW(hkApp, NULL, lpResult, &len);
594  if (res) goto end;
595  found = TRUE;
596 
597  if (env)
598  {
599  DWORD count = sizeof(buffer);
600  if (!RegQueryValueExW(hkApp, L"Path", NULL, NULL, (LPBYTE)buffer, &count) && buffer[0])
602  }
603 
604 end:
605  if (hkApp) RegCloseKey(hkApp);
606  return found;
607 }
#define TRUE
Definition: types.h:120
#define KEY_READ
Definition: nt_native.h:1023
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLuint GLuint end
Definition: gl.h:1545
static LPWSTR SHELL_BuildEnvW(const WCHAR *path)
Definition: shlexec.cpp:510
BOOL WINAPI PathAddExtensionW(LPWSTR lpszPath, LPCWSTR lpszExtension)
Definition: path.c:2617
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
LSTATUS WINAPI RegQueryValueW(HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count)
Definition: reg.c:4254
#define MAX_PATH
Definition: compat.h:26
static const WCHAR wszExe[]
Definition: shlexec.cpp:29
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static LPCWSTR LPCWSTR LPCWSTR env
Definition: db.cpp:168
static const WCHAR szName[]
Definition: msipriv.h:1194
GLuint res
Definition: glext.h:9613
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by SHELL_FindExecutable().

◆ shellex_get_dataobj()

static IDataObject* shellex_get_dataobj ( LPSHELLEXECUTEINFOW  sei)
static

Definition at line 1289 of file shlexec.cpp.

1290 {
1291  LPCITEMIDLIST pidllast = NULL;
1292  CComPtr<IDataObject> dataobj;
1294  LPITEMIDLIST pidl = NULL;
1295  HRESULT r;
1296 
1297  if (sei->fMask & SEE_MASK_CLASSALL)
1298  pidl = (LPITEMIDLIST)sei->lpIDList;
1299  else
1300  {
1301  WCHAR fullpath[MAX_PATH];
1302  BOOL ret;
1303 
1304  fullpath[0] = 0;
1305  ret = GetFullPathNameW(sei->lpFile, MAX_PATH, fullpath, NULL);
1306  if (!ret)
1307  goto end;
1308 
1309  pidl = ILCreateFromPathW(fullpath);
1310  }
1311 
1312  r = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &shf), &pidllast);
1313  if (FAILED(r))
1314  goto end;
1315 
1316  shf->GetUIObjectOf(NULL, 1, &pidllast, IID_NULL_PPV_ARG(IDataObject, &dataobj));
1317 
1318 end:
1319  if (pidl != sei->lpIDList)
1320  ILFree(pidl);
1321  return dataobj.Detach();
1322 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1105
GLuint GLuint end
Definition: gl.h:1545
#define IID_PPV_ARG(Itype, ppType)
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define IID_NULL_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
int ret
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1323
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:982
T * Detach()
Definition: atlcomcli.h:156
#define SEE_MASK_CLASSALL
Definition: shlexec.cpp:32
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

Referenced by shellex_load_object_and_run().

◆ shellex_load_object_and_run()

static HRESULT shellex_load_object_and_run ( HKEY  hkey,
LPCGUID  guid,
LPSHELLEXECUTEINFOW  sei 
)
static

Definition at line 1393 of file shlexec.cpp.

1394 {
1395  // Can not use CComPtr here because of CoUninitialize at the end, before the destructors would run.
1396  IDataObject *dataobj = NULL;
1397  IObjectWithSite *ows = NULL;
1398  IShellExtInit *obj = NULL;
1399  HRESULT r;
1400 
1401  TRACE("%p %s %p\n", hkey, debugstr_guid(guid), sei);
1402 
1403  r = CoInitialize(NULL);
1404  if (FAILED(r))
1405  goto end;
1406 
1407  r = CoCreateInstance(*guid, NULL, CLSCTX_INPROC_SERVER,
1409  if (FAILED(r))
1410  {
1411  ERR("failed %08x\n", r);
1412  goto end;
1413  }
1414 
1415  dataobj = shellex_get_dataobj(sei);
1416  if (!dataobj)
1417  {
1418  ERR("failed to get data object\n");
1419  r = E_FAIL;
1420  goto end;
1421  }
1422 
1423  r = obj->Initialize(NULL, dataobj, hkey);
1424  if (FAILED(r))
1425  goto end;
1426 
1427  r = obj->QueryInterface(IID_PPV_ARG(IObjectWithSite, &ows));
1428  if (FAILED(r))
1429  goto end;
1430 
1431  ows->SetSite(NULL);
1432 
1434 
1435 end:
1436  if (ows)
1437  ows->Release();
1438  if (dataobj)
1439  dataobj->Release();
1440  if (obj)
1441  obj->Release();
1442  CoUninitialize();
1443  return r;
1444 }
static IDataObject * shellex_get_dataobj(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:1289
static HRESULT shellex_run_context_menu_default(IShellExtInit *obj, LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:1324
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLuint end
Definition: gl.h:1545
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
const GUID * guid
ULONG Release()
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
#define ERR(fmt,...)
Definition: debug.h:109
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1897
HRESULT SetSite([in] IUnknown *pUnkSite)

Referenced by ShellExecute_FromContextMenu().

◆ shellex_run_context_menu_default()

static HRESULT shellex_run_context_menu_default ( IShellExtInit obj,
LPSHELLEXECUTEINFOW  sei 
)
static

Definition at line 1324 of file shlexec.cpp.

1326 {
1328  CMINVOKECOMMANDINFOEX ici;
1330  WCHAR string[0x80];
1331  INT i, n, def = -1;
1332  HMENU hmenu = 0;
1333  HRESULT r;
1334 
1335  TRACE("%p %p\n", obj, sei);
1336 
1337  r = obj->QueryInterface(IID_PPV_ARG(IContextMenu, &cm));
1338  if (FAILED(r))
1339  return r;
1340 
1341  hmenu = CreateMenu();
1342  if (!hmenu)
1343  goto end;
1344 
1345  /* the number of the last menu added is returned in r */
1346  r = cm->QueryContextMenu(hmenu, 0, 0x20, 0x7fff, CMF_DEFAULTONLY);
1347  if (FAILED(r))
1348  goto end;
1349 
1351  for (i = 0; i < n; i++)
1352  {
1353  memset(&info, 0, sizeof(info));
1354  info.cbSize = sizeof info;
1356  info.dwTypeData = string;
1357  info.cch = sizeof string;
1358  string[0] = 0;
1360 
1361  TRACE("menu %d %s %08x %08lx %08x %08x\n", i, debugstr_w(string),
1362  info.fState, info.dwItemData, info.fType, info.wID);
1363  if ((!sei->lpVerb && (info.fState & MFS_DEFAULT)) ||
1364  (sei->lpVerb && !lstrcmpiW(sei->lpVerb, string)))
1365  {
1366  def = i;
1367  break;
1368  }
1369  }
1370 
1371  r = E_FAIL;
1372  if (def == -1)
1373  goto end;
1374 
1375  memset(&ici, 0, sizeof ici);
1376  ici.cbSize = sizeof ici;
1377  ici.fMask = CMIC_MASK_UNICODE | (sei->fMask & (SEE_MASK_NO_CONSOLE | SEE_MASK_NOASYNC | SEE_MASK_ASYNCOK | SEE_MASK_FLAG_NO_UI));
1378  ici.nShow = sei->nShow;
1379  ici.lpVerb = MAKEINTRESOURCEA(def);
1380  ici.hwnd = sei->hwnd;
1381  ici.lpParametersW = sei->lpParameters;
1382 
1383  r = cm->InvokeCommand((LPCMINVOKECOMMANDINFO)&ici);
1384 
1385  TRACE("invoke command returned %08x\n", r);
1386 
1387 end:
1388  if (hmenu)
1389  DestroyMenu( hmenu );
1390  return r;
1391 }
HMENU WINAPI CreateMenu(void)
Definition: menu.c:837
#define MIIM_FTYPE
Definition: winuser.h:724
#define TRUE
Definition: types.h:120
static HMENU hmenu
Definition: win.c:66
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define SEE_MASK_NO_CONSOLE
Definition: shellapi.h:38
GLdouble n
Definition: glext.h:7729
#define SEE_MASK_ASYNCOK
Definition: shellapi.h:52
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
GLuint GLuint end
Definition: gl.h:1545
#define MFS_DEFAULT
Definition: winuser.h:743
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
int32_t INT
Definition: typedefs.h:56
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
struct _test_info info[]
Definition: SetCursorPos.c:19
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define MIIM_STATE
Definition: winuser.h:716
#define debugstr_w
Definition: kernel32.h:32
int WINAPI GetMenuItemCount(_In_opt_ HMENU)
smooth NULL
Definition: ftsmooth.c:416
#define SEE_MASK_NOASYNC
Definition: shellapi.h:33
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:36
#define MIIM_ID
Definition: winuser.h:717
BOOL WINAPI GetMenuItemInfoW(_In_ HMENU, _In_ UINT, _In_ BOOL, _Inout_ LPMENUITEMINFOW)
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
char string[160]
Definition: util.h:11
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define MIIM_STRING
Definition: winuser.h:722
LPCWSTR lpParameters
Definition: shellapi.h:331
#define MIIM_DATA
Definition: winuser.h:721
#define memset(x, y, z)
Definition: compat.h:39
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60

Referenced by shellex_load_object_and_run().

◆ ShellExecCmdLine()

HRESULT WINAPI ShellExecCmdLine ( HWND  hwnd,
LPCWSTR  pwszCommand,
LPCWSTR  pwszStartDir,
int  nShow,
LPVOID  pUnused,
DWORD  dwSeclFlags 
)

Definition at line 2349 of file shlexec.cpp.

2356 {
2359  LPCWSTR pszVerb = NULL;
2360  WCHAR szFile[MAX_PATH], szFile2[MAX_PATH];
2361  HRESULT hr;
2362  LPCWSTR pchParams;
2363  LPWSTR lpCommand = NULL;
2364 
2365  if (pwszCommand == NULL)
2367  1, (ULONG_PTR*)pwszCommand);
2368 
2369  __SHCloneStrW(&lpCommand, pwszCommand);
2370  StrTrimW(lpCommand, L" \t");
2371 
2372  if (dwSeclFlags & SECL_NO_UI)
2374  if (dwSeclFlags & SECL_LOG_USAGE)
2376  if (dwSeclFlags & SECL_USE_IDLIST)
2378 
2379  if (dwSeclFlags & SECL_RUNAS)
2380  {
2381  dwSize = 0;
2382  hr = AssocQueryStringW(0, ASSOCSTR_COMMAND, lpCommand, L"RunAs", NULL, &dwSize);
2383  if (SUCCEEDED(hr) && dwSize != 0)
2384  {
2385  pszVerb = L"runas";
2386  }
2387  }
2388 
2389  if (PathIsURLW(lpCommand) || UrlIsW(lpCommand, URLIS_APPLIABLE))
2390  {
2391  StringCchCopyW(szFile, _countof(szFile), lpCommand);
2392  pchParams = NULL;
2393  }
2394  else
2395  {
2396  pchParams = SplitParams(lpCommand, szFile, _countof(szFile));
2397  if (szFile[0] != UNICODE_NULL && szFile[1] == L':' &&
2398  szFile[2] == UNICODE_NULL)
2399  {
2400  PathAddBackslashW(szFile);
2401  }
2402  if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) ||
2403  SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) ||
2404  SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) ||
2405  SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) ||
2406  SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) ||
2407  SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL))
2408  {
2409  StringCchCopyW(szFile, _countof(szFile), szFile2);
2410  }
2411  else if (SearchPathW(NULL, lpCommand, NULL, _countof(szFile2), szFile2, NULL) ||
2412  SearchPathW(NULL, lpCommand, wszExe, _countof(szFile2), szFile2, NULL) ||
2413  SearchPathW(NULL, lpCommand, wszCom, _countof(szFile2), szFile2, NULL) ||
2414  SearchPathW(pwszStartDir, lpCommand, NULL, _countof(szFile2), szFile2, NULL) ||
2415  SearchPathW(pwszStartDir, lpCommand, wszExe, _countof(szFile2), szFile2, NULL) ||
2416  SearchPathW(pwszStartDir, lpCommand, wszCom, _countof(szFile2), szFile2, NULL))
2417  {
2418  StringCchCopyW(szFile, _countof(szFile), szFile2);
2419  pchParams = NULL;
2420  }
2421 
2422  if (!(dwSeclFlags & SECL_ALLOW_NONEXE))
2423  {
2424  if (!GetBinaryTypeW(szFile, &dwType))
2425  {
2426  SHFree(lpCommand);
2427 
2428  if (!(dwSeclFlags & SECL_NO_UI))
2429  {
2430  WCHAR szText[128 + MAX_PATH], szFormat[128];
2432  StringCchPrintfW(szText, _countof(szText), szFormat, szFile);
2434  }
2435  return CO_E_APPNOTFOUND;
2436  }
2437  }
2438  else
2439  {
2441  {
2442  SHFree(lpCommand);
2443 
2444  if (!(dwSeclFlags & SECL_NO_UI))
2445  {
2446  WCHAR szText[128 + MAX_PATH], szFormat[128];
2448  StringCchPrintfW(szText, _countof(szText), szFormat, szFile);
2450  }
2452  }
2453  }
2454  }
2455 
2456  ZeroMemory(&info, sizeof(info));
2457  info.cbSize = sizeof(info);
2458  info.fMask = dwFlags;
2459  info.hwnd = hwnd;
2460  info.lpVerb = pszVerb;
2461  info.lpFile = szFile;
2462  info.lpParameters = (pchParams && *pchParams) ? pchParams : NULL;
2463  info.lpDirectory = pwszStartDir;
2464  info.nShow = nShow;
2465  if (ShellExecuteExW(&info))
2466  {
2467  if (info.lpIDList)
2468  CoTaskMemFree(info.lpIDList);
2469 
2470  SHFree(lpCommand);
2471 
2472  return S_OK;
2473  }
2474 
2475  dwError = GetLastError();
2476 
2477  SHFree(lpCommand);
2478 
2479  return HRESULT_FROM_WIN32(dwError);
2480 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define SECL_USE_IDLIST
#define _countof(array)
Definition: fontsub.cpp:30
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:308
#define SECL_NO_UI
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
#define SECL_RUNAS
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
static LPCWSTR SplitParams(LPCWSTR psz, LPWSTR pszArg0, size_t cchArg0)
Definition: shlexec.cpp:2303
BOOL WINAPI GetBinaryTypeW(LPCWSTR lpApplicationName, LPDWORD lpBinaryType)
Definition: vdm.c:1235
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
BOOL WINAPI PathIsURLW(LPCWSTR lpstrPath)
Definition: url.c:2432
struct _test_info info[]
Definition: SetCursorPos.c:19
uint32_t ULONG_PTR
Definition: typedefs.h:63
static __inline void __SHCloneStrW(WCHAR **target, const WCHAR *source)
Definition: shell32_main.h:154
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
#define UNICODE_NULL
static const WCHAR szText[]
Definition: dialog.c:139
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:289
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
smooth NULL
Definition: ftsmooth.c:416
#define SEE_MASK_NOASYNC
Definition: shellapi.h:33
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:36
#define SECL_LOG_USAGE
#define SECL_ALLOW_NONEXE
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2197
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc, LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
Definition: assoc.c:427
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static const WCHAR wszCom[]
Definition: shlexec.cpp:30
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
#define SEE_MASK_DOENVSUBST
Definition: shellapi.h:35
static const WCHAR wszExe[]
Definition: shlexec.cpp:29
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1250
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define MB_ICONERROR
Definition: winuser.h:781
#define IDS_FILE_NOT_FOUND
Definition: shresdef.h:285
BOOL WINAPI UrlIsW(LPCWSTR pszUrl, URLIS Urlis)
Definition: url.c:1933
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
#define S_OK
Definition: intsafe.h:59
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693
#define SEE_MASK_FLAG_LOG_USAGE
Definition: shellapi.h:57
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
BOOL WINAPI StrTrimW(LPWSTR lpszStr, LPCWSTR lpszTrim)
Definition: string.c:1869
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331
#define SEE_MASK_INVOKEIDLIST
Definition: shellapi.h:28
#define CO_E_APPNOTFOUND
Definition: winerror.h:2808
WCHAR * LPWSTR
Definition: xmlstorage.h:184
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by DoEntry(), and RunDlgProc().

◆ ShellExecute_FromContextMenu()

static LONG ShellExecute_FromContextMenu ( LPSHELLEXECUTEINFOW  sei)
static

Definition at line 1450 of file shlexec.cpp.

1451 {
1452  HKEY hkey, hkeycm = 0;
1453  WCHAR szguid[39];
1454  HRESULT hr;
1455  GUID guid;
1456  DWORD i;
1457  LONG r;
1458 
1459  TRACE("%s\n", debugstr_w(sei->lpFile));
1460 
1461  hkey = ShellExecute_GetClassKey(sei);
1462  if (!hkey)
1463  return ERROR_FUNCTION_FAILED;
1464 
1465  r = RegOpenKeyW(hkey, L"shellex\\ContextMenuHandlers", &hkeycm);
1466  if (r == ERROR_SUCCESS)
1467  {
1468  i = 0;
1469  while (1)
1470  {
1471  r = RegEnumKeyW(hkeycm, i++, szguid, sizeof(szguid) / sizeof(szguid[0]));
1472  if (r != ERROR_SUCCESS)
1473  break;
1474 
1475  hr = CLSIDFromString(szguid, &guid);
1476  if (SUCCEEDED(hr))
1477  {
1478  /* stop at the first one that succeeds in running */
1479  hr = shellex_load_object_and_run(hkey, &guid, sei);
1480  if (SUCCEEDED(hr))
1481  break;
1482  }
1483  }
1484  RegCloseKey(hkeycm);
1485  }
1486 
1487  if (hkey != sei->hkeyClass)
1488  RegCloseKey(hkey);
1489  return r;
1490 }
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const GUID * guid
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
static HKEY ShellExecute_GetClassKey(const SHELLEXECUTEINFOW *sei)
Definition: shlexec.cpp:1241
long LONG
Definition: pedump.c:60
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3296
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LONG WINAPI RegEnumKeyW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cbName)
Definition: reg.c:2416
static HRESULT shellex_load_object_and_run(HKEY hkey, LPCGUID guid, LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:1393
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2247
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SHELL_execute().

◆ ShellExecute_GetClassKey()

static HKEY ShellExecute_GetClassKey ( const SHELLEXECUTEINFOW sei)
static

Definition at line 1241 of file shlexec.cpp.

1242 {
1243  LPCWSTR ext = NULL, lpClass = NULL;
1244  LPWSTR cls = NULL;
1245  DWORD type = 0, sz = 0;
1246  HKEY hkey = 0;
1247  LONG r;
1248 
1249  if (sei->fMask & SEE_MASK_CLASSALL)
1250  return sei->hkeyClass;
1251 
1252  if (sei->fMask & SEE_MASK_CLASSNAME)
1253  lpClass = sei->lpClass;
1254  else
1255  {
1256  ext = PathFindExtensionW(sei->lpFile);
1257  TRACE("ext = %s\n", debugstr_w(ext));
1258  if (!ext)
1259  return hkey;
1260 
1261  r = RegOpenKeyW(HKEY_CLASSES_ROOT, ext, &hkey);
1262  if (r != ERROR_SUCCESS)
1263  return hkey;
1264 
1265  r = RegQueryValueExW(hkey, NULL, 0, &type, NULL, &sz);
1266  if (r == ERROR_SUCCESS && type == REG_SZ)
1267  {
1268  sz += sizeof (WCHAR);
1269  cls = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sz);
1270  cls[0] = 0;
1271  RegQueryValueExW(hkey, NULL, 0, &type, (LPBYTE) cls, &sz);
1272  }
1273 
1274  RegCloseKey( hkey );
1275  lpClass = cls;
1276  }
1277 
1278  TRACE("class = %s\n", debugstr_w(lpClass));
1279 
1280  hkey = 0;
1281  if (lpClass)
1282  RegOpenKeyW( HKEY_CLASSES_ROOT, lpClass, &hkey);
1283 
1284  HeapFree(GetProcessHeap(), 0, cls);
1285 
1286  return hkey;
1287 }
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3296
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
char ext[3]
Definition: mkdosfs.c:358
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:442
#define TRACE(s)
Definition: solgame.cpp:4
#define SEE_MASK_CLASSNAME
Definition: shellapi.h:25
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define SEE_MASK_CLASSALL
Definition: shlexec.cpp:32
#define HeapFree(x, y, z)
Definition: compat.h:394
#define REG_SZ
Definition: layer.c:22

Referenced by ShellExecute_FromContextMenu().

◆ ShellExecuteA()

HINSTANCE WINAPI ShellExecuteA ( HWND  hWnd,
LPCSTR  lpVerb,
LPCSTR  lpFile,
LPCSTR  lpParameters,
LPCSTR  lpDirectory,
INT  iShowCmd 
)

Definition at line 2113 of file shlexec.cpp.

2115 {
2116  SHELLEXECUTEINFOA sei;
2117 
2118  TRACE("%p,%s,%s,%s,%s,%d\n",
2119  hWnd, debugstr_a(lpVerb), debugstr_a(lpFile),
2120  debugstr_a(lpParameters), debugstr_a(lpDirectory), iShowCmd);
2121 
2122  sei.cbSize = sizeof(sei);
2123  sei.fMask = SEE_MASK_FLAG_NO_UI;
2124  sei.hwnd = hWnd;
2125  sei.lpVerb = lpVerb;
2126  sei.lpFile = lpFile;
2127  sei.lpParameters = lpParameters;
2128  sei.lpDirectory = lpDirectory;
2129  sei.nShow = iShowCmd;
2130  sei.lpIDList = 0;
2131  sei.lpClass = 0;
2132  sei.hkeyClass = 0;
2133  sei.dwHotKey = 0;
2134  sei.hProcess = 0;
2135 
2136  ShellExecuteExA(&sei);
2137  return sei.hInstApp;
2138 }
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExA(LPSHELLEXECUTEINFOA sei)
Definition: shlexec.cpp:2147
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstApp
Definition: shellapi.h:317
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:36
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:482
#define TRACE(s)
Definition: solgame.cpp:4
LPCSTR lpParameters
Definition: shellapi.h:314
#define debugstr_a
Definition: kernel32.h:31
LPCSTR lpDirectory
Definition: shellapi.h:315

Referenced by FileProtocolHandlerA(), MACRO_ExecFile(), and shell_execute_().

◆ ShellExecuteExA()

Definition at line 2147 of file shlexec.cpp.

2148 {
2149  SHELLEXECUTEINFOW seiW;
2150  BOOL ret;
2151  WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL, *wClass = NULL;
2152 
2153  TRACE("%p\n", sei);
2154 
2155  memcpy(&seiW, sei, sizeof(SHELLEXECUTEINFOW));
2156 
2157  if (sei->lpVerb)
2158  seiW.lpVerb = __SHCloneStrAtoW(&wVerb, sei->lpVerb);
2159 
2160  if (sei->lpFile)
2161  seiW.lpFile = __SHCloneStrAtoW(&wFile, sei->lpFile);
2162 
2163  if (sei->lpParameters)
2164  seiW.lpParameters = __SHCloneStrAtoW(&wParameters, sei->lpParameters);
2165 
2166  if (sei->lpDirectory)
2167  seiW.lpDirectory = __SHCloneStrAtoW(&wDirectory, sei->lpDirectory);
2168 
2169  if ((sei->fMask & SEE_MASK_CLASSALL) == SEE_MASK_CLASSNAME && sei->lpClass)
2170  seiW.lpClass = __SHCloneStrAtoW(&wClass, sei->lpClass);
2171  else
2172  seiW.lpClass = NULL;
2173 
2174  ret = SHELL_execute(&seiW, SHELL_ExecuteW);
2175 
2176  sei->hInstApp = seiW.hInstApp;
2177 
2178  if (sei->fMask & SEE_MASK_NOCLOSEPROCESS)
2179  sei->hProcess = seiW.hProcess;
2180 
2181  SHFree(wVerb);
2182  SHFree(wFile);
2183  SHFree(wParameters);
2184  SHFree(wDirectory);
2185  SHFree(wClass);
2186 
2187  return ret;
2188 }
HINSTANCE hInstApp
Definition: shellapi.h:334
static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
Definition: shlexec.cpp:1713
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:31
unsigned int BOOL
Definition: ntddk_ex.h:94
HINSTANCE hInstApp
Definition: shellapi.h:317
LPCWSTR lpDirectory
Definition: shellapi.h:332
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define SEE_MASK_CLASSNAME
Definition: shellapi.h:25
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPCSTR lpParameters
Definition: shellapi.h:314
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LPCSTR lpDirectory
Definition: shellapi.h:315
static __inline LPWSTR __SHCloneStrAtoW(WCHAR **target, const char *source)
Definition: shell32_main.h:160
LPCWSTR lpParameters
Definition: shellapi.h:331
static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait, const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
Definition: shlexec.cpp:429
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331
#define SEE_MASK_CLASSALL
Definition: shlexec.cpp:32

Referenced by shell_execute_ex_(), and ShellExecuteA().

◆ ShellExecuteExW()

◆ ShellExecuteW()

HINSTANCE WINAPI ShellExecuteW ( HWND  hwnd,
LPCWSTR  lpVerb,
LPCWSTR  lpFile,
LPCWSTR  lpParameters,
LPCWSTR  lpDirectory,
INT  nShowCmd 
)

Definition at line 2208 of file shlexec.cpp.

2210 {
2211  SHELLEXECUTEINFOW sei;
2212 
2213  TRACE("\n");
2214  sei.cbSize = sizeof(sei);
2215  sei.fMask = SEE_MASK_FLAG_NO_UI;
2216  sei.hwnd = hwnd;
2217  sei.lpVerb = lpVerb;
2218  sei.lpFile = lpFile;
2219  sei.lpParameters = lpParameters;
2220  sei.lpDirectory = lpDirectory;
2221  sei.nShow = nShowCmd;
2222  sei.lpIDList = 0;
2223  sei.lpClass = 0;
2224  sei.hkeyClass = 0;
2225  sei.dwHotKey = 0;
2226  sei.hProcess = 0;
2227 
2229  return sei.hInstApp;
2230 }
HINSTANCE hInstApp
Definition: shellapi.h:334
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
Definition: shlexec.cpp:1713
LPCWSTR lpDirectory
Definition: shellapi.h:332
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:36
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:482
#define TRACE(s)
Definition: solgame.cpp:4
LPCWSTR lpParameters
Definition: shellapi.h:331
static UINT_PTR SHELL_ExecuteW(const WCHAR *lpCmd, WCHAR *env, BOOL shWait, const SHELLEXECUTEINFOW *psei, LPSHELLEXECUTEINFOW psei_out)
Definition: shlexec.cpp:429

Referenced by _RunHotplug(), _RunMMCpl(), _RunPower(), _RunVolume(), CDrivesFolder::CallBack(), CDesktopFolder::CallBack(), Control_StartApplet(), CPlApplet(), DIALOG_EXECUTE_DlgProc(), DisplayApplet(), CExeDropHandler::Drop(), CTrayWindow::ExecContextMenuCmd(), CTrayWindow::ExecResourceCmd(), CDrvDefExt::ExtraPageProc(), CDrvDefExt::GeneralPageProc(), GeneralPageProc(), CTrayWindow::HandleCommand(), CTrayWindow::HandleHotKey(), IHlink_fnNavigate(), CCPLItemMenu::InvokeCommand(), launch_file(), LaunchDeviceManager(), LaunchSoundControl(), MainWnd_OnOpenRegKey(), msi_dialog_hyperlink_handler(), OnAddStartMenuItems(), OnAdvancedStartMenuItems(), CMainWindow::OnCommand(), CShellMenuCallback::OnExec(), CTrayClockWnd::OnLButtonDblClick(), OnLink(), OnNotify(), OnRemoveStartmenuItems(), CZipExtract::CCompleteSettingsPage::OnWizardFinish(), OpenShellFolder(), PROGRAM_ExecuteProgram(), RegFolderContextMenuCallback(), RouteTheCall(), RunCommand(), SHELL_execute(), CShellDispatch::ShellExecute(), SHFindFiles(), and StartRecDlgProc().

◆ SplitParams()

static LPCWSTR SplitParams ( LPCWSTR  psz,
LPWSTR  pszArg0,
size_t  cchArg0 
)
static

Definition at line 2303 of file shlexec.cpp.

2304 {
2305  LPCWSTR pch;
2306  size_t ich = 0;
2307  if (*psz == L'"')
2308  {
2309  // 1st argument is quoted. the string in quotes is quoted 1st argument.
2310  // [pch] --> [pszArg0+ich]
2311  for (pch = psz + 1; *pch && ich + 1 < cchArg0; ++ich, ++pch)
2312  {
2313  if (*pch == L'"' && pch[1] == L'"')
2314  {
2315  // doubled double quotations found!
2316  pszArg0[ich] = L'"';
2317  }
2318  else if (*pch == L'"')
2319  {
2320  // single double quotation found!
2321  ++pch;
2322  break;
2323  }
2324  else
2325  {
2326  // otherwise
2327  pszArg0[ich] = *pch;
2328  }
2329  }
2330  }
2331  else
2332  {
2333  // 1st argument is unquoted. non-space sequence is 1st argument.
2334  // [pch] --> [pszArg0+ich]
2335  for (pch = psz; *pch && !iswspace(*pch) && ich + 1 < cchArg0; ++ich, ++pch)
2336  {
2337  pszArg0[ich] = *pch;
2338  }
2339  }
2340  pszArg0[ich] = 0;
2341 
2342  // skip space
2343  while (iswspace(*pch))
2344  ++pch;
2345 
2346  return pch;
2347 }
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define pch(ap)
Definition: match.c:418
#define iswspace(_c)
Definition: ctype.h:669
static const WCHAR L[]
Definition: oid.c:1250

Referenced by ShellExecCmdLine().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( exec  )

◆ WOWShellExecute()

EXTERN_C HINSTANCE WINAPI WOWShellExecute ( HWND  hWnd,
LPCSTR  lpVerb,
LPCSTR  lpFile,
LPCSTR  lpParameters,
LPCSTR  lpDirectory,
INT  iShowCmd,
void callback 
)

Definition at line 2237 of file shlexec.cpp.

2239 {
2240  SHELLEXECUTEINFOW seiW;
2241  WCHAR *wVerb = NULL, *wFile = NULL, *wParameters = NULL, *wDirectory = NULL;
2242  HANDLE hProcess = 0;
2243 
2244  seiW.lpVerb = lpVerb ? __SHCloneStrAtoW(&wVerb, lpVerb) : NULL;
2245  seiW.lpFile = lpFile ? __SHCloneStrAtoW(&wFile, lpFile) : NULL;
2246  seiW.lpParameters = lpParameters ? __SHCloneStrAtoW(&wParameters, lpParameters) : NULL;
2247  seiW.lpDirectory = lpDirectory ? __SHCloneStrAtoW(&wDirectory, lpDirectory) : NULL;
2248 
2249  seiW.cbSize = sizeof(seiW);
2250  seiW.fMask = 0;
2251  seiW.hwnd = hWnd;
2252  seiW.nShow = iShowCmd;
2253  seiW.lpIDList = 0;
2254  seiW.lpClass = 0;
2255  seiW.hkeyClass = 0;
2256  seiW.dwHotKey = 0;
2257  seiW.hProcess = hProcess;
2258 
2260 
2261  SHFree(wVerb);
2262  SHFree(wFile);
2263  SHFree(wParameters);
2264  SHFree(wDirectory);
2265  return seiW.hInstApp;
2266 }
HINSTANCE hInstApp
Definition: shellapi.h:334
static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
Definition: shlexec.cpp:1713
HWND hWnd
Definition: settings.c:17
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
LPCWSTR lpDirectory
Definition: shellapi.h:332
UINT_PTR(* SHELL_ExecuteW32)(const WCHAR *lpCmd, WCHAR *env, BOOL shWait, const SHELLEXECUTEINFOW *sei, LPSHELLEXECUTEINFOW sei_out)
Definition: shlexec.cpp:34
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:482
MmuTrapHandler callback[0x30]
Definition: mmuobject.c:44
__wchar_t WCHAR
Definition: xmlstorage.h:180
static __inline LPWSTR __SHCloneStrAtoW(WCHAR **target, const char *source)
Definition: shell32_main.h:160
LPCWSTR lpParameters
Definition: shellapi.h:331
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:331

Variable Documentation

◆ wszCom

const WCHAR wszCom[] = L".com"
static

Definition at line 30 of file shlexec.cpp.

Referenced by ShellExecCmdLine().

◆ wszExe

const WCHAR wszExe[] = L".exe"
static

◆ wszOpen

const WCHAR wszOpen[] = L"open"
static