[ros-diffs] [jmorlan] 40148: - When running a non-executable file, if the program handling the file type is a console program (e.g. Perl/Python) it should run in the same console as cmd, and cmd should wait for it. Implement this by using ShellExecuteEx instead of plain ShellExecute, with the SEE_MASK_NOCLOSEPROCESS and SEE_MASK_NO_CONSOLE flags. (SEE_MASK_NO_CONSOLE does the opposite of its MSDN description) - Use NULL as the lpVerb to get the default action ("open" is not necessarily the default) - Allow passing parameters besides just the file name

jmorlan at svn.reactos.org jmorlan at svn.reactos.org
Sat Mar 21 03:12:24 CET 2009


Author: jmorlan
Date: Sat Mar 21 05:12:23 2009
New Revision: 40148

URL: http://svn.reactos.org/svn/reactos?rev=40148&view=rev
Log:
- When running a non-executable file, if the program handling the file type is a console program (e.g. Perl/Python) it should run in the same console as cmd, and cmd should wait for it. Implement this by using ShellExecuteEx instead of plain ShellExecute, with the SEE_MASK_NOCLOSEPROCESS and SEE_MASK_NO_CONSOLE flags. (SEE_MASK_NO_CONSOLE does the opposite of its MSDN description)
- Use NULL as the lpVerb to get the default action ("open" is not necessarily the default)
- Allow passing parameters besides just the file name

Modified:
    trunk/reactos/base/shell/cmd/cmd.c

Modified: trunk/reactos/base/shell/cmd/cmd.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=40148&r1=40147&r2=40148&view=diff
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Sat Mar 21 05:12:23 2009
@@ -258,52 +258,50 @@
 
 
 #ifdef _UNICODE
-#define SHELLEXECUTETEXT   	"ShellExecuteW"
+#define SHELLEXECUTETEXT   	"ShellExecuteExW"
 #else
-#define SHELLEXECUTETEXT   	"ShellExecuteA"
+#define SHELLEXECUTETEXT   	"ShellExecuteExA"
 #endif
 
-typedef HINSTANCE (WINAPI *MYEX)(
-	HWND hwnd,
-	LPCTSTR lpOperation,
-	LPCTSTR lpFile,
-	LPCTSTR lpParameters,
-	LPCTSTR lpDirectory,
-	INT nShowCmd
-);
-
-
-
-static BOOL RunFile(LPTSTR filename)
-{
+typedef BOOL (WINAPI *MYEX)(LPSHELLEXECUTEINFO lpExecInfo);
+
+static HANDLE RunFile(LPTSTR filename, LPTSTR params)
+{
+	SHELLEXECUTEINFO sei;
 	HMODULE     hShell32;
 	MYEX        hShExt;
-	HINSTANCE   ret;
+	BOOL        ret;
 
 	TRACE ("RunFile(%s)\n", debugstr_aw(filename));
 	hShell32 = LoadLibrary(_T("SHELL32.DLL"));
 	if (!hShell32)
 	{
 		WARN ("RunFile: couldn't load SHELL32.DLL!\n");
-		return FALSE;
+		return NULL;
 	}
 
 	hShExt = (MYEX)(FARPROC)GetProcAddress(hShell32, SHELLEXECUTETEXT);
 	if (!hShExt)
 	{
-		WARN ("RunFile: couldn't find ShellExecuteA/W in SHELL32.DLL!\n");
+		WARN ("RunFile: couldn't find ShellExecuteExA/W in SHELL32.DLL!\n");
 		FreeLibrary(hShell32);
-		return FALSE;
-	}
-
-	TRACE ("RunFile: ShellExecuteA/W is at %x\n", hShExt);
-
-	ret = (hShExt)(NULL, _T("open"), filename, NULL, NULL, SW_SHOWNORMAL);
-
-	TRACE ("RunFile: ShellExecuteA/W returned 0x%p\n", ret);
+		return NULL;
+	}
+
+	TRACE ("RunFile: ShellExecuteExA/W is at %x\n", hShExt);
+
+	memset(&sei, 0, sizeof sei);
+	sei.cbSize = sizeof sei;
+	sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE;
+	sei.lpFile = filename;
+	sei.lpParameters = params;
+	sei.nShow = SW_SHOWNORMAL;
+	ret = hShExt(&sei);
+
+	TRACE ("RunFile: ShellExecuteExA/W returned 0x%p\n", ret);
 
 	FreeLibrary(hShell32);
-	return (((DWORD_PTR)ret) > 32);
+	return ret ? sei.hProcess : NULL;
 }
 
 
@@ -496,6 +494,16 @@
 		                   &prci))
 
 		{
+			CloseHandle(prci.hThread);
+		}
+		else
+		{
+			// See if we can run this with ShellExecute() ie myfile.xls
+			prci.hProcess = RunFile(szFullName, rest);
+		}
+
+		if (prci.hProcess != NULL)
+		{
 			if (IsConsoleProcess(prci.hProcess))
 			{
 				/* FIXME: Protect this with critical section */
@@ -514,24 +522,15 @@
                         {
                             nErrorLevel = 0;
                         }
-			CloseHandle (prci.hThread);
 			CloseHandle (prci.hProcess);
 		}
 		else
 		{
-			TRACE ("[ShellExecute: %s]\n", debugstr_aw(full));
-			// See if we can run this with ShellExecute() ie myfile.xls
-			if (!RunFile(full))
-			{
-				TRACE ("[ShellExecute failed!: %s]\n", debugstr_aw(full));
-				error_bad_command (first);
-                                nErrorLevel = 1;
-			}
-                        else
-                        {
-                                nErrorLevel = 0;
-                        }
-		}
+			TRACE ("[ShellExecute failed!: %s]\n", debugstr_aw(full));
+			error_bad_command (first);
+			nErrorLevel = 1;
+		}
+
 		// restore console mode
 		SetConsoleMode (
 			GetStdHandle( STD_INPUT_HANDLE ),



More information about the Ros-diffs mailing list