From a127ad1cd1f323db151b05bc0bff6849e7699b43 Mon Sep 17 00:00:00 2001 From: Stefan Leichter Date: Tue, 25 Mar 2003 00:33:56 +0000 Subject: [PATCH] Let wcmd handle .cmd files like .bat files. --- dlls/shell32/shlexec.c | 2 +- programs/wcmd/batch.c | 11 +++++++++-- programs/wcmd/wcmdmain.c | 9 ++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c index 74453062b75..752e7c55fe7 100644 --- a/dlls/shell32/shlexec.c +++ b/dlls/shell32/shlexec.c @@ -264,7 +264,7 @@ static UINT SHELL_FindExecutable(LPCSTR lpPath, LPCSTR lpFile, LPCSTR lpOperatio /* See if it's a program - if GetProfileString fails, we skip this * section. Actually, if GetProfileString fails, we've probably * got a lot more to worry about than running a program... */ - if (GetProfileStringA("windows", "programs", "exe pif bat com", + if (GetProfileStringA("windows", "programs", "exe pif bat cmd com", buffer, sizeof(buffer)) > 0) { UINT i; diff --git a/programs/wcmd/batch.c b/programs/wcmd/batch.c index 8abac877817..d594e4b1450 100644 --- a/programs/wcmd/batch.c +++ b/programs/wcmd/batch.c @@ -47,15 +47,22 @@ extern DWORD errorlevel; void WCMD_batch (char *file, char *command, int called) { -HANDLE h; +#define WCMD_BATCH_EXT_SIZE 5 + +HANDLE h = INVALID_HANDLE_VALUE; char string[MAXSTRING]; +char extension[][WCMD_BATCH_EXT_SIZE] = {".bat",".cmd"}; +int i; BATCH_CONTEXT *prev_context; + for(i=0; (i<(sizeof(extension)/WCMD_BATCH_EXT_SIZE)) && + (h == INVALID_HANDLE_VALUE); i++) { strcpy (string, file); CharLower (string); - if (strstr (string, ".bat") == NULL) strcat (string, ".bat"); + if (strstr (string, extension[i]) == NULL) strcat (string, extension[i]); h = CreateFile (string, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + } if (h == INVALID_HANDLE_VALUE) { SetLastError (ERROR_FILE_NOT_FOUND); WCMD_print_error (); diff --git a/programs/wcmd/wcmdmain.c b/programs/wcmd/wcmdmain.c index ab5cd4ec471..6f660cf1533 100644 --- a/programs/wcmd/wcmdmain.c +++ b/programs/wcmd/wcmdmain.c @@ -366,9 +366,16 @@ char filetorun[MAX_PATH]; return; } } + if ((strchr (param1, '.') == NULL) || (strstr (param1, ".cmd") != NULL)) { + if (SearchPath (NULL, param1, ".cmd", sizeof(filetorun), filetorun, NULL)) { + WCMD_batch (filetorun, command, 0); + return; + } + } } else { /* Explicit path given */ - if (strstr (param1, ".bat") != NULL) { + if ((strstr (param1, ".bat") != NULL) || + (strstr (param1, ".cmd") != NULL)) { WCMD_batch (param1, command, 0); return; }