2 * Shell Library Functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
45 #include "wine/winbase16.h"
46 #include "shell32_main.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(exec
);
53 static const WCHAR wszOpen
[] = {'o','p','e','n',0};
54 static const WCHAR wszExe
[] = {'.','e','x','e',0};
55 static const WCHAR wszILPtr
[] = {':','%','p',0};
56 static const WCHAR wszShell
[] = {'\\','s','h','e','l','l','\\',0};
57 static const WCHAR wszFolder
[] = {'F','o','l','d','e','r',0};
58 static const WCHAR wszEmpty
[] = {0};
60 #define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)
63 /***********************************************************************
64 * SHELL_ArgifyW [Internal]
66 * this function is supposed to expand the escape sequences found in the registry
67 * some diving reported that the following were used:
68 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
73 * %I address of a global item ID (explorer switch /idlist)
74 * %L seems to be %1 as long filename followed by the 8+3 variation
76 * %* all following parameters (see batfile)
79 * FIXME: Careful of going over string boundaries. No checking is done to 'res'...
81 static BOOL
SHELL_ArgifyW(WCHAR
* out
, int len
, const WCHAR
* fmt
, const WCHAR
* lpFile
, LPITEMIDLIST pidl
, LPCWSTR args
)
85 BOOL found_p1
= FALSE
;
90 TRACE("%p, %d, %s, %s, %p, %p\n", out
, len
, debugstr_w(fmt
),
91 debugstr_w(lpFile
), pidl
, args
);
125 while(*args
&& !isspace(*args
))
128 while(isspace(*args
))
133 /* else fall through */
135 if (!done
|| (*fmt
== '1'))
137 /*FIXME Is the call to SearchPathW() really needed? We already have separated out the parameter string in args. */
138 if (SearchPathW(NULL
, lpFile
, wszExe
, sizeof(xlpFile
)/sizeof(WCHAR
), xlpFile
, NULL
))
143 /* Add double quotation marks unless we already have them
144 (e.g.: "file://%1" %* for exefile) or unless the arg is already
145 enclosed in double quotation marks */
146 if ((res
== out
|| *(fmt
+ 1) != '"') && *cmd
!= '"')
163 * IE uses this a lot for activating things such as windows media
164 * player. This is not verified to be fully correct but it appears
170 strcpyW(res
, lpFile
);
171 res
+= strlenW(lpFile
);
179 HGLOBAL hmem
= SHAllocShared(pidl
, ILGetSize(pidl
), 0);
180 pv
= SHLockShared(hmem
, 0);
181 res
+= sprintfW(res
, wszILPtr
, pv
);
189 * Check if this is an env-variable here...
192 /* Make sure that we have at least one more %.*/
193 if (strchrW(fmt
, '%'))
195 WCHAR tmpBuffer
[1024];
196 PWSTR tmpB
= tmpBuffer
;
197 WCHAR tmpEnvBuff
[MAX_PATH
];
204 TRACE("Checking %s to be an env-var\n", debugstr_w(tmpBuffer
));
206 envRet
= GetEnvironmentVariableW(tmpBuffer
, tmpEnvBuff
, MAX_PATH
);
207 if (envRet
== 0 || envRet
> MAX_PATH
)
208 strcpyW( res
, tmpBuffer
);
210 strcpyW( res
, tmpEnvBuff
);
216 /* Don't skip past terminator (catch a single '%' at the end) */
231 HRESULT
SHELL_GetPathFromIDListForExecuteA(LPCITEMIDLIST pidl
, LPSTR pszPath
, UINT uOutSize
)
234 IShellFolder
* desktop
;
236 HRESULT hr
= SHGetDesktopFolder(&desktop
);
239 hr
= IShellFolder_GetDisplayNameOf(desktop
, pidl
, SHGDN_FORPARSING
, &strret
);
242 StrRetToStrNA(pszPath
, uOutSize
, &strret
, pidl
);
244 IShellFolder_Release(desktop
);
250 HRESULT
SHELL_GetPathFromIDListForExecuteW(LPCITEMIDLIST pidl
, LPWSTR pszPath
, UINT uOutSize
)
253 IShellFolder
* desktop
;
255 HRESULT hr
= SHGetDesktopFolder(&desktop
);
258 hr
= IShellFolder_GetDisplayNameOf(desktop
, pidl
, SHGDN_FORPARSING
, &strret
);
261 StrRetToStrNW(pszPath
, uOutSize
, &strret
, pidl
);
263 IShellFolder_Release(desktop
);
269 /*************************************************************************
270 * SHELL_ExecuteW [Internal]
273 static UINT_PTR
SHELL_ExecuteW(const WCHAR
*lpCmd
, WCHAR
*env
, BOOL shWait
,
274 LPSHELLEXECUTEINFOW psei
, LPSHELLEXECUTEINFOW psei_out
)
276 STARTUPINFOW startup
;
277 PROCESS_INFORMATION info
;
278 UINT_PTR retval
= 31;
280 WCHAR curdir
[MAX_PATH
];
282 TRACE("Execute %s from directory %s\n", debugstr_w(lpCmd
), debugstr_w(psei
->lpDirectory
));
283 /* ShellExecute specifies the command from psei->lpDirectory
284 * if present. Not from the current dir as CreateProcess does */
285 if( psei
->lpDirectory
&& psei
->lpDirectory
[0] )
286 if( ( gcdret
= GetCurrentDirectoryW( MAX_PATH
, curdir
)))
287 if( !SetCurrentDirectoryW( psei
->lpDirectory
))
288 ERR("cannot set directory %s\n", debugstr_w(psei
->lpDirectory
));
289 ZeroMemory(&startup
,sizeof(STARTUPINFOW
));
290 startup
.cb
= sizeof(STARTUPINFOW
);
291 startup
.dwFlags
= STARTF_USESHOWWINDOW
;
292 startup
.wShowWindow
= psei
->nShow
;
293 if (CreateProcessW(NULL
, (LPWSTR
)lpCmd
, NULL
, NULL
, FALSE
, CREATE_UNICODE_ENVIRONMENT
,
294 env
, *psei
->lpDirectory
? psei
->lpDirectory
: NULL
, &startup
, &info
))
296 /* Give 30 seconds to the app to come up, if desired. Probably only needed
297 when starting app immediately before making a DDE connection. */
299 if (WaitForInputIdle( info
.hProcess
, 30000 ) == WAIT_FAILED
)
300 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
302 if (psei
->fMask
& SEE_MASK_NOCLOSEPROCESS
)
303 psei_out
->hProcess
= info
.hProcess
;
305 CloseHandle( info
.hProcess
);
306 CloseHandle( info
.hThread
);
308 else if ((retval
= GetLastError()) >= 32)
310 TRACE("CreateProcess returned error %d\n", retval
);
311 retval
= ERROR_BAD_FORMAT
;
314 TRACE("returning %u\n", retval
);
316 psei_out
->hInstApp
= (HINSTANCE
)retval
;
318 if( !SetCurrentDirectoryW( curdir
))
319 ERR("cannot return to directory %s\n", debugstr_w(curdir
));
325 /***********************************************************************
326 * SHELL_BuildEnvW [Internal]
328 * Build the environment for the new process, adding the specified
329 * path to the PATH variable. Returned pointer must be freed by caller.
331 static void *SHELL_BuildEnvW( const WCHAR
*path
)
333 static const WCHAR wPath
[] = {'P','A','T','H','=',0};
334 WCHAR
*strings
, *new_env
;
336 int total
= strlenW(path
) + 1;
337 BOOL got_path
= FALSE
;
339 if (!(strings
= GetEnvironmentStringsW())) return NULL
;
343 int len
= strlenW(p
) + 1;
344 if (!strncmpiW( p
, wPath
, 5 )) got_path
= TRUE
;
348 if (!got_path
) total
+= 5; /* we need to create PATH */
349 total
++; /* terminating null */
351 if (!(new_env
= HeapAlloc( GetProcessHeap(), 0, total
* sizeof(WCHAR
) )))
353 FreeEnvironmentStringsW( strings
);
360 int len
= strlenW(p
) + 1;
361 memcpy( p2
, p
, len
* sizeof(WCHAR
) );
362 if (!strncmpiW( p
, wPath
, 5 ))
365 strcpyW( p2
+ len
, path
);
366 p2
+= strlenW(path
) + 1;
373 strcpyW( p2
, wPath
);
375 p2
+= strlenW(p2
) + 1;
378 FreeEnvironmentStringsW( strings
);
383 /***********************************************************************
384 * SHELL_TryAppPathW [Internal]
386 * Helper function for SHELL_FindExecutable
387 * @param lpResult - pointer to a buffer of size MAX_PATH
388 * On entry: szName is a filename (probably without path separators).
389 * On exit: if szName found in "App Path", place full path in lpResult, and return true
391 static BOOL
SHELL_TryAppPathW( LPCWSTR szName
, LPWSTR lpResult
, WCHAR
**env
)
393 static const WCHAR wszKeyAppPaths
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',
394 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','A','p','p',' ','P','a','t','h','s','\\',0};
395 static const WCHAR wPath
[] = {'P','a','t','h',0};
402 if (env
) *env
= NULL
;
403 strcpyW(buffer
, wszKeyAppPaths
);
404 strcatW(buffer
, szName
);
405 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, buffer
, 0, KEY_READ
, &hkApp
);
408 len
= MAX_PATH
*sizeof(WCHAR
);
409 res
= RegQueryValueW(hkApp
, NULL
, lpResult
, &len
);
415 DWORD count
= sizeof(buffer
);
416 if (!RegQueryValueExW(hkApp
, wPath
, NULL
, NULL
, (LPBYTE
)buffer
, &count
) && buffer
[0])
417 *env
= SHELL_BuildEnvW( buffer
);
421 if (hkApp
) RegCloseKey(hkApp
);
425 static UINT
SHELL_FindExecutableByOperation(LPCWSTR lpPath
, LPCWSTR lpFile
, LPCWSTR lpOperation
, LPWSTR key
, LPWSTR filetype
, LPWSTR command
, LONG commandlen
)
427 static const WCHAR wCommand
[] = {'\\','c','o','m','m','a','n','d',0};
429 /* Looking for ...buffer\shell\<verb>\command */
430 strcatW(filetype
, wszShell
);
431 strcatW(filetype
, lpOperation
);
432 strcatW(filetype
, wCommand
);
434 if (RegQueryValueW(HKEY_CLASSES_ROOT
, filetype
, command
,
435 &commandlen
) == ERROR_SUCCESS
)
437 commandlen
/= sizeof(WCHAR
);
438 if (key
) strcpyW(key
, filetype
);
442 LONG paramlen
= sizeof(param
);
443 static const WCHAR wSpace
[] = {' ',0};
445 /* FIXME: it seems all Windows version don't behave the same here.
446 * the doc states that this ddeexec information can be found after
448 * on Win98, it doesn't appear, but I think it does on Win2k
450 /* Get the parameters needed by the application
451 from the associated ddeexec key */
452 tmp
= strstrW(filetype
, wCommand
);
454 strcatW(filetype
, wDdeexec
);
455 if (RegQueryValueW(HKEY_CLASSES_ROOT
, filetype
, param
,
456 ¶mlen
) == ERROR_SUCCESS
)
458 paramlen
/= sizeof(WCHAR
);
459 strcatW(command
, wSpace
);
460 strcatW(command
, param
);
461 commandlen
+= paramlen
;
465 command
[commandlen
] = '\0';
467 return 33; /* FIXME see SHELL_FindExecutable() */
470 return 31; /* default - 'No association was found' */
473 /*************************************************************************
474 * SHELL_FindExecutable [Internal]
476 * Utility for code sharing between FindExecutable and ShellExecute
478 * lpFile the name of a file
479 * lpOperation the operation on it (open)
481 * lpResult a buffer, big enough :-(, to store the command to do the
482 * operation on the file
483 * key a buffer, big enough, to get the key name to do actually the
484 * command (it'll be used afterwards for more information
487 UINT
SHELL_FindExecutable(LPCWSTR lpPath
, LPCWSTR lpFile
, LPCWSTR lpOperation
,
488 LPWSTR lpResult
, int resultLen
, LPWSTR key
, WCHAR
**env
, LPITEMIDLIST pidl
, LPCWSTR args
)
490 static const WCHAR wWindows
[] = {'w','i','n','d','o','w','s',0};
491 static const WCHAR wPrograms
[] = {'p','r','o','g','r','a','m','s',0};
492 static const WCHAR wExtensions
[] = {'e','x','e',' ','p','i','f',' ','b','a','t',' ','c','m','d',' ','c','o','m',0};
493 WCHAR
*extension
= NULL
; /* pointer to file extension */
494 WCHAR filetype
[256]; /* registry name for this filetype */
495 LONG filetypelen
= sizeof(filetype
); /* length of above */
496 WCHAR command
[1024]; /* command from registry */
497 WCHAR wBuffer
[256]; /* Used to GetProfileString */
498 UINT retval
= 31; /* default - 'No association was found' */
499 WCHAR
*tok
; /* token pointer */
500 WCHAR xlpFile
[256]; /* result of SearchPath */
501 DWORD attribs
; /* file attributes */
503 TRACE("%s\n", (lpFile
!= NULL
) ? debugstr_w(lpFile
) : "-");
506 lpResult
[0] = '\0'; /* Start off with an empty return string */
507 if (key
) *key
= '\0';
509 /* trap NULL parameters on entry */
510 if ((lpFile
== NULL
) || (lpResult
== NULL
) || (lpOperation
== NULL
))
512 WARN("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
513 debugstr_w(lpFile
), debugstr_w(lpOperation
), debugstr_w(lpResult
));
514 return 2; /* File not found. Close enough, I guess. */
517 if (SHELL_TryAppPathW( lpFile
, lpResult
, env
))
519 TRACE("found %s via App Paths\n", debugstr_w(lpResult
));
523 if (SearchPathW(lpPath
, lpFile
, wszExe
, sizeof(xlpFile
)/sizeof(WCHAR
), xlpFile
, NULL
))
525 TRACE("SearchPathW returned non-zero\n");
527 /* Hey, isn't this value ignored? Why make this call? Shouldn't we return here? --dank*/
530 attribs
= GetFileAttributesW(lpFile
);
531 if (attribs
!=INVALID_FILE_ATTRIBUTES
&& (attribs
&FILE_ATTRIBUTE_DIRECTORY
))
533 strcpyW(filetype
, wszFolder
);
534 filetypelen
= 6; /* strlen("Folder") */
538 /* First thing we need is the file's extension */
539 extension
= strrchrW(xlpFile
, '.'); /* Assume last "." is the one; */
540 /* File->Run in progman uses */
542 TRACE("xlpFile=%s,extension=%s\n", debugstr_w(xlpFile
), debugstr_w(extension
));
544 if (extension
== NULL
|| extension
[1]==0)
546 WARN("Returning 31 - No association\n");
547 return 31; /* no association */
550 /* Three places to check: */
551 /* 1. win.ini, [windows], programs (NB no leading '.') */
552 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
553 /* 3. win.ini, [extensions], extension (NB no leading '.' */
554 /* All I know of the order is that registry is checked before */
555 /* extensions; however, it'd make sense to check the programs */
556 /* section first, so that's what happens here. */
558 /* See if it's a program - if GetProfileString fails, we skip this
559 * section. Actually, if GetProfileString fails, we've probably
560 * got a lot more to worry about than running a program... */
561 if (GetProfileStringW(wWindows
, wPrograms
, wExtensions
, wBuffer
, sizeof(wBuffer
)/sizeof(WCHAR
)) > 0)
568 while (*p
&& *p
!= ' ' && *p
!= '\t') p
++;
572 while (*p
== ' ' || *p
== '\t') p
++;
575 if (strcmpiW(tok
, &extension
[1]) == 0) /* have to skip the leading "." */
577 strcpyW(lpResult
, xlpFile
);
578 /* Need to perhaps check that the file has a path
580 TRACE("found %s\n", debugstr_w(lpResult
));
583 /* Greater than 32 to indicate success FIXME According to the
584 * docs, I should be returning a handle for the
585 * executable. Does this mean I'm supposed to open the
586 * executable file or something? More RTFM, I guess... */
593 if (RegQueryValueW(HKEY_CLASSES_ROOT
, extension
, filetype
,
594 &filetypelen
) == ERROR_SUCCESS
)
596 filetypelen
/= sizeof(WCHAR
);
597 filetype
[filetypelen
] = '\0';
598 TRACE("File type: %s\n", debugstr_w(filetype
));
606 /* pass the operation string to SHELL_FindExecutableByOperation() */
607 filetype
[filetypelen
] = '\0';
608 retval
= SHELL_FindExecutableByOperation(lpPath
, lpFile
, lpOperation
, key
, filetype
, command
, sizeof(command
));
612 WCHAR operation
[MAX_PATH
];
615 /* Looking for ...buffer\shell\<operation>\command */
616 strcatW(filetype
, wszShell
);
618 /* enumerate the operation subkeys in the registry and search for one with an associated command */
619 if (RegOpenKeyW(HKEY_CLASSES_ROOT
, filetype
, &hkey
) == ERROR_SUCCESS
)
624 if (RegEnumKeyW(hkey
, idx
, operation
, MAX_PATH
) != ERROR_SUCCESS
)
627 filetype
[filetypelen
] = '\0';
628 retval
= SHELL_FindExecutableByOperation(lpPath
, lpFile
, operation
, key
, filetype
, command
, sizeof(command
));
639 SHELL_ArgifyW(lpResult
, resultLen
, command
, xlpFile
, pidl
, args
);
641 /* Remove double quotation marks and command line arguments */
642 if (*lpResult
== '"')
645 while (*(p
+ 1) != '"')
654 else /* Check win.ini */
656 static const WCHAR wExtensions
[] = {'e','x','t','e','n','s','i','o','n','s',0};
658 /* Toss the leading dot */
660 if (GetProfileStringW(wExtensions
, extension
, wszEmpty
, command
, sizeof(command
)/sizeof(WCHAR
)) > 0)
662 if (strlenW(command
) != 0)
664 strcpyW(lpResult
, command
);
665 tok
= strchrW(lpResult
, '^'); /* should be ^.extension? */
669 strcatW(lpResult
, xlpFile
); /* what if no dir in xlpFile? */
670 tok
= strchrW(command
, '^'); /* see above */
671 if ((tok
!= NULL
) && (strlenW(tok
)>5))
673 strcatW(lpResult
, &tok
[5]);
676 retval
= 33; /* FIXME - see above */
681 TRACE("returning %s\n", debugstr_w(lpResult
));
685 /******************************************************************
688 * callback for the DDE connection. not really useful
690 static HDDEDATA CALLBACK
dde_cb(UINT uType
, UINT uFmt
, HCONV hConv
,
691 HSZ hsz1
, HSZ hsz2
, HDDEDATA hData
,
692 ULONG_PTR dwData1
, ULONG_PTR dwData2
)
694 TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n",
695 uType
, uFmt
, hConv
, hsz1
, hsz2
, hData
, dwData1
, dwData2
);
699 /******************************************************************
702 * ShellExecute helper. Used to do an operation with a DDE connection
704 * Handles both the direct connection (try #1), and if it fails,
705 * launching an application and trying (#2) to connect to it
708 static unsigned dde_connect(WCHAR
* key
, const WCHAR
* start
, WCHAR
* ddeexec
,
709 const WCHAR
* lpFile
, WCHAR
*env
,
710 LPCWSTR szCommandline
, LPITEMIDLIST pidl
, SHELL_ExecuteW32 execfunc
,
711 LPSHELLEXECUTEINFOW psei
, LPSHELLEXECUTEINFOW psei_out
)
713 static const WCHAR wApplication
[] = {'\\','a','p','p','l','i','c','a','t','i','o','n',0};
714 static const WCHAR wTopic
[] = {'\\','t','o','p','i','c',0};
715 WCHAR
* endkey
= key
+ strlenW(key
);
716 WCHAR app
[256], topic
[256], ifexec
[256], res
[256];
717 LONG applen
, topiclen
, ifexeclen
;
721 HSZ hszApp
, hszTopic
;
725 BOOL unicode
= !(GetVersion() & 0x80000000);
727 strcpyW(endkey
, wApplication
);
728 applen
= sizeof(app
);
729 if (RegQueryValueW(HKEY_CLASSES_ROOT
, key
, app
, &applen
) != ERROR_SUCCESS
)
731 FIXME("default app name NIY %s\n", debugstr_w(key
));
735 strcpyW(endkey
, wTopic
);
736 topiclen
= sizeof(topic
);
737 if (RegQueryValueW(HKEY_CLASSES_ROOT
, key
, topic
, &topiclen
) != ERROR_SUCCESS
)
739 static const WCHAR wSystem
[] = {'S','y','s','t','e','m',0};
740 strcpyW(topic
, wSystem
);
745 if (DdeInitializeW(&ddeInst
, dde_cb
, APPCMD_CLIENTONLY
, 0L) != DMLERR_NO_ERROR
)
750 if (DdeInitializeA(&ddeInst
, dde_cb
, APPCMD_CLIENTONLY
, 0L) != DMLERR_NO_ERROR
)
754 hszApp
= DdeCreateStringHandleW(ddeInst
, app
, CP_WINUNICODE
);
755 hszTopic
= DdeCreateStringHandleW(ddeInst
, topic
, CP_WINUNICODE
);
757 hConv
= DdeConnect(ddeInst
, hszApp
, hszTopic
, NULL
);
761 static const WCHAR wIfexec
[] = {'\\','i','f','e','x','e','c',0};
762 TRACE("Launching '%s'\n", debugstr_w(start
));
763 ret
= execfunc(start
, env
, TRUE
, psei
, psei_out
);
766 TRACE("Couldn't launch\n");
769 hConv
= DdeConnect(ddeInst
, hszApp
, hszTopic
, NULL
);
772 TRACE("Couldn't connect. ret=%d\n", ret
);
773 DdeUninitialize(ddeInst
);
774 SetLastError(ERROR_DDE_FAIL
);
775 return 30; /* whatever */
777 strcpyW(endkey
, wIfexec
);
778 ifexeclen
= sizeof(ifexec
);
779 if (RegQueryValueW(HKEY_CLASSES_ROOT
, key
, ifexec
, &ifexeclen
) == ERROR_SUCCESS
)
785 SHELL_ArgifyW(res
, sizeof(res
)/sizeof(WCHAR
), exec
, lpFile
, pidl
, szCommandline
);
786 TRACE("%s %s => %s\n", debugstr_w(exec
), debugstr_w(lpFile
), debugstr_w(res
));
788 /* It's documented in the KB 330337 that IE has a bug and returns
789 * error DMLERR_NOTPROCESSED on XTYP_EXECUTE request.
792 hDdeData
= DdeClientTransaction((LPBYTE
)res
, (strlenW(res
) + 1) * sizeof(WCHAR
), hConv
, 0L, 0,
793 XTYP_EXECUTE
, 30000, &tid
);
796 DWORD lenA
= WideCharToMultiByte(CP_ACP
, 0, res
, -1, NULL
, 0, NULL
, NULL
);
797 char *resA
= HeapAlloc(GetProcessHeap(), 0, lenA
);
798 WideCharToMultiByte(CP_ACP
, 0, res
, -1, resA
, lenA
, NULL
, NULL
);
799 hDdeData
= DdeClientTransaction( (LPBYTE
)resA
, lenA
, hConv
, 0L, 0,
800 XTYP_EXECUTE
, 10000, &tid
);
801 HeapFree(GetProcessHeap(), 0, resA
);
804 DdeFreeDataHandle(hDdeData
);
806 WARN("DdeClientTransaction failed with error %04x\n", DdeGetLastError(ddeInst
));
809 DdeDisconnect(hConv
);
812 DdeUninitialize(ddeInst
);
817 /*************************************************************************
818 * execute_from_key [Internal]
820 static UINT_PTR
execute_from_key(LPWSTR key
, LPCWSTR lpFile
, WCHAR
*env
, LPCWSTR szCommandline
,
821 LPCWSTR executable_name
,
822 SHELL_ExecuteW32 execfunc
,
823 LPSHELLEXECUTEINFOW psei
, LPSHELLEXECUTEINFOW psei_out
)
826 LONG cmdlen
= sizeof(cmd
);
827 UINT_PTR retval
= 31;
829 TRACE("%s %s %s %s %s\n", debugstr_w(key
), debugstr_w(lpFile
), debugstr_w(env
),
830 debugstr_w(szCommandline
), debugstr_w(executable_name
));
834 /* Get the application from the registry */
835 if (RegQueryValueW(HKEY_CLASSES_ROOT
, key
, cmd
, &cmdlen
) == ERROR_SUCCESS
)
839 TRACE("got cmd: %s\n", debugstr_w(cmd
));
843 /* Is there a replace() function anywhere? */
844 cmdlen
/= sizeof(WCHAR
);
846 SHELL_ArgifyW(param
, sizeof(param
)/sizeof(WCHAR
), cmd
, lpFile
, psei
->lpIDList
, szCommandline
);
847 retval
= execfunc(param
, env
, FALSE
, psei
, psei_out
);
851 static const WCHAR wCommand
[] = {'c','o','m','m','a','n','d',0};
852 static const WCHAR wDdeexec
[] = {'d','d','e','e','x','e','c',0};
855 LONG paramlen
= sizeof(param
);
859 /* Get the parameters needed by the application
860 from the associated ddeexec key */
861 tmp
= strstrW(key
, wCommand
);
863 strcpyW(tmp
, wDdeexec
);
865 TRACE("trying ddeexec cmd: %s\n", debugstr_w(key
));
867 if (RegQueryValueW(HKEY_CLASSES_ROOT
, key
, param
, ¶mlen
) == ERROR_SUCCESS
)
869 TRACE("Got ddeexec %s => %s\n", debugstr_w(key
), debugstr_w(param
));
870 retval
= dde_connect(key
, executable_name
, param
, lpFile
, env
, szCommandline
, psei
->lpIDList
, execfunc
, psei
, psei_out
);
873 WARN("Nothing appropriate found for %s\n", debugstr_w(key
));
879 /*************************************************************************
880 * FindExecutableA [SHELL32.@]
882 HINSTANCE WINAPI
FindExecutableA(LPCSTR lpFile
, LPCSTR lpDirectory
, LPSTR lpResult
)
885 WCHAR
*wFile
= NULL
, *wDirectory
= NULL
;
886 WCHAR wResult
[MAX_PATH
];
888 if (lpFile
) __SHCloneStrAtoW(&wFile
, lpFile
);
889 if (lpDirectory
) __SHCloneStrAtoW(&wDirectory
, lpDirectory
);
891 retval
= FindExecutableW(wFile
, wDirectory
, wResult
);
892 WideCharToMultiByte(CP_ACP
, 0, wResult
, -1, lpResult
, MAX_PATH
, NULL
, NULL
);
893 if (wFile
) SHFree( wFile
);
894 if (wDirectory
) SHFree( wDirectory
);
896 TRACE("returning %s\n", lpResult
);
900 /*************************************************************************
901 * FindExecutableW [SHELL32.@]
903 HINSTANCE WINAPI
FindExecutableW(LPCWSTR lpFile
, LPCWSTR lpDirectory
, LPWSTR lpResult
)
905 UINT_PTR retval
= 31; /* default - 'No association was found' */
908 TRACE("File %s, Dir %s\n",
909 (lpFile
!= NULL
? debugstr_w(lpFile
) : "-"), (lpDirectory
!= NULL
? debugstr_w(lpDirectory
) : "-"));
911 lpResult
[0] = '\0'; /* Start off with an empty return string */
913 /* trap NULL parameters on entry */
914 if ((lpFile
== NULL
) || (lpResult
== NULL
))
916 /* FIXME - should throw a warning, perhaps! */
917 return (HINSTANCE
)2; /* File not found. Close enough, I guess. */
922 GetCurrentDirectoryW(sizeof(old_dir
)/sizeof(WCHAR
), old_dir
);
923 SetCurrentDirectoryW(lpDirectory
);
926 retval
= SHELL_FindExecutable(lpDirectory
, lpFile
, wszOpen
, lpResult
, MAX_PATH
, NULL
, NULL
, NULL
, NULL
);
928 TRACE("returning %s\n", debugstr_w(lpResult
));
930 SetCurrentDirectoryW(old_dir
);
931 return (HINSTANCE
)retval
;
934 /* FIXME: is this already implemented somewhere else? */
935 static HKEY
ShellExecute_GetClassKey( LPSHELLEXECUTEINFOW sei
)
937 LPCWSTR ext
= NULL
, lpClass
= NULL
;
939 DWORD type
= 0, sz
= 0;
943 if (sei
->fMask
& SEE_MASK_CLASSALL
)
944 return sei
->hkeyClass
;
946 if (sei
->fMask
& SEE_MASK_CLASSNAME
)
947 lpClass
= sei
->lpClass
;
950 ext
= PathFindExtensionW( sei
->lpFile
);
951 TRACE("ext = %s\n", debugstr_w( ext
) );
955 r
= RegOpenKeyW( HKEY_CLASSES_ROOT
, ext
, &hkey
);
956 if (r
!= ERROR_SUCCESS
)
959 r
= RegQueryValueExW( hkey
, NULL
, 0, &type
, NULL
, &sz
);
960 if ( r
== ERROR_SUCCESS
&& type
== REG_SZ
)
962 sz
+= sizeof (WCHAR
);
963 cls
= HeapAlloc( GetProcessHeap(), 0, sz
);
965 RegQueryValueExW( hkey
, NULL
, 0, &type
, (LPBYTE
) cls
, &sz
);
972 TRACE("class = %s\n", debugstr_w(lpClass
) );
976 RegOpenKeyW( HKEY_CLASSES_ROOT
, lpClass
, &hkey
);
978 HeapFree( GetProcessHeap(), 0, cls
);
983 static IDataObject
*shellex_get_dataobj( LPSHELLEXECUTEINFOW sei
)
985 LPCITEMIDLIST pidllast
= NULL
;
986 IDataObject
*dataobj
= NULL
;
987 IShellFolder
*shf
= NULL
;
988 LPITEMIDLIST pidl
= NULL
;
991 if (sei
->fMask
& SEE_MASK_CLASSALL
)
992 pidl
= sei
->lpIDList
;
995 WCHAR fullpath
[MAX_PATH
];
998 r
= GetFullPathNameW( sei
->lpFile
, MAX_PATH
, fullpath
, NULL
);
1002 pidl
= ILCreateFromPathW( fullpath
);
1005 r
= SHBindToParent( pidl
, &IID_IShellFolder
, (LPVOID
*)&shf
, &pidllast
);
1009 IShellFolder_GetUIObjectOf( shf
, NULL
, 1, &pidllast
,
1010 &IID_IDataObject
, NULL
, (LPVOID
*) &dataobj
);
1013 if ( pidl
!= sei
->lpIDList
)
1016 IShellFolder_Release( shf
);
1020 static HRESULT
shellex_run_context_menu_default( IShellExtInit
*obj
,
1021 LPSHELLEXECUTEINFOW sei
)
1023 IContextMenu
*cm
= NULL
;
1024 CMINVOKECOMMANDINFOEX ici
;
1031 TRACE("%p %p\n", obj
, sei
);
1033 r
= IShellExtInit_QueryInterface( obj
, &IID_IContextMenu
, (LPVOID
*) &cm
);
1037 hmenu
= CreateMenu();
1041 /* the number of the last menu added is returned in r */
1042 r
= IContextMenu_QueryContextMenu( cm
, hmenu
, 0, 0x20, 0x7fff, CMF_DEFAULTONLY
);
1046 n
= GetMenuItemCount( hmenu
);
1047 for ( i
= 0; i
< n
; i
++ )
1049 memset( &info
, 0, sizeof info
);
1050 info
.cbSize
= sizeof info
;
1051 info
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_DATA
| MIIM_ID
;
1052 info
.dwTypeData
= string
;
1053 info
.cch
= sizeof string
;
1055 GetMenuItemInfoW( hmenu
, i
, TRUE
, &info
);
1057 TRACE("menu %d %s %08x %08lx %08x %08x\n", i
, debugstr_w(string
),
1058 info
.fState
, info
.dwItemData
, info
.fType
, info
.wID
);
1059 if ( ( !sei
->lpVerb
&& (info
.fState
& MFS_DEFAULT
) ) ||
1060 ( sei
->lpVerb
&& !lstrcmpiW( sei
->lpVerb
, string
) ) )
1071 memset( &ici
, 0, sizeof ici
);
1072 ici
.cbSize
= sizeof ici
;
1073 ici
.fMask
= CMIC_MASK_UNICODE
;
1074 ici
.nShow
= sei
->nShow
;
1075 ici
.lpVerb
= MAKEINTRESOURCEA( def
);
1076 ici
.hwnd
= sei
->hwnd
;
1077 ici
.lpParametersW
= sei
->lpParameters
;
1079 r
= IContextMenu_InvokeCommand( cm
, (LPCMINVOKECOMMANDINFO
) &ici
);
1081 TRACE("invoke command returned %08lx\n", r
);
1085 DestroyMenu( hmenu
);
1087 IContextMenu_Release( cm
);
1091 static HRESULT
shellex_load_object_and_run( HKEY hkey
, LPCGUID guid
, LPSHELLEXECUTEINFOW sei
)
1093 IDataObject
*dataobj
= NULL
;
1094 IObjectWithSite
*ows
= NULL
;
1095 IShellExtInit
*obj
= NULL
;
1098 TRACE("%p %s %p\n", hkey
, debugstr_guid( guid
), sei
);
1100 r
= CoInitialize( NULL
);
1104 r
= CoCreateInstance( guid
, NULL
, CLSCTX_INPROC_SERVER
,
1105 &IID_IShellExtInit
, (LPVOID
*)&obj
);
1108 ERR("failed %08lx\n", r
);
1112 dataobj
= shellex_get_dataobj( sei
);
1115 ERR("failed to get data object\n");
1119 r
= IShellExtInit_Initialize( obj
, NULL
, dataobj
, hkey
);
1123 r
= IShellExtInit_QueryInterface( obj
, &IID_IObjectWithSite
, (LPVOID
*) &ows
);
1127 IObjectWithSite_SetSite( ows
, NULL
);
1129 r
= shellex_run_context_menu_default( obj
, sei
);
1133 IObjectWithSite_Release( ows
);
1135 IDataObject_Release( dataobj
);
1137 IShellExtInit_Release( obj
);
1143 /*************************************************************************
1144 * ShellExecute_FromContextMenu [Internal]
1146 static LONG
ShellExecute_FromContextMenu( LPSHELLEXECUTEINFOW sei
)
1148 static const WCHAR szcm
[] = { 's','h','e','l','l','e','x','\\',
1149 'C','o','n','t','e','x','t','M','e','n','u','H','a','n','d','l','e','r','s',0 };
1150 HKEY hkey
, hkeycm
= 0;
1157 TRACE("%s\n", debugstr_w(sei
->lpFile
) );
1159 hkey
= ShellExecute_GetClassKey( sei
);
1161 return ERROR_FUNCTION_FAILED
;
1163 r
= RegOpenKeyW( hkey
, szcm
, &hkeycm
);
1164 if ( r
== ERROR_SUCCESS
)
1169 r
= RegEnumKeyW( hkeycm
, i
++, szguid
, 39 );
1170 if ( r
!= ERROR_SUCCESS
)
1173 hr
= CLSIDFromString( szguid
, &guid
);
1176 /* stop at the first one that succeeds in running */
1177 hr
= shellex_load_object_and_run( hkey
, &guid
, sei
);
1178 if ( SUCCEEDED( hr
) )
1182 RegCloseKey( hkeycm
);
1185 if ( hkey
!= sei
->hkeyClass
)
1186 RegCloseKey( hkey
);
1190 /*************************************************************************
1191 * SHELL_execute [Internal]
1193 BOOL
SHELL_execute( LPSHELLEXECUTEINFOW sei
, SHELL_ExecuteW32 execfunc
)
1195 static const WCHAR wQuote
[] = {'"',0};
1196 static const WCHAR wSpace
[] = {' ',0};
1197 static const WCHAR wWww
[] = {'w','w','w',0};
1198 static const WCHAR wFile
[] = {'f','i','l','e',0};
1199 static const WCHAR wHttp
[] = {'h','t','t','p',':','/','/',0};
1200 static const WCHAR wExplorer
[] = {'e','x','p','l','o','r','e','r','.','e','x','e',0};
1201 static const DWORD unsupportedFlags
=
1202 SEE_MASK_INVOKEIDLIST
| SEE_MASK_ICON
| SEE_MASK_HOTKEY
|
1203 SEE_MASK_CONNECTNETDRV
| SEE_MASK_FLAG_DDEWAIT
| SEE_MASK_FLAG_NO_UI
|
1204 SEE_MASK_UNICODE
| SEE_MASK_NO_CONSOLE
| SEE_MASK_ASYNCOK
|
1207 WCHAR wszApplicationName
[MAX_PATH
+2], wszParameters
[1024], wszDir
[MAX_PATH
];
1208 SHELLEXECUTEINFOW sei_tmp
; /* modifiable copy of SHELLEXECUTEINFO struct */
1209 WCHAR wfileName
[MAX_PATH
];
1211 WCHAR lpstrProtocol
[256];
1213 UINT_PTR retval
= 31;
1215 WCHAR buffer
[MAX_PATH
];
1218 /* make a local copy of the LPSHELLEXECUTEINFO structure and work with this from now on */
1219 memcpy(&sei_tmp
, sei
, sizeof(sei_tmp
));
1221 TRACE("mask=0x%08lx hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
1222 sei_tmp
.fMask
, sei_tmp
.hwnd
, debugstr_w(sei_tmp
.lpVerb
),
1223 debugstr_w(sei_tmp
.lpFile
), debugstr_w(sei_tmp
.lpParameters
),
1224 debugstr_w(sei_tmp
.lpDirectory
), sei_tmp
.nShow
,
1225 ((sei_tmp
.fMask
& SEE_MASK_CLASSALL
) == SEE_MASK_CLASSNAME
) ?
1226 debugstr_w(sei_tmp
.lpClass
) : "not used");
1228 sei
->hProcess
= NULL
;
1230 /* make copies of all path/command strings */
1231 if (!sei_tmp
.lpFile
)
1232 *wszApplicationName
= '\0';
1233 else if (*sei_tmp
.lpFile
== '\"')
1236 strcpyW(wszApplicationName
, sei_tmp
.lpFile
+1);
1237 l
=lstrlenW(wszApplicationName
);
1238 if (wszApplicationName
[l
-1] == '\"')
1239 wszApplicationName
[l
-1] = '\0';
1240 TRACE("wszApplicationName=%s\n",debugstr_w(wszApplicationName
));
1243 strcpyW(wszApplicationName
, sei_tmp
.lpFile
);
1245 if (sei_tmp
.lpParameters
)
1246 strcpyW(wszParameters
, sei_tmp
.lpParameters
);
1248 *wszParameters
= '\0';
1250 if (sei_tmp
.lpDirectory
)
1251 strcpyW(wszDir
, sei_tmp
.lpDirectory
);
1255 /* adjust string pointers to point to the new buffers */
1256 sei_tmp
.lpFile
= wszApplicationName
;
1257 sei_tmp
.lpParameters
= wszParameters
;
1258 sei_tmp
.lpDirectory
= wszDir
;
1260 if (sei_tmp
.fMask
& unsupportedFlags
)
1262 FIXME("flags ignored: 0x%08lx\n", sei_tmp
.fMask
& unsupportedFlags
);
1265 /* process the IDList */
1266 if (sei_tmp
.fMask
& SEE_MASK_IDLIST
)
1268 IShellExecuteHookW
* pSEH
;
1270 HRESULT hr
= SHBindToParent(sei_tmp
.lpIDList
, &IID_IShellExecuteHookW
, (LPVOID
*)&pSEH
, NULL
);
1274 hr
= IShellExecuteHookW_Execute(pSEH
, &sei_tmp
);
1276 IShellExecuteHookW_Release(pSEH
);
1282 SHGetPathFromIDListW(sei_tmp
.lpIDList
, wszApplicationName
);
1283 TRACE("-- idlist=%p (%s)\n", sei_tmp
.lpIDList
, debugstr_w(wszApplicationName
));
1286 if ( ERROR_SUCCESS
== ShellExecute_FromContextMenu( &sei_tmp
) )
1288 sei
->hInstApp
= (HINSTANCE
) 33;
1292 if (sei_tmp
.fMask
& SEE_MASK_CLASSALL
)
1294 /* launch a document by fileclass like 'WordPad.Document.1' */
1295 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
1296 /* FIXME: szCommandline should not be of a fixed size. Fixed to 1024, MAX_PATH is way too short! */
1297 ULONG cmask
=(sei_tmp
.fMask
& SEE_MASK_CLASSALL
);
1298 HCR_GetExecuteCommandW((cmask
== SEE_MASK_CLASSKEY
) ? sei_tmp
.hkeyClass
: NULL
,
1299 (cmask
== SEE_MASK_CLASSNAME
) ? sei_tmp
.lpClass
: NULL
,
1300 (sei_tmp
.lpVerb
) ? sei_tmp
.lpVerb
: wszOpen
,
1301 wszParameters
, sizeof(wszParameters
)/sizeof(WCHAR
));
1303 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
1304 TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", debugstr_w(wszParameters
), debugstr_w(wszApplicationName
));
1307 done
= SHELL_ArgifyW(wcmd
, sizeof(wcmd
)/sizeof(WCHAR
), wszParameters
, wszApplicationName
, sei_tmp
.lpIDList
, NULL
);
1308 if (!done
&& wszApplicationName
[0])
1310 strcatW(wcmd
, wSpace
);
1311 strcatW(wcmd
, wszApplicationName
);
1313 retval
= execfunc(wcmd
, NULL
, FALSE
, &sei_tmp
, sei
);
1320 /* Has the IDList not yet been translated? */
1321 if (sei_tmp
.fMask
& SEE_MASK_IDLIST
)
1323 /* last chance to translate IDList: now also allow CLSID paths */
1324 if (SUCCEEDED(SHELL_GetPathFromIDListForExecuteW(sei_tmp
.lpIDList
, buffer
, sizeof(buffer
)))) {
1325 if (buffer
[0]==':' && buffer
[1]==':') {
1326 /* open shell folder for the specified class GUID */
1327 strcpyW(wszParameters
, buffer
);
1328 strcpyW(wszApplicationName
, wExplorer
);
1330 sei_tmp
.fMask
&= ~SEE_MASK_INVOKEIDLIST
;
1332 WCHAR target
[MAX_PATH
];
1334 /* Check if we're executing a directory and if so use the
1335 handler for the Folder class */
1336 strcpyW(target
, buffer
);
1337 attribs
= GetFileAttributesW(buffer
);
1338 if (attribs
!= INVALID_FILE_ATTRIBUTES
&&
1339 (attribs
& FILE_ATTRIBUTE_DIRECTORY
) &&
1340 HCR_GetExecuteCommandW(0, wszFolder
,
1341 sei_tmp
.lpVerb
?sei_tmp
.lpVerb
:wszOpen
,
1342 buffer
, sizeof(buffer
))) {
1343 SHELL_ArgifyW(wszApplicationName
,
1344 sizeof(wszApplicationName
)/sizeof(WCHAR
),
1345 buffer
, target
, sei_tmp
.lpIDList
, NULL
);
1347 sei_tmp
.fMask
&= ~SEE_MASK_INVOKEIDLIST
;
1352 /* expand environment strings */
1353 if (ExpandEnvironmentStringsW(sei_tmp
.lpFile
, buffer
, MAX_PATH
))
1354 lstrcpyW(wszApplicationName
, buffer
);
1356 if (*sei_tmp
.lpParameters
)
1357 if (ExpandEnvironmentStringsW(sei_tmp
.lpParameters
, buffer
, MAX_PATH
))
1358 lstrcpyW(wszParameters
, buffer
);
1360 if (*sei_tmp
.lpDirectory
)
1361 if (ExpandEnvironmentStringsW(sei_tmp
.lpDirectory
, buffer
, MAX_PATH
))
1362 lstrcpyW(wszDir
, buffer
);
1364 /* Else, try to execute the filename */
1365 TRACE("execute:%s,%s,%s\n", debugstr_w(wszApplicationName
), debugstr_w(wszParameters
), debugstr_w(wszDir
));
1367 /* separate out command line arguments from executable file name */
1368 if (!*sei_tmp
.lpParameters
) {
1369 /* If the executable path is quoted, handle the rest of the command line as parameters. */
1370 if (sei_tmp
.lpFile
[0] == '"') {
1371 LPWSTR src
= wszApplicationName
/*sei_tmp.lpFile*/ + 1;
1372 LPWSTR dst
= wfileName
;
1375 /* copy the unquoted executable path to 'wfileName' */
1376 while(*src
&& *src
!='"')
1384 while(isspace(*src
))
1389 /* copy the parameter string to 'wszParameters' */
1390 strcpyW(wszParameters
, src
);
1392 /* terminate previous command string after the quote character */
1397 /* If the executable name is not quoted, we have to use this search loop here,
1398 that in CreateProcess() is not sufficient because it does not handle shell links. */
1399 WCHAR buffer
[MAX_PATH
], xlpFile
[MAX_PATH
];
1402 LPWSTR beg
= wszApplicationName
/*sei_tmp.lpFile*/;
1403 for(s
=beg
; (space
=strchrW(s
, ' ')); s
=space
+1) {
1404 int idx
= space
-sei_tmp
.lpFile
;
1405 memcpy(buffer
, sei_tmp
.lpFile
, idx
* sizeof(WCHAR
));
1408 /*FIXME This finds directory paths if the targeted file name contains spaces. */
1409 if (SearchPathW(*sei_tmp
.lpDirectory
? sei_tmp
.lpDirectory
: NULL
, buffer
, wszExe
, sizeof(xlpFile
), xlpFile
, NULL
))
1411 /* separate out command from parameter string */
1412 LPCWSTR p
= space
+ 1;
1417 strcpyW(wszParameters
, p
);
1424 strcpyW(wfileName
, sei_tmp
.lpFile
);
1427 strcpyW(wfileName
, sei_tmp
.lpFile
);
1431 strcpyW(wcmd
, wszApplicationName
);
1432 if (sei_tmp
.lpParameters
[0]) {
1433 strcatW(wcmd
, wSpace
);
1434 strcatW(wcmd
, wszParameters
);
1437 /* We set the default to open, and that should generally work.
1438 But that is not really the way the MS docs say to do it. */
1439 if (!sei_tmp
.lpVerb
)
1440 sei_tmp
.lpVerb
= wszOpen
;
1442 retval
= execfunc(wcmd
, NULL
, FALSE
, &sei_tmp
, sei
);
1446 /* Else, try to find the executable */
1448 retval
= SHELL_FindExecutable(sei_tmp
.lpDirectory
, lpFile
, sei_tmp
.lpVerb
, wcmd
, 1024, lpstrProtocol
, &env
, sei_tmp
.lpIDList
, sei_tmp
.lpParameters
);
1449 if (retval
> 32) /* Found */
1451 WCHAR wszQuotedCmd
[MAX_PATH
+2];
1452 /* Must quote to handle case where cmd contains spaces,
1453 * else security hole if malicious user creates executable file "C:\\Program"
1455 strcpyW(wszQuotedCmd
, wQuote
);
1456 strcatW(wszQuotedCmd
, wcmd
);
1457 strcatW(wszQuotedCmd
, wQuote
);
1458 if (wszParameters
[0]) {
1459 strcatW(wszQuotedCmd
, wSpace
);
1460 strcatW(wszQuotedCmd
, wszParameters
);
1462 TRACE("%s/%s => %s/%s\n", debugstr_w(wszApplicationName
), debugstr_w(sei_tmp
.lpVerb
), debugstr_w(wszQuotedCmd
), debugstr_w(lpstrProtocol
));
1464 retval
= execute_from_key(lpstrProtocol
, wszApplicationName
, env
, sei_tmp
.lpParameters
, wcmd
, execfunc
, &sei_tmp
, sei
);
1466 retval
= execfunc(wszQuotedCmd
, env
, FALSE
, &sei_tmp
, sei
);
1467 HeapFree( GetProcessHeap(), 0, env
);
1469 else if (PathIsURLW((LPWSTR
)lpFile
)) /* File not found, check for URL */
1471 static const WCHAR wShell
[] = {'\\','s','h','e','l','l','\\',0};
1472 static const WCHAR wCommand
[] = {'\\','c','o','m','m','a','n','d',0};
1476 lpstrRes
= strchrW(lpFile
, ':');
1478 iSize
= lpstrRes
- lpFile
;
1480 iSize
= strlenW(lpFile
);
1482 TRACE("Got URL: %s\n", debugstr_w(lpFile
));
1483 /* Looking for ...protocol\shell\lpOperation\command */
1484 memcpy(lpstrProtocol
, lpFile
, iSize
*sizeof(WCHAR
));
1485 lpstrProtocol
[iSize
] = '\0';
1486 strcatW(lpstrProtocol
, wShell
);
1487 strcatW(lpstrProtocol
, sei_tmp
.lpVerb
? sei_tmp
.lpVerb
: wszOpen
);
1488 strcatW(lpstrProtocol
, wCommand
);
1490 /* Remove File Protocol from lpFile */
1491 /* In the case file://path/file */
1492 if (!strncmpiW(lpFile
, wFile
, iSize
))
1495 while (*lpFile
== ':') lpFile
++;
1497 retval
= execute_from_key(lpstrProtocol
, lpFile
, NULL
, sei_tmp
.lpParameters
, wcmd
, execfunc
, &sei_tmp
, sei
);
1499 /* Check if file specified is in the form www.??????.*** */
1500 else if (!strncmpiW(lpFile
, wWww
, 3))
1502 /* if so, append lpFile http:// and call ShellExecute */
1503 WCHAR lpstrTmpFile
[256];
1504 strcpyW(lpstrTmpFile
, wHttp
);
1505 strcatW(lpstrTmpFile
, lpFile
);
1506 retval
= (UINT_PTR
)ShellExecuteW(sei_tmp
.hwnd
, sei_tmp
.lpVerb
, lpstrTmpFile
, NULL
, NULL
, 0);
1509 TRACE("retval %u\n", retval
);
1513 sei
->hInstApp
= (HINSTANCE
)retval
;
1517 sei
->hInstApp
= (HINSTANCE
)33;
1521 /*************************************************************************
1522 * ShellExecuteA [SHELL32.290]
1524 HINSTANCE WINAPI
ShellExecuteA(HWND hWnd
, LPCSTR lpOperation
,LPCSTR lpFile
,
1525 LPCSTR lpParameters
,LPCSTR lpDirectory
, INT iShowCmd
)
1527 SHELLEXECUTEINFOA sei
;
1529 TRACE("%p,%s,%s,%s,%s,%d\n",
1530 hWnd
, debugstr_a(lpOperation
), debugstr_a(lpFile
),
1531 debugstr_a(lpParameters
), debugstr_a(lpDirectory
), iShowCmd
);
1533 sei
.cbSize
= sizeof(sei
);
1536 sei
.lpVerb
= lpOperation
;
1537 sei
.lpFile
= lpFile
;
1538 sei
.lpParameters
= lpParameters
;
1539 sei
.lpDirectory
= lpDirectory
;
1540 sei
.nShow
= iShowCmd
;
1547 ShellExecuteExA (&sei
);
1548 return sei
.hInstApp
;
1551 /*************************************************************************
1552 * ShellExecuteExA [SHELL32.292]
1555 BOOL WINAPI
ShellExecuteExA (LPSHELLEXECUTEINFOA sei
)
1557 SHELLEXECUTEINFOW seiW
;
1559 WCHAR
*wVerb
= NULL
, *wFile
= NULL
, *wParameters
= NULL
, *wDirectory
= NULL
, *wClass
= NULL
;
1563 memcpy(&seiW
, sei
, sizeof(SHELLEXECUTEINFOW
));
1566 seiW
.lpVerb
= __SHCloneStrAtoW(&wVerb
, sei
->lpVerb
);
1569 seiW
.lpFile
= __SHCloneStrAtoW(&wFile
, sei
->lpFile
);
1571 if (sei
->lpParameters
)
1572 seiW
.lpParameters
= __SHCloneStrAtoW(&wParameters
, sei
->lpParameters
);
1574 if (sei
->lpDirectory
)
1575 seiW
.lpDirectory
= __SHCloneStrAtoW(&wDirectory
, sei
->lpDirectory
);
1577 if ((sei
->fMask
& SEE_MASK_CLASSALL
) == SEE_MASK_CLASSNAME
&& sei
->lpClass
)
1578 seiW
.lpClass
= __SHCloneStrAtoW(&wClass
, sei
->lpClass
);
1580 seiW
.lpClass
= NULL
;
1582 ret
= SHELL_execute( &seiW
, SHELL_ExecuteW
);
1584 sei
->hInstApp
= seiW
.hInstApp
;
1586 if (sei
->fMask
& SEE_MASK_NOCLOSEPROCESS
)
1587 sei
->hProcess
= seiW
.hProcess
;
1589 if (wVerb
) SHFree(wVerb
);
1590 if (wFile
) SHFree(wFile
);
1591 if (wParameters
) SHFree(wParameters
);
1592 if (wDirectory
) SHFree(wDirectory
);
1593 if (wClass
) SHFree(wClass
);
1598 /*************************************************************************
1599 * ShellExecuteExW [SHELL32.293]
1602 BOOL WINAPI
ShellExecuteExW (LPSHELLEXECUTEINFOW sei
)
1604 return SHELL_execute( sei
, SHELL_ExecuteW
);
1607 /*************************************************************************
1608 * ShellExecuteW [SHELL32.294]
1610 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
1611 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
1613 HINSTANCE WINAPI
ShellExecuteW(HWND hwnd
, LPCWSTR lpOperation
, LPCWSTR lpFile
,
1614 LPCWSTR lpParameters
, LPCWSTR lpDirectory
, INT nShowCmd
)
1616 SHELLEXECUTEINFOW sei
;
1619 sei
.cbSize
= sizeof(sei
);
1622 sei
.lpVerb
= lpOperation
;
1623 sei
.lpFile
= lpFile
;
1624 sei
.lpParameters
= lpParameters
;
1625 sei
.lpDirectory
= lpDirectory
;
1626 sei
.nShow
= nShowCmd
;
1633 SHELL_execute( &sei
, SHELL_ExecuteW
);
1634 return sei
.hInstApp
;