Set the dll search path to the location specified in configure
[wine/multimedia.git] / dlls / shell32 / shlexec.c
blobb490b78a5471185cf4c2de0556cbacec1c6225c2
1 /*
2 * Shell Library Functions
4 * Copyright 1998 Marcus Meissner
5 * Copyright 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include <ctype.h>
33 #include <assert.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winerror.h"
38 #include "winreg.h"
39 #include "wownt32.h"
40 #include "heap.h"
41 #include "shellapi.h"
42 #include "wingdi.h"
43 #include "winuser.h"
44 #include "shlobj.h"
45 #include "shlwapi.h"
46 #include "ddeml.h"
48 #include "wine/winbase16.h"
49 #include "shell32_main.h"
50 #include "undocshell.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(exec);
56 /***********************************************************************
57 * this function is supposed to expand the escape sequences found in the registry
58 * some diving reported that the following were used:
59 * + %1, %2... seem to report to parameter of index N in ShellExecute pmts
60 * %1 file
61 * %2 printer
62 * %3 driver
63 * %4 port
64 * %I address of a global item ID (explorer switch /idlist)
65 * %L seems to be %1 as long filename followed by the 8+3 variation
66 * %S ???
67 * %* all following parameters (see batfile)
69 static BOOL argify(char* res, int len, const char* fmt, const char* lpFile)
71 char xlpFile[1024];
72 BOOL done = FALSE;
74 while (*fmt)
76 if (*fmt == '%')
78 switch (*++fmt)
80 case '\0':
81 case '%':
82 *res++ = '%';
83 break;
84 case '1':
85 case '*':
86 if (!done || (*fmt == '1'))
88 if (SearchPathA(NULL, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
90 strcpy(res, xlpFile);
91 res += strlen(xlpFile);
93 else
95 strcpy(res, lpFile);
96 res += strlen(lpFile);
99 break;
101 * IE uses this alot for activating things such as windows media
102 * player. This is not verified to be fully correct but it appears
103 * to work just fine.
105 case 'L':
106 strcpy(res,lpFile);
107 res += strlen(lpFile);
108 break;
110 default: FIXME("Unknown escape sequence %%%c\n", *fmt);
112 fmt++;
113 done = TRUE;
115 else
116 *res++ = *fmt++;
118 *res = '\0';
119 return done;
122 /*************************************************************************
123 * SHELL_ExecuteA [Internal]
126 static UINT SHELL_ExecuteA(char *lpCmd, LPSHELLEXECUTEINFOA sei, BOOL shWait)
128 STARTUPINFOA startup;
129 PROCESS_INFORMATION info;
130 UINT retval = 31;
132 TRACE("Execute %s from directory %s\n", lpCmd, sei->lpDirectory);
133 ZeroMemory(&startup,sizeof(STARTUPINFOA));
134 startup.cb = sizeof(STARTUPINFOA);
135 startup.dwFlags = STARTF_USESHOWWINDOW;
136 startup.wShowWindow = sei->nShow;
137 if (CreateProcessA(NULL, lpCmd, NULL, NULL, FALSE, 0,
138 NULL, sei->lpDirectory, &startup, &info))
140 /* Give 30 seconds to the app to come up, if desired. Probably only needed
141 when starting app immediately before making a DDE connection. */
142 if (shWait)
143 if (WaitForInputIdle( info.hProcess, 30000 ) == -1)
144 WARN("WaitForInputIdle failed: Error %ld\n", GetLastError() );
145 retval = 33;
146 if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
147 sei->hProcess = info.hProcess;
148 else
149 CloseHandle( info.hProcess );
150 CloseHandle( info.hThread );
152 else if ((retval = GetLastError()) >= 32)
154 FIXME("Strange error set by CreateProcess: %d\n", retval);
155 retval = ERROR_BAD_FORMAT;
158 sei->hInstApp = (HINSTANCE)retval;
159 return retval;
162 /***********************************************************************
163 * SHELL_TryAppPath
165 * Helper function for SHELL_FindExecutable
166 * @param lpResult - pointer to a buffer of size MAX_PATH
167 * On entry: szName is a filename (probably without path separators).
168 * On exit: if szName found in "App Path", place full path in lpResult, and return true
170 static BOOL SHELL_TryAppPath( LPCSTR szName, LPSTR lpResult)
172 HKEY hkApp = 0;
173 char szAppKey[256];
174 LONG len;
175 LONG res;
176 BOOL found = FALSE;
178 sprintf(szAppKey, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s", szName);
179 res = RegOpenKeyExA(HKEY_LOCAL_MACHINE, szAppKey, 0, KEY_READ, &hkApp);
180 if (res) {
181 /*TRACE("RegOpenKeyExA(HKEY_LOCAL_MACHINE, %s,) returns %ld\n", szAppKey, res);*/
182 goto end;
185 len = MAX_PATH;
186 res = RegQueryValueA(hkApp, NULL, lpResult, &len);
187 if (res) {
188 /*TRACE("RegQueryValueA(hkApp, NULL,) returns %ld\n", res);*/
189 goto end;
191 /*TRACE("%s -> %s\n", szName, lpResult);*/
192 found = TRUE;
194 end:
195 if (hkApp) RegCloseKey(hkApp);
196 return found;
199 /*************************************************************************
200 * SHELL_FindExecutable [Internal]
202 * Utility for code sharing between FindExecutable and ShellExecute
203 * in:
204 * lpFile the name of a file
205 * lpOperation the operation on it (open)
206 * out:
207 * lpResult a buffer, big enough :-(, to store the command to do the
208 * operation on the file
209 * key a buffer, big enough, to get the key name to do actually the
210 * command (it'll be used afterwards for more information
211 * on the operation)
213 static UINT SHELL_FindExecutable(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperation,
214 LPSTR lpResult, LPSTR key)
216 char *extension = NULL; /* pointer to file extension */
217 char tmpext[5]; /* local copy to mung as we please */
218 char filetype[256]; /* registry name for this filetype */
219 LONG filetypelen = 256; /* length of above */
220 char command[256]; /* command from registry */
221 LONG commandlen = 256; /* This is the most DOS can handle :) */
222 char buffer[256]; /* Used to GetProfileString */
223 UINT retval = 31; /* default - 'No association was found' */
224 char *tok; /* token pointer */
225 char xlpFile[256] = ""; /* result of SearchPath */
227 TRACE("%s\n", (lpFile != NULL) ? lpFile : "-");
229 lpResult[0] = '\0'; /* Start off with an empty return string */
230 if (key) *key = '\0';
232 /* trap NULL parameters on entry */
233 if ((lpFile == NULL) || (lpResult == NULL) || (lpOperation == NULL))
235 WARN("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
236 lpFile, lpOperation, lpResult);
237 return 2; /* File not found. Close enough, I guess. */
240 if (SHELL_TryAppPath( lpFile, lpResult ))
242 TRACE("found %s via App Paths\n", lpResult);
243 return 33;
246 if (SearchPathA(lpPath, lpFile, ".exe", sizeof(xlpFile), xlpFile, NULL))
248 TRACE("SearchPathA returned non-zero\n");
249 lpFile = xlpFile;
250 /* Hey, isn't this value ignored? Why make this call? Shouldn't we return here? --dank*/
253 /* First thing we need is the file's extension */
254 extension = strrchr(xlpFile, '.'); /* Assume last "." is the one; */
255 /* File->Run in progman uses */
256 /* .\FILE.EXE :( */
257 TRACE("xlpFile=%s,extension=%s\n", xlpFile, extension);
259 if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
261 WARN("Returning 31 - No association\n");
262 return 31; /* no association */
265 /* Make local copy & lowercase it for reg & 'programs=' lookup */
266 lstrcpynA(tmpext, extension, 5);
267 CharLowerA(tmpext);
268 TRACE("%s file\n", tmpext);
270 /* Three places to check: */
271 /* 1. win.ini, [windows], programs (NB no leading '.') */
272 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
273 /* 3. win.ini, [extensions], extension (NB no leading '.' */
274 /* All I know of the order is that registry is checked before */
275 /* extensions; however, it'd make sense to check the programs */
276 /* section first, so that's what happens here. */
278 /* See if it's a program - if GetProfileString fails, we skip this
279 * section. Actually, if GetProfileString fails, we've probably
280 * got a lot more to worry about than running a program... */
281 if (GetProfileStringA("windows", "programs", "exe pif bat cmd com",
282 buffer, sizeof(buffer)) > 0)
284 UINT i;
286 for (i = 0;i<strlen(buffer); i++) buffer[i] = tolower(buffer[i]);
288 tok = strtok(buffer, " \t"); /* ? */
289 while (tok!= NULL)
291 if (strcmp(tok, &tmpext[1]) == 0) /* have to skip the leading "." */
293 strcpy(lpResult, xlpFile);
294 /* Need to perhaps check that the file has a path
295 * attached */
296 TRACE("found %s\n", lpResult);
297 return 33;
299 /* Greater than 32 to indicate success FIXME According to the
300 * docs, I should be returning a handle for the
301 * executable. Does this mean I'm supposed to open the
302 * executable file or something? More RTFM, I guess... */
304 tok = strtok(NULL, " \t");
308 /* Check registry */
309 if (RegQueryValueA(HKEY_CLASSES_ROOT, tmpext, filetype,
310 &filetypelen) == ERROR_SUCCESS)
312 filetype[filetypelen] = '\0';
313 TRACE("File type: %s\n", filetype);
315 /* Looking for ...buffer\shell\lpOperation\command */
316 strcat(filetype, "\\shell\\");
317 strcat(filetype, lpOperation);
318 strcat(filetype, "\\command");
320 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, command,
321 &commandlen) == ERROR_SUCCESS)
323 if (key) strcpy(key, filetype);
324 #if 0
325 LPSTR tmp;
326 char param[256];
327 LONG paramlen = 256;
329 /* FIXME: it seems all Windows version don't behave the same here.
330 * the doc states that this ddeexec information can be found after
331 * the exec names.
332 * on Win98, it doesn't appear, but I think it does on Win2k
334 /* Get the parameters needed by the application
335 from the associated ddeexec key */
336 tmp = strstr(filetype, "command");
337 tmp[0] = '\0';
338 strcat(filetype, "ddeexec");
340 if (RegQueryValueA(HKEY_CLASSES_ROOT, filetype, param, &paramlen) == ERROR_SUCCESS)
342 strcat(command, " ");
343 strcat(command, param);
344 commandlen += paramlen;
346 #endif
347 command[commandlen] = '\0';
348 argify(lpResult, sizeof(lpResult), command, xlpFile);
349 retval = 33; /* FIXME see above */
352 else /* Check win.ini */
354 /* Toss the leading dot */
355 extension++;
356 if (GetProfileStringA("extensions", extension, "", command,
357 sizeof(command)) > 0)
359 if (strlen(command) != 0)
361 strcpy(lpResult, command);
362 tok = strstr(lpResult, "^"); /* should be ^.extension? */
363 if (tok != NULL)
365 tok[0] = '\0';
366 strcat(lpResult, xlpFile); /* what if no dir in xlpFile? */
367 tok = strstr(command, "^"); /* see above */
368 if ((tok != NULL) && (strlen(tok)>5))
370 strcat(lpResult, &tok[5]);
373 retval = 33; /* FIXME - see above */
378 TRACE("returning %s\n", lpResult);
379 return retval;
382 /******************************************************************
383 * dde_cb
385 * callback for the DDE connection. not really usefull
387 static HDDEDATA CALLBACK dde_cb(UINT uType, UINT uFmt, HCONV hConv,
388 HSZ hsz1, HSZ hsz2,
389 HDDEDATA hData, DWORD dwData1, DWORD dwData2)
391 return NULL;
394 /******************************************************************
395 * dde_connect
397 * ShellExecute helper. Used to do an operation with a DDE connection
399 * Handles both the direct connection (try #1), and if it fails,
400 * launching an application and trying (#2) to connect to it
403 static unsigned dde_connect(char* key, char* start, char* ddeexec,
404 const char* lpFile,
405 LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc)
407 char* endkey = key + strlen(key);
408 char app[256], topic[256], ifexec[256], res[256];
409 LONG applen, topiclen, ifexeclen;
410 char* exec;
411 DWORD ddeInst = 0;
412 DWORD tid;
413 HSZ hszApp, hszTopic;
414 HCONV hConv;
415 unsigned ret = 31;
417 strcpy(endkey, "\\application");
418 applen = sizeof(app);
419 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, app, &applen) != ERROR_SUCCESS)
421 FIXME("default app name NIY %s\n", key);
422 return 2;
425 strcpy(endkey, "\\topic");
426 topiclen = sizeof(topic);
427 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, topic, &topiclen) != ERROR_SUCCESS)
429 strcpy(topic, "System");
432 if (DdeInitializeA(&ddeInst, dde_cb, APPCMD_CLIENTONLY, 0L) != DMLERR_NO_ERROR)
434 return 2;
437 hszApp = DdeCreateStringHandleA(ddeInst, app, CP_WINANSI);
438 hszTopic = DdeCreateStringHandleA(ddeInst, topic, CP_WINANSI);
440 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
441 exec = ddeexec;
442 if (!hConv)
444 TRACE("Launching '%s'\n", start);
445 ret = execfunc(start, sei, TRUE);
446 if (ret < 32)
448 TRACE("Couldn't launch\n");
449 goto error;
451 hConv = DdeConnect(ddeInst, hszApp, hszTopic, NULL);
452 if (!hConv)
454 TRACE("Couldn't connect. ret=%d\n", ret);
455 ret = 30; /* whatever */
456 goto error;
458 strcpy(endkey, "\\ifexec");
459 ifexeclen = sizeof(ifexec);
460 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, ifexec, &ifexeclen) == ERROR_SUCCESS)
462 exec = ifexec;
466 argify(res, sizeof(res), exec, lpFile);
467 TRACE("%s %s => %s\n", exec, lpFile, res);
469 ret = (DdeClientTransaction(res, strlen(res) + 1, hConv, 0L, 0,
470 XTYP_EXECUTE, 10000, &tid) != DMLERR_NO_ERROR) ? 31 : 33;
471 DdeDisconnect(hConv);
472 error:
473 DdeUninitialize(ddeInst);
474 return ret;
477 /*************************************************************************
478 * execute_from_key [Internal]
480 static UINT execute_from_key(LPSTR key, LPCSTR lpFile, LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc)
482 char cmd[1024] = "";
483 LONG cmdlen = sizeof(cmd);
484 UINT retval = 31;
486 /* Get the application for the registry */
487 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, cmd, &cmdlen) == ERROR_SUCCESS)
489 LPSTR tmp;
490 char param[256] = "";
491 LONG paramlen = 256;
493 /* Get the parameters needed by the application
494 from the associated ddeexec key */
495 tmp = strstr(key, "command");
496 assert(tmp);
497 strcpy(tmp, "ddeexec");
499 if (RegQueryValueA(HKEY_CLASSES_ROOT, key, param, &paramlen) == ERROR_SUCCESS)
501 TRACE("Got ddeexec %s => %s\n", key, param);
502 retval = dde_connect(key, cmd, param, lpFile, sei, execfunc);
504 else
506 /* Is there a replace() function anywhere? */
507 cmd[cmdlen] = '\0';
508 argify(param, sizeof(param), cmd, lpFile);
509 retval = execfunc(param, sei, FALSE);
512 else TRACE("ooch\n");
514 return retval;
517 /*************************************************************************
518 * FindExecutableA [SHELL32.@]
520 HINSTANCE WINAPI FindExecutableA(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
522 UINT retval = 31; /* default - 'No association was found' */
523 char old_dir[1024];
525 TRACE("File %s, Dir %s\n",
526 (lpFile != NULL ? lpFile : "-"), (lpDirectory != NULL ? lpDirectory : "-"));
528 lpResult[0] = '\0'; /* Start off with an empty return string */
530 /* trap NULL parameters on entry */
531 if ((lpFile == NULL) || (lpResult == NULL))
533 /* FIXME - should throw a warning, perhaps! */
534 return (HINSTANCE)2; /* File not found. Close enough, I guess. */
537 if (lpDirectory)
539 GetCurrentDirectoryA(sizeof(old_dir), old_dir);
540 SetCurrentDirectoryA(lpDirectory);
543 retval = SHELL_FindExecutable(lpDirectory, lpFile, "open", lpResult, NULL);
545 TRACE("returning %s\n", lpResult);
546 if (lpDirectory)
547 SetCurrentDirectoryA(old_dir);
548 return (HINSTANCE)retval;
551 /*************************************************************************
552 * FindExecutableW [SHELL32.@]
554 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
556 FIXME("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
557 return (HINSTANCE)31; /* default - 'No association was found' */
560 /*************************************************************************
561 * ShellExecuteExA32 [Internal]
563 BOOL WINAPI ShellExecuteExA32 (LPSHELLEXECUTEINFOA sei, SHELL_ExecuteA1632 execfunc)
565 CHAR szApplicationName[MAX_PATH],szCommandline[MAX_PATH],szPidl[20],fileName[MAX_PATH];
566 LPSTR pos;
567 int gap, len;
568 char lpstrProtocol[256];
569 LPCSTR lpFile,lpOperation;
570 UINT retval = 31;
571 char cmd[1024];
572 BOOL done;
574 TRACE("mask=0x%08lx hwnd=%p verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s\n",
575 sei->fMask, sei->hwnd, debugstr_a(sei->lpVerb),
576 debugstr_a(sei->lpFile), debugstr_a(sei->lpParameters),
577 debugstr_a(sei->lpDirectory), sei->nShow,
578 (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei->lpClass) : "not used");
580 sei->hProcess = NULL;
581 ZeroMemory(szApplicationName,MAX_PATH);
582 if (sei->lpFile)
583 strcpy(szApplicationName, sei->lpFile);
585 ZeroMemory(szCommandline,MAX_PATH);
586 if (sei->lpParameters)
587 strcpy(szCommandline, sei->lpParameters);
589 if (sei->fMask & (SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
590 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
591 SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
592 SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
594 FIXME("flags ignored: 0x%08lx\n", sei->fMask);
597 /* process the IDList */
598 if ( (sei->fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST) /*0x0c*/
600 SHGetPathFromIDListA (sei->lpIDList,szApplicationName);
601 TRACE("-- idlist=%p (%s)\n", sei->lpIDList, szApplicationName);
603 else
605 if (sei->fMask & SEE_MASK_IDLIST )
607 pos = strstr(szCommandline, "%I");
608 if (pos)
610 LPVOID pv;
611 HGLOBAL hmem = SHAllocShared ( sei->lpIDList, ILGetSize(sei->lpIDList), 0);
612 pv = SHLockShared(hmem,0);
613 sprintf(szPidl,":%p",pv );
614 SHUnlockShared(pv);
616 gap = strlen(szPidl);
617 len = strlen(pos)-2;
618 memmove(pos+gap,pos+2,len);
619 memcpy(pos,szPidl,gap);
624 if (sei->fMask & (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY))
626 /* launch a document by fileclass like 'WordPad.Document.1' */
627 /* the Commandline contains 'c:\Path\wordpad.exe "%1"' */
628 /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
629 if (sei->fMask & SEE_MASK_CLASSKEY)
630 HCR_GetExecuteCommandEx(sei->hkeyClass,
631 (sei->fMask & SEE_MASK_CLASSNAME) ? sei->lpClass: NULL,
632 (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
633 else if (sei->fMask & SEE_MASK_CLASSNAME)
634 HCR_GetExecuteCommandA(sei->lpClass, (sei->lpVerb) ? sei->lpVerb :
635 "open", szCommandline, sizeof(szCommandline));
637 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
638 TRACE("SEE_MASK_CLASSNAME->'%s', doc->'%s'\n", szCommandline, szApplicationName);
640 cmd[0] = '\0';
641 done = argify(cmd, sizeof(cmd), szCommandline, szApplicationName);
642 if (!done && szApplicationName[0])
644 strcat(cmd, " ");
645 strcat(cmd, szApplicationName);
647 retval = execfunc(cmd, sei, FALSE);
648 if (retval > 32)
649 return TRUE;
650 else
651 return FALSE;
654 /* We set the default to open, and that should generally work.
655 But that is not really the way the MS docs say to do it. */
656 if (sei->lpVerb == NULL)
657 lpOperation = "open";
658 else
659 lpOperation = sei->lpVerb;
661 /* Else, try to execute the filename */
662 TRACE("execute:'%s','%s'\n",szApplicationName, szCommandline);
664 strcpy(fileName, szApplicationName);
665 lpFile = fileName;
666 if (szCommandline[0]) {
667 strcat(szApplicationName, " ");
668 strcat(szApplicationName, szCommandline);
671 retval = execfunc(szApplicationName, sei, FALSE);
672 if (retval > 32)
673 return TRUE;
675 /* Else, try to find the executable */
676 cmd[0] = '\0';
677 retval = SHELL_FindExecutable(sei->lpDirectory, lpFile, lpOperation, cmd, lpstrProtocol);
678 if (retval > 32) /* Found */
680 CHAR szQuotedCmd[MAX_PATH+2];
681 /* Must quote to handle case where cmd contains spaces,
682 * else security hole if malicious user creates executable file "C:\\Program"
684 if (szCommandline[0])
685 sprintf(szQuotedCmd, "\"%s\" %s", cmd, szCommandline);
686 else
687 sprintf(szQuotedCmd, "\"%s\"", cmd);
688 TRACE("%s/%s => %s/%s\n", szApplicationName, lpOperation, szQuotedCmd, lpstrProtocol);
689 if (*lpstrProtocol)
690 retval = execute_from_key(lpstrProtocol, szApplicationName, sei, execfunc);
691 else
692 retval = execfunc(szQuotedCmd, sei, FALSE);
694 else if (PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */
696 LPSTR lpstrRes;
697 INT iSize;
699 lpstrRes = strchr(lpFile, ':');
700 if (lpstrRes)
701 iSize = lpstrRes - lpFile;
702 else
703 iSize = strlen(lpFile);
705 TRACE("Got URL: %s\n", lpFile);
706 /* Looking for ...protocol\shell\lpOperation\command */
707 strncpy(lpstrProtocol, lpFile, iSize);
708 lpstrProtocol[iSize] = '\0';
709 strcat(lpstrProtocol, "\\shell\\");
710 strcat(lpstrProtocol, lpOperation);
711 strcat(lpstrProtocol, "\\command");
713 /* Remove File Protocol from lpFile */
714 /* In the case file://path/file */
715 if (!strncasecmp(lpFile, "file", iSize))
717 lpFile += iSize;
718 while (*lpFile == ':') lpFile++;
720 retval = execute_from_key(lpstrProtocol, lpFile, sei, execfunc);
722 /* Check if file specified is in the form www.??????.*** */
723 else if (!strncasecmp(lpFile, "www", 3))
725 /* if so, append lpFile http:// and call ShellExecute */
726 char lpstrTmpFile[256] = "http://" ;
727 strcat(lpstrTmpFile, lpFile);
728 retval = (UINT)ShellExecuteA(sei->hwnd, lpOperation, lpstrTmpFile, NULL, NULL, 0);
731 if (retval <= 32)
733 sei->hInstApp = (HINSTANCE)retval;
734 return FALSE;
737 sei->hInstApp = (HINSTANCE)33;
738 return TRUE;
741 /*************************************************************************
742 * ShellExecuteA [SHELL32.290]
744 HINSTANCE WINAPI ShellExecuteA(HWND hWnd, LPCSTR lpOperation,LPCSTR lpFile,
745 LPCSTR lpParameters,LPCSTR lpDirectory, INT iShowCmd)
747 SHELLEXECUTEINFOA sei;
748 HANDLE hProcess = 0;
750 TRACE("\n");
751 sei.cbSize = sizeof(sei);
752 sei.fMask = 0;
753 sei.hwnd = hWnd;
754 sei.lpVerb = lpOperation;
755 sei.lpFile = lpFile;
756 sei.lpParameters = lpParameters;
757 sei.lpDirectory = lpDirectory;
758 sei.nShow = iShowCmd;
759 sei.lpIDList = 0;
760 sei.lpClass = 0;
761 sei.hkeyClass = 0;
762 sei.dwHotKey = 0;
763 sei.hProcess = hProcess;
765 ShellExecuteExA32 (&sei, SHELL_ExecuteA);
766 return sei.hInstApp;
769 /*************************************************************************
770 * ShellExecuteEx [SHELL32.291]
773 BOOL WINAPI ShellExecuteExAW (LPVOID sei)
775 if (SHELL_OsIsUnicode())
776 return ShellExecuteExW (sei);
777 return ShellExecuteExA32 (sei, SHELL_ExecuteA);
780 /*************************************************************************
781 * ShellExecuteExA [SHELL32.292]
784 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
786 return ShellExecuteExA32 (sei, SHELL_ExecuteA);
789 /*************************************************************************
790 * ShellExecuteExW [SHELL32.293]
793 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
795 SHELLEXECUTEINFOA seiA;
796 DWORD ret;
798 TRACE("%p\n", sei);
800 memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
802 if (sei->lpVerb)
803 seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
805 if (sei->lpFile)
806 seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
808 if (sei->lpParameters)
809 seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
811 if (sei->lpDirectory)
812 seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
814 if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
815 seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
816 else
817 seiA.lpClass = NULL;
819 ret = ShellExecuteExA(&seiA);
821 if (seiA.lpVerb) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
822 if (seiA.lpFile) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
823 if (seiA.lpParameters) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
824 if (seiA.lpDirectory) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
825 if (seiA.lpClass) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
827 return ret;
830 /*************************************************************************
831 * ShellExecuteW [SHELL32.294]
832 * from shellapi.h
833 * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation,
834 * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
836 HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile,
837 LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
839 SHELLEXECUTEINFOW sei;
840 HANDLE hProcess = 0;
842 TRACE("\n");
843 sei.cbSize = sizeof(sei);
844 sei.fMask = 0;
845 sei.hwnd = hwnd;
846 sei.lpVerb = lpOperation;
847 sei.lpFile = lpFile;
848 sei.lpParameters = lpParameters;
849 sei.lpDirectory = lpDirectory;
850 sei.nShow = nShowCmd;
851 sei.lpIDList = 0;
852 sei.lpClass = 0;
853 sei.hkeyClass = 0;
854 sei.dwHotKey = 0;
855 sei.hProcess = hProcess;
857 ShellExecuteExW (&sei);
858 return sei.hInstApp;