mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 13:56:56 +00:00
ShellExecute is run when executable is not found to open for example Notepad files by typing "myfile.txt".
svn path=/trunk/; revision=10147
This commit is contained in:
parent
016e6a3f65
commit
15971f9aa5
1 changed files with 91 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $Id: cmd.c,v 1.16 2004/06/21 18:57:22 weiden Exp $
|
||||
/* $Id: cmd.c,v 1.17 2004/07/16 20:39:06 jc Exp $
|
||||
*
|
||||
* CMD.C - command-line interface.
|
||||
*
|
||||
|
@ -126,6 +126,9 @@
|
|||
* 28-Mai-2004 (Hartmut Birr)
|
||||
* Removed MakeSureDirectoryPathExistsEx.
|
||||
* Use the current directory if GetTempPath fails.
|
||||
*
|
||||
* 12-Jul-2004 (Jens Collin <jens.collin@lakhei.com>)
|
||||
* Added ShellExecute call when all else fails to be able to "launch" any file.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -146,6 +149,8 @@
|
|||
#include "cmd.h"
|
||||
#include "batch.h"
|
||||
|
||||
#include <shellapi.h>
|
||||
|
||||
typedef NTSTATUS (STDCALL *NtQueryInformationProcessProc)(HANDLE, PROCESSINFOCLASS,
|
||||
PVOID, ULONG, PULONG);
|
||||
typedef NTSTATUS (STDCALL *NtReadVirtualMemoryProc)(HANDLE, PVOID, PVOID, ULONG, PULONG);
|
||||
|
@ -241,6 +246,68 @@ static BOOL IsConsoleProcess(HANDLE Process)
|
|||
}
|
||||
|
||||
|
||||
|
||||
#ifdef _UNICODE
|
||||
#define SHELLEXECUTETEXT L"ShellExecuteW"
|
||||
#else
|
||||
#define SHELLEXECUTETEXT "ShellExecuteA"
|
||||
#endif
|
||||
|
||||
typedef HINSTANCE (WINAPI *MYEX)(
|
||||
HWND hwnd,
|
||||
LPCTSTR lpOperation,
|
||||
LPCTSTR lpFile,
|
||||
LPCTSTR lpParameters,
|
||||
LPCTSTR lpDirectory,
|
||||
INT nShowCmd
|
||||
);
|
||||
|
||||
|
||||
|
||||
static BOOL RunFile(LPTSTR filename)
|
||||
{
|
||||
HMODULE hShell32;
|
||||
MYEX hShExt;
|
||||
HINSTANCE ret;
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("RunFile(%s)\n"), filename);
|
||||
#endif
|
||||
hShell32 = LoadLibrary(_T("SHELL32.DLL"));
|
||||
if (!hShell32)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("RunFile: couldn't load SHELL32.DLL!\n"));
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
hShExt = (MYEX)(FARPROC)GetProcAddress(hShell32, SHELLEXECUTETEXT);
|
||||
if (!hShExt)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("RunFile: couldn't find ShellExecuteA/W in SHELL32.DLL!\n"));
|
||||
#endif
|
||||
FreeLibrary(hShell32);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("RunFile: ShellExecuteA/W is at %x\n"), hShExt);
|
||||
#endif
|
||||
|
||||
ret = (hShExt)(NULL, _T("open"), filename, NULL, NULL, SW_SHOWNORMAL);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("RunFile: ShellExecuteA/W returned %d\n"), (DWORD)ret);
|
||||
#endif
|
||||
|
||||
FreeLibrary(hShell32);
|
||||
return (((DWORD)ret) > 32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* This command (in first) was not found in the command table
|
||||
*
|
||||
|
@ -353,8 +420,17 @@ Execute (LPTSTR full, LPTSTR first, LPTSTR rest)
|
|||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage (GetLastError (),
|
||||
_T("Error executing CreateProcess()!!\n"));
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("[ShellExecute: %s]\n"), full);
|
||||
#endif
|
||||
// See if we can run this with ShellExecute() ie myfile.xls
|
||||
if (!RunFile(full))
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
DebugPrintf (_T("[ShellExecute failed!: %s]\n"), full);
|
||||
#endif
|
||||
error_bad_command ();
|
||||
}
|
||||
}
|
||||
// restore console mode
|
||||
SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue