2003-01-21 21:14:36 +01:00
|
|
|
/*
|
|
|
|
* Start a program using ShellExecuteEx, optionally wait for it to finish
|
|
|
|
* Compatible with Microsoft's "c:\windows\command\start.exe"
|
|
|
|
*
|
|
|
|
* Copyright 2003 Dan Kegel
|
2007-12-11 21:14:13 +01:00
|
|
|
* Copyright 2007 Lyutin Anatoly (Etersoft)
|
2003-01-21 21:14:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-01-21 21:14:36 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-01-23 12:16:36 +01:00
|
|
|
#include <windows.h>
|
2003-01-21 21:14:36 +01:00
|
|
|
#include <shlobj.h>
|
2012-01-23 12:16:36 +01:00
|
|
|
#include <shellapi.h>
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2007-12-11 21:14:13 +01:00
|
|
|
#include <wine/debug.h>
|
|
|
|
|
2003-01-21 21:14:36 +01:00
|
|
|
#include "resources.h"
|
|
|
|
|
2007-12-11 21:14:13 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(start);
|
|
|
|
|
2003-01-21 21:14:36 +01:00
|
|
|
/**
|
|
|
|
Output given message to stdout without formatting.
|
|
|
|
*/
|
2007-12-11 21:14:13 +01:00
|
|
|
static void output(const WCHAR *message)
|
2003-01-21 21:14:36 +01:00
|
|
|
{
|
|
|
|
DWORD count;
|
2007-12-11 21:14:13 +01:00
|
|
|
DWORD res;
|
2019-05-01 10:40:12 +02:00
|
|
|
int wlen = lstrlenW(message);
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2007-12-11 21:14:13 +01:00
|
|
|
if (!wlen) return;
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2007-12-11 21:14:13 +01:00
|
|
|
res = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), message, wlen, &count, NULL);
|
|
|
|
|
2011-08-24 15:28:14 +02:00
|
|
|
/* If writing to console fails, assume it's file
|
|
|
|
* i/o so convert to OEM codepage and output
|
|
|
|
*/
|
2007-12-11 21:14:13 +01:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
char *mesA;
|
|
|
|
/* Convert to OEM, then output */
|
|
|
|
len = WideCharToMultiByte( GetConsoleOutputCP(), 0, message, wlen, NULL, 0, NULL, NULL );
|
|
|
|
mesA = HeapAlloc(GetProcessHeap(), 0, len*sizeof(char));
|
|
|
|
if (!mesA) return;
|
|
|
|
WideCharToMultiByte( GetConsoleOutputCP(), 0, message, wlen, mesA, len, NULL, NULL );
|
|
|
|
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), mesA, len, &count, FALSE);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mesA);
|
2003-01-21 21:14:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Output given message from string table,
|
|
|
|
followed by ": ",
|
|
|
|
followed by description of given GetLastError() value to stdout,
|
|
|
|
followed by a trailing newline,
|
|
|
|
then terminate.
|
|
|
|
*/
|
2007-12-11 21:14:13 +01:00
|
|
|
|
2010-03-29 12:26:55 +02:00
|
|
|
static void fatal_error(const WCHAR *msg, DWORD error_code, const WCHAR *filename)
|
2007-12-11 21:14:13 +01:00
|
|
|
{
|
2010-03-29 12:26:55 +02:00
|
|
|
DWORD_PTR args[1];
|
2007-12-11 21:14:13 +01:00
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
output(msg);
|
2020-11-12 00:37:56 +01:00
|
|
|
output(L": ");
|
2010-03-29 12:26:55 +02:00
|
|
|
args[0] = (DWORD_PTR)filename;
|
|
|
|
status = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
|
|
|
|
NULL, error_code, 0, (LPWSTR)&lpMsgBuf, 0, (__ms_va_list *)args );
|
2007-12-11 21:14:13 +01:00
|
|
|
if (!status)
|
|
|
|
{
|
|
|
|
WINE_ERR("FormatMessage failed\n");
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
output(lpMsgBuf);
|
|
|
|
LocalFree((HLOCAL) lpMsgBuf);
|
2020-11-12 00:37:56 +01:00
|
|
|
output(L"\n");
|
2007-12-11 21:14:13 +01:00
|
|
|
}
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
2010-03-29 12:26:55 +02:00
|
|
|
static void fatal_string_error(int which, DWORD error_code, const WCHAR *filename)
|
2003-01-21 21:14:36 +01:00
|
|
|
{
|
2007-12-11 21:14:13 +01:00
|
|
|
WCHAR msg[2048];
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2018-07-13 19:01:30 +02:00
|
|
|
if (!LoadStringW(GetModuleHandleW(NULL), which, msg, ARRAY_SIZE(msg)))
|
2007-12-11 21:14:13 +01:00
|
|
|
WINE_ERR("LoadString failed, error %d\n", GetLastError());
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2010-03-29 12:26:55 +02:00
|
|
|
fatal_error(msg, error_code, filename);
|
2003-01-21 21:14:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fatal_string(int which)
|
|
|
|
{
|
2007-12-11 21:14:13 +01:00
|
|
|
WCHAR msg[2048];
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2018-07-13 19:01:30 +02:00
|
|
|
if (!LoadStringW(GetModuleHandleW(NULL), which, msg, ARRAY_SIZE(msg)))
|
2007-12-11 21:14:13 +01:00
|
|
|
WINE_ERR("LoadString failed, error %d\n", GetLastError());
|
2003-01-21 21:14:36 +01:00
|
|
|
|
|
|
|
output(msg);
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
|
2005-06-27 11:57:28 +02:00
|
|
|
static void usage(void)
|
2003-01-21 21:14:36 +01:00
|
|
|
{
|
|
|
|
fatal_string(STRING_USAGE);
|
|
|
|
}
|
|
|
|
|
2007-12-11 21:14:13 +01:00
|
|
|
static WCHAR *build_args( int argc, WCHAR **argvW )
|
2005-11-10 12:06:15 +01:00
|
|
|
{
|
2007-12-11 21:14:13 +01:00
|
|
|
int i, wlen = 1;
|
|
|
|
WCHAR *ret, *p;
|
2005-11-10 12:06:15 +01:00
|
|
|
|
|
|
|
for (i = 0; i < argc; i++ )
|
2007-07-10 23:47:02 +02:00
|
|
|
{
|
2019-05-01 10:40:12 +02:00
|
|
|
wlen += lstrlenW(argvW[i]) + 1;
|
|
|
|
if (wcschr(argvW[i], ' '))
|
2007-12-11 21:14:13 +01:00
|
|
|
wlen += 2;
|
2007-07-10 23:47:02 +02:00
|
|
|
}
|
2007-12-11 21:14:13 +01:00
|
|
|
ret = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
|
2006-02-01 13:50:52 +01:00
|
|
|
ret[0] = 0;
|
2005-11-10 12:06:15 +01:00
|
|
|
|
|
|
|
for (i = 0, p = ret; i < argc; i++ )
|
2007-07-10 23:47:02 +02:00
|
|
|
{
|
2019-05-01 10:40:12 +02:00
|
|
|
if (wcschr(argvW[i], ' '))
|
2020-11-12 00:37:56 +01:00
|
|
|
p += swprintf(p, wlen - (p - ret), L" \"%s\"", argvW[i]);
|
2007-07-10 23:47:02 +02:00
|
|
|
else
|
2020-11-12 00:37:56 +01:00
|
|
|
p += swprintf(p, wlen - (p - ret), L" %s", argvW[i]);
|
2007-07-10 23:47:02 +02:00
|
|
|
}
|
2005-11-10 12:06:15 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-13 02:30:42 +02:00
|
|
|
static WCHAR *get_parent_dir(WCHAR* path)
|
|
|
|
{
|
|
|
|
WCHAR *last_slash;
|
|
|
|
WCHAR *result;
|
|
|
|
int len;
|
|
|
|
|
2019-05-01 10:40:12 +02:00
|
|
|
last_slash = wcsrchr( path, '\\' );
|
2008-04-13 02:30:42 +02:00
|
|
|
if (last_slash == NULL)
|
|
|
|
len = 1;
|
|
|
|
else
|
|
|
|
len = last_slash - path + 1;
|
|
|
|
|
|
|
|
result = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
CopyMemory(result, path, (len-1)*sizeof(WCHAR));
|
|
|
|
result[len-1] = '\0';
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-06-27 09:19:58 +02:00
|
|
|
static BOOL is_option(const WCHAR* arg, const WCHAR* opt)
|
|
|
|
{
|
|
|
|
return CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
|
|
|
|
arg, -1, opt, -1) == CSTR_EQUAL;
|
|
|
|
}
|
|
|
|
|
2019-08-11 16:28:26 +02:00
|
|
|
static void parse_title(const WCHAR *arg, WCHAR *title, int size)
|
|
|
|
{
|
|
|
|
/* See:
|
|
|
|
* WCMD_start() in programs/cmd/builtins.c
|
|
|
|
* WCMD_parameter_with_delims() in programs/cmd/batch.c
|
|
|
|
* The shell has already tokenized the command line for us.
|
|
|
|
* All we need to do is filter out all the quotes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int next;
|
|
|
|
const WCHAR *p = arg;
|
|
|
|
|
|
|
|
for (next = 0; next < (size-1) && *p; p++) {
|
|
|
|
if (*p != '"')
|
|
|
|
title[next++] = *p;
|
|
|
|
}
|
|
|
|
title[next] = '\0';
|
|
|
|
}
|
|
|
|
|
2019-08-11 16:28:50 +02:00
|
|
|
static BOOL search_path(const WCHAR *firstParam, WCHAR **full_path)
|
|
|
|
{
|
|
|
|
/* Copied from WCMD_run_program() in programs/cmd/wcmdmain.c */
|
|
|
|
|
|
|
|
#define MAXSTRING 8192
|
|
|
|
|
|
|
|
WCHAR temp[MAX_PATH];
|
|
|
|
WCHAR pathtosearch[MAXSTRING];
|
|
|
|
WCHAR *pathposn;
|
|
|
|
WCHAR stemofsearch[MAX_PATH]; /* maximum allowed executable name is
|
|
|
|
MAX_PATH, including null character */
|
|
|
|
WCHAR *lastSlash;
|
|
|
|
WCHAR pathext[MAXSTRING];
|
|
|
|
BOOL extensionsupplied = FALSE;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
/* Calculate the search path and stem to search for */
|
2020-11-12 00:37:56 +01:00
|
|
|
if (wcspbrk (firstParam, L"/\\:") == NULL) { /* No explicit path given, search path */
|
|
|
|
lstrcpyW(pathtosearch, L".;");
|
|
|
|
len = GetEnvironmentVariableW(L"PATH", &pathtosearch[2], ARRAY_SIZE(pathtosearch)-2);
|
2019-08-11 16:28:50 +02:00
|
|
|
if ((len == 0) || (len >= ARRAY_SIZE(pathtosearch) - 2)) {
|
2020-11-12 00:37:56 +01:00
|
|
|
lstrcpyW (pathtosearch, L".");
|
2019-08-11 16:28:50 +02:00
|
|
|
}
|
|
|
|
if (wcschr(firstParam, '.') != NULL) extensionsupplied = TRUE;
|
|
|
|
if (lstrlenW(firstParam) >= MAX_PATH) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW(stemofsearch, firstParam);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Convert eg. ..\fred to include a directory by removing file part */
|
|
|
|
GetFullPathNameW(firstParam, ARRAY_SIZE(pathtosearch), pathtosearch, NULL);
|
|
|
|
lastSlash = wcsrchr(pathtosearch, '\\');
|
|
|
|
if (lastSlash && wcschr(lastSlash, '.') != NULL) extensionsupplied = TRUE;
|
|
|
|
lstrcpyW(stemofsearch, lastSlash+1);
|
|
|
|
|
|
|
|
/* Reduce pathtosearch to a path with trailing '\' to support c:\a.bat and
|
|
|
|
c:\windows\a.bat syntax */
|
|
|
|
if (lastSlash) *(lastSlash + 1) = 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now extract PATHEXT */
|
2020-11-12 00:37:56 +01:00
|
|
|
len = GetEnvironmentVariableW(L"PATHEXT", pathext, ARRAY_SIZE(pathext));
|
2019-08-11 16:28:50 +02:00
|
|
|
if ((len == 0) || (len >= ARRAY_SIZE(pathext))) {
|
2020-11-12 00:37:56 +01:00
|
|
|
lstrcpyW (pathext, L".bat;.com;.cmd;.exe");
|
2019-08-11 16:28:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Loop through the search path, dir by dir */
|
|
|
|
pathposn = pathtosearch;
|
|
|
|
WINE_TRACE("Searching in '%s' for '%s'\n", wine_dbgstr_w(pathtosearch),
|
|
|
|
wine_dbgstr_w(stemofsearch));
|
|
|
|
while (pathposn) {
|
|
|
|
WCHAR thisDir[MAX_PATH] = {'\0'};
|
|
|
|
int length = 0;
|
|
|
|
WCHAR *pos = NULL;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
BOOL inside_quotes = FALSE;
|
|
|
|
|
|
|
|
/* Work on the first directory on the search path */
|
|
|
|
pos = pathposn;
|
|
|
|
while ((inside_quotes || *pos != ';') && *pos != 0)
|
|
|
|
{
|
|
|
|
if (*pos == '"')
|
|
|
|
inside_quotes = !inside_quotes;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*pos) { /* Reached semicolon */
|
|
|
|
memcpy(thisDir, pathposn, (pos-pathposn) * sizeof(WCHAR));
|
|
|
|
thisDir[(pos-pathposn)] = 0x00;
|
|
|
|
pathposn = pos+1;
|
|
|
|
} else { /* Reached string end */
|
|
|
|
lstrcpyW(thisDir, pathposn);
|
|
|
|
pathposn = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove quotes */
|
|
|
|
length = lstrlenW(thisDir);
|
|
|
|
if (thisDir[length - 1] == '"')
|
|
|
|
thisDir[length - 1] = 0;
|
|
|
|
|
|
|
|
if (*thisDir != '"')
|
|
|
|
lstrcpyW(temp, thisDir);
|
|
|
|
else
|
|
|
|
lstrcpyW(temp, thisDir + 1);
|
|
|
|
|
|
|
|
/* Since you can have eg. ..\.. on the path, need to expand
|
|
|
|
to full information */
|
|
|
|
GetFullPathNameW(temp, MAX_PATH, thisDir, NULL);
|
|
|
|
|
|
|
|
/* 1. If extension supplied, see if that file exists */
|
2020-11-12 00:37:56 +01:00
|
|
|
lstrcatW(thisDir, L"\\");
|
2019-08-11 16:28:50 +02:00
|
|
|
lstrcatW(thisDir, stemofsearch);
|
|
|
|
pos = &thisDir[lstrlenW(thisDir)]; /* Pos = end of name */
|
|
|
|
|
|
|
|
/* 1. If extension supplied, see if that file exists */
|
|
|
|
if (extensionsupplied) {
|
|
|
|
if (GetFileAttributesW(thisDir) != INVALID_FILE_ATTRIBUTES) {
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 2. Any .* matches? */
|
|
|
|
if (!found) {
|
|
|
|
HANDLE h;
|
|
|
|
WIN32_FIND_DATAW finddata;
|
|
|
|
|
2020-11-12 00:37:56 +01:00
|
|
|
lstrcatW(thisDir, L".*");
|
2019-08-11 16:28:50 +02:00
|
|
|
h = FindFirstFileW(thisDir, &finddata);
|
|
|
|
FindClose(h);
|
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
|
|
|
|
WCHAR *thisExt = pathext;
|
|
|
|
|
|
|
|
/* 3. Yes - Try each path ext */
|
|
|
|
while (thisExt) {
|
|
|
|
WCHAR *nextExt = wcschr(thisExt, ';');
|
|
|
|
|
|
|
|
if (nextExt) {
|
|
|
|
memcpy(pos, thisExt, (nextExt-thisExt) * sizeof(WCHAR));
|
|
|
|
pos[(nextExt-thisExt)] = 0x00;
|
|
|
|
thisExt = nextExt+1;
|
|
|
|
} else {
|
|
|
|
lstrcpyW(pos, thisExt);
|
|
|
|
thisExt = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetFileAttributesW(thisDir) != INVALID_FILE_ATTRIBUTES) {
|
|
|
|
found = TRUE;
|
|
|
|
thisExt = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
int needed_size = lstrlenW(thisDir) + 1;
|
|
|
|
*full_path = HeapAlloc(GetProcessHeap(), 0, needed_size * sizeof(WCHAR));
|
|
|
|
if (*full_path)
|
|
|
|
lstrcpyW(*full_path, thisDir);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-10-17 17:05:47 +02:00
|
|
|
int __cdecl wmain (int argc, WCHAR *argv[])
|
2003-01-21 21:14:36 +01:00
|
|
|
{
|
2007-12-11 21:14:13 +01:00
|
|
|
SHELLEXECUTEINFOW sei;
|
2012-06-27 09:19:58 +02:00
|
|
|
DWORD creation_flags;
|
2007-12-11 21:14:13 +01:00
|
|
|
WCHAR *args = NULL;
|
2005-11-10 12:06:15 +01:00
|
|
|
int i;
|
2014-02-27 15:33:27 +01:00
|
|
|
BOOL unix_mode = FALSE;
|
|
|
|
BOOL progid_open = FALSE;
|
2012-06-27 09:19:58 +02:00
|
|
|
WCHAR *title = NULL;
|
2019-08-11 16:28:50 +02:00
|
|
|
const WCHAR *file;
|
2008-04-13 02:30:42 +02:00
|
|
|
WCHAR *dos_filename = NULL;
|
2019-08-11 16:28:50 +02:00
|
|
|
WCHAR *fullpath = NULL;
|
2008-04-13 02:30:42 +02:00
|
|
|
WCHAR *parent_directory = NULL;
|
|
|
|
DWORD binary_type;
|
2003-01-21 21:14:36 +01:00
|
|
|
|
|
|
|
memset(&sei, 0, sizeof(sei));
|
|
|
|
sei.cbSize = sizeof(sei);
|
2020-11-12 00:37:56 +01:00
|
|
|
sei.lpVerb = L"open";
|
2003-01-21 21:14:36 +01:00
|
|
|
sei.nShow = SW_SHOWNORMAL;
|
|
|
|
/* Dunno what these mean, but it looks like winMe's start uses them */
|
2007-07-16 17:19:06 +02:00
|
|
|
sei.fMask = SEE_MASK_FLAG_DDEWAIT|
|
2014-04-22 19:47:29 +02:00
|
|
|
SEE_MASK_FLAG_NO_UI;
|
2012-06-27 09:19:58 +02:00
|
|
|
sei.lpDirectory = NULL;
|
|
|
|
creation_flags = CREATE_NEW_CONSOLE;
|
2003-01-21 21:14:36 +01:00
|
|
|
|
|
|
|
/* Canonical Microsoft commandline flag processing:
|
2012-06-27 09:19:58 +02:00
|
|
|
* flags start with / and are case insensitive.
|
2003-01-21 21:14:36 +01:00
|
|
|
*/
|
2005-11-10 12:06:15 +01:00
|
|
|
for (i=1; i<argc; i++) {
|
2017-03-20 18:14:19 +01:00
|
|
|
/* parse first quoted argument as console title */
|
|
|
|
if (!title && argv[i][0] == '"') {
|
2019-08-11 16:28:26 +02:00
|
|
|
/* it will remove at least 1 quote */
|
|
|
|
int maxChars = lstrlenW(argv[1]);
|
|
|
|
title = HeapAlloc(GetProcessHeap(), 0, maxChars*sizeof(WCHAR));
|
|
|
|
if (title)
|
|
|
|
parse_title(argv[i], title, maxChars);
|
|
|
|
else {
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
2012-06-27 09:19:58 +02:00
|
|
|
continue;
|
|
|
|
}
|
2005-11-10 12:06:15 +01:00
|
|
|
if (argv[i][0] != '/')
|
2003-01-21 21:14:36 +01:00
|
|
|
break;
|
|
|
|
|
2012-06-27 09:19:58 +02:00
|
|
|
/* Unix paths can start with / so we have to assume anything following /unix is not a flag */
|
2009-06-10 21:11:48 +02:00
|
|
|
if (unix_mode || progid_open)
|
2008-04-13 02:30:42 +02:00
|
|
|
break;
|
|
|
|
|
2012-06-27 09:19:58 +02:00
|
|
|
if (argv[i][0] == '/' && (argv[i][1] == 'd' || argv[i][1] == 'D')) {
|
|
|
|
if (argv[i][2])
|
|
|
|
/* The start directory was concatenated to the option */
|
|
|
|
sei.lpDirectory = argv[i]+2;
|
|
|
|
else if (i+1 == argc) {
|
|
|
|
WINE_ERR("you must specify a directory path for the /d option\n");
|
2011-07-11 14:33:37 +02:00
|
|
|
usage();
|
2012-06-27 09:19:58 +02:00
|
|
|
} else
|
|
|
|
sei.lpDirectory = argv[++i];
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/b")) {
|
2012-11-07 23:18:57 +01:00
|
|
|
creation_flags &= ~CREATE_NEW_CONSOLE;
|
2012-06-27 09:19:58 +02:00
|
|
|
}
|
|
|
|
else if (argv[i][0] == '/' && (argv[i][1] == 'i' || argv[i][1] == 'I')) {
|
|
|
|
TRACE("/i is ignored\n"); /* FIXME */
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/min")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
sei.nShow = SW_SHOWMINIMIZED;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/max")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
sei.nShow = SW_SHOWMAXIMIZED;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/low")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
creation_flags |= IDLE_PRIORITY_CLASS;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/normal")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
creation_flags |= NORMAL_PRIORITY_CLASS;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/high")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
creation_flags |= HIGH_PRIORITY_CLASS;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/realtime")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
creation_flags |= REALTIME_PRIORITY_CLASS;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/abovenormal")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
creation_flags |= ABOVE_NORMAL_PRIORITY_CLASS;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/belownormal")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
creation_flags |= BELOW_NORMAL_PRIORITY_CLASS;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/separate")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
TRACE("/separate is ignored\n"); /* FIXME */
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/shared")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
TRACE("/shared is ignored\n"); /* FIXME */
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/node")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
if (i+1 == argc) {
|
|
|
|
WINE_ERR("you must specify a numa node for the /node option\n");
|
2003-01-21 21:14:36 +01:00
|
|
|
usage();
|
2012-06-27 09:19:58 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
TRACE("/node is ignored\n"); /* FIXME */
|
|
|
|
i++;
|
2003-01-21 21:14:36 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/affinity"))
|
2012-06-27 09:19:58 +02:00
|
|
|
{
|
|
|
|
if (i+1 == argc) {
|
|
|
|
WINE_ERR("you must specify a numa node for the /node option\n");
|
|
|
|
usage();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
TRACE("/affinity is ignored\n"); /* FIXME */
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/w") || is_option(argv[i], L"/wait")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
sei.fMask |= SEE_MASK_NOCLOSEPROCESS;
|
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/?")) {
|
2012-06-27 09:19:58 +02:00
|
|
|
usage();
|
|
|
|
}
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2012-06-27 09:19:58 +02:00
|
|
|
/* Wine extensions */
|
|
|
|
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/unix")) {
|
2014-02-27 15:33:27 +01:00
|
|
|
unix_mode = TRUE;
|
2012-06-27 09:19:58 +02:00
|
|
|
}
|
2020-11-12 00:37:56 +01:00
|
|
|
else if (is_option(argv[i], L"/progIDOpen")) {
|
2014-02-27 15:33:27 +01:00
|
|
|
progid_open = TRUE;
|
2012-06-27 09:19:58 +02:00
|
|
|
} else
|
|
|
|
|
|
|
|
{
|
|
|
|
WINE_ERR("Unknown option '%s'\n", wine_dbgstr_w(argv[i]));
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2009-06-10 21:11:48 +02:00
|
|
|
if (progid_open) {
|
2012-06-27 09:19:58 +02:00
|
|
|
if (i == argc)
|
|
|
|
usage();
|
2009-06-10 21:11:48 +02:00
|
|
|
sei.lpClass = argv[i++];
|
|
|
|
sei.fMask |= SEE_MASK_CLASSNAME;
|
|
|
|
}
|
|
|
|
|
2012-06-27 09:19:58 +02:00
|
|
|
if (i == argc) {
|
|
|
|
if (progid_open || unix_mode)
|
|
|
|
usage();
|
2020-11-12 00:37:56 +01:00
|
|
|
file = L"cmd.exe";
|
2012-06-27 09:19:58 +02:00
|
|
|
}
|
|
|
|
else
|
2019-08-11 16:28:50 +02:00
|
|
|
file = argv[i++];
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2005-11-10 12:06:15 +01:00
|
|
|
args = build_args( argc - i, &argv[i] );
|
|
|
|
sei.lpParameters = args;
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2009-06-10 21:11:48 +02:00
|
|
|
if (unix_mode || progid_open) {
|
2008-12-16 16:16:10 +01:00
|
|
|
LPWSTR (*CDECL wine_get_dos_file_name_ptr)(LPCSTR);
|
2008-04-13 02:30:42 +02:00
|
|
|
char* multibyte_unixpath;
|
|
|
|
int multibyte_unixpath_len;
|
|
|
|
|
2008-09-03 11:30:44 +02:00
|
|
|
wine_get_dos_file_name_ptr = (void*)GetProcAddress(GetModuleHandleA("KERNEL32"), "wine_get_dos_file_name");
|
2008-04-13 02:30:42 +02:00
|
|
|
|
|
|
|
if (!wine_get_dos_file_name_ptr)
|
|
|
|
fatal_string(STRING_UNIXFAIL);
|
|
|
|
|
2019-08-11 16:28:50 +02:00
|
|
|
multibyte_unixpath_len = WideCharToMultiByte(CP_UNIXCP, 0, file, -1, NULL, 0, NULL, NULL);
|
2008-04-13 02:30:42 +02:00
|
|
|
multibyte_unixpath = HeapAlloc(GetProcessHeap(), 0, multibyte_unixpath_len);
|
|
|
|
|
2019-08-11 16:28:50 +02:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, file, -1, multibyte_unixpath, multibyte_unixpath_len, NULL, NULL);
|
2008-04-13 02:30:42 +02:00
|
|
|
|
|
|
|
dos_filename = wine_get_dos_file_name_ptr(multibyte_unixpath);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, multibyte_unixpath);
|
|
|
|
|
|
|
|
if (!dos_filename)
|
|
|
|
fatal_string(STRING_UNIXFAIL);
|
|
|
|
|
|
|
|
sei.lpFile = dos_filename;
|
2012-06-27 09:19:58 +02:00
|
|
|
if (!sei.lpDirectory)
|
|
|
|
sei.lpDirectory = parent_directory = get_parent_dir(dos_filename);
|
2009-01-03 01:25:13 +01:00
|
|
|
sei.fMask &= ~SEE_MASK_FLAG_NO_UI;
|
2019-08-11 16:28:50 +02:00
|
|
|
} else {
|
|
|
|
if (search_path(file, &fullpath)) {
|
|
|
|
if (fullpath != NULL) {
|
|
|
|
sei.lpFile = fullpath;
|
|
|
|
} else {
|
|
|
|
fatal_string_error(STRING_EXECFAIL, ERROR_OUTOFMEMORY, file);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sei.lpFile = file;
|
|
|
|
}
|
2019-08-11 16:28:45 +02:00
|
|
|
}
|
2008-04-13 02:30:42 +02:00
|
|
|
|
2019-08-11 16:28:45 +02:00
|
|
|
if (GetBinaryTypeW(sei.lpFile, &binary_type)) {
|
2008-04-13 02:30:42 +02:00
|
|
|
WCHAR *commandline;
|
|
|
|
STARTUPINFOW startup_info;
|
|
|
|
PROCESS_INFORMATION process_information;
|
|
|
|
|
|
|
|
/* explorer on windows always quotes the filename when running a binary on windows (see bug 5224) so we have to use CreateProcessW in this case */
|
|
|
|
|
2019-05-01 10:40:12 +02:00
|
|
|
commandline = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(sei.lpFile)+3+lstrlenW(sei.lpParameters))*sizeof(WCHAR));
|
|
|
|
swprintf(commandline, lstrlenW(sei.lpFile) + 3 + lstrlenW(sei.lpParameters),
|
2020-11-12 00:37:56 +01:00
|
|
|
L"\"%s\"%s", sei.lpFile, sei.lpParameters);
|
2008-04-13 02:30:42 +02:00
|
|
|
|
|
|
|
ZeroMemory(&startup_info, sizeof(startup_info));
|
|
|
|
startup_info.cb = sizeof(startup_info);
|
2019-08-11 16:28:37 +02:00
|
|
|
startup_info.wShowWindow = sei.nShow;
|
2019-11-26 03:28:54 +01:00
|
|
|
startup_info.dwFlags |= STARTF_USESHOWWINDOW;
|
2012-06-27 09:19:58 +02:00
|
|
|
startup_info.lpTitle = title;
|
2008-04-13 02:30:42 +02:00
|
|
|
|
|
|
|
if (!CreateProcessW(
|
2019-08-11 16:28:50 +02:00
|
|
|
sei.lpFile, /* lpApplicationName */
|
2008-04-13 02:30:42 +02:00
|
|
|
commandline, /* lpCommandLine */
|
|
|
|
NULL, /* lpProcessAttributes */
|
|
|
|
NULL, /* lpThreadAttributes */
|
|
|
|
FALSE, /* bInheritHandles */
|
2012-06-27 09:19:58 +02:00
|
|
|
creation_flags, /* dwCreationFlags */
|
2008-04-13 02:30:42 +02:00
|
|
|
NULL, /* lpEnvironment */
|
|
|
|
sei.lpDirectory, /* lpCurrentDirectory */
|
|
|
|
&startup_info, /* lpStartupInfo */
|
|
|
|
&process_information /* lpProcessInformation */ ))
|
|
|
|
{
|
2010-03-29 12:26:55 +02:00
|
|
|
fatal_string_error(STRING_EXECFAIL, GetLastError(), sei.lpFile);
|
2008-04-13 02:30:42 +02:00
|
|
|
}
|
|
|
|
sei.hProcess = process_information.hProcess;
|
2008-05-29 12:12:12 +02:00
|
|
|
goto done;
|
2019-08-11 16:28:45 +02:00
|
|
|
}
|
2003-01-21 21:14:36 +01:00
|
|
|
|
2008-05-29 12:12:12 +02:00
|
|
|
if (!ShellExecuteExW(&sei))
|
2018-10-24 13:32:14 +02:00
|
|
|
{
|
|
|
|
const WCHAR *filename = sei.lpFile;
|
|
|
|
DWORD size, filename_len;
|
|
|
|
WCHAR *name, *env;
|
|
|
|
|
2020-11-12 00:37:56 +01:00
|
|
|
size = GetEnvironmentVariableW(L"PATHEXT", NULL, 0);
|
2018-10-24 13:32:14 +02:00
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
WCHAR *start, *ptr;
|
|
|
|
|
|
|
|
env = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (!env)
|
|
|
|
fatal_string_error(STRING_EXECFAIL, ERROR_OUTOFMEMORY, sei.lpFile);
|
2020-11-12 00:37:56 +01:00
|
|
|
GetEnvironmentVariableW(L"PATHEXT", env, size);
|
2018-10-24 13:32:14 +02:00
|
|
|
|
2019-05-01 10:40:12 +02:00
|
|
|
filename_len = lstrlenW(filename);
|
2018-10-24 13:32:14 +02:00
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, (filename_len + size) * sizeof(WCHAR));
|
|
|
|
if (!name)
|
|
|
|
fatal_string_error(STRING_EXECFAIL, ERROR_OUTOFMEMORY, sei.lpFile);
|
|
|
|
|
|
|
|
sei.lpFile = name;
|
|
|
|
start = env;
|
2019-05-01 10:40:12 +02:00
|
|
|
while ((ptr = wcschr(start, ';')))
|
2018-10-24 13:32:14 +02:00
|
|
|
{
|
|
|
|
if (start == ptr)
|
|
|
|
{
|
|
|
|
start = ptr + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-01 10:40:12 +02:00
|
|
|
lstrcpyW(name, filename);
|
2018-10-24 13:32:14 +02:00
|
|
|
memcpy(&name[filename_len], start, (ptr - start) * sizeof(WCHAR));
|
|
|
|
name[filename_len + (ptr - start)] = 0;
|
|
|
|
|
|
|
|
if (ShellExecuteExW(&sei))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, env);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = ptr + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fatal_string_error(STRING_EXECFAIL, GetLastError(), filename);
|
|
|
|
}
|
2008-05-29 12:12:12 +02:00
|
|
|
|
|
|
|
done:
|
2005-11-10 12:06:15 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, args );
|
2008-04-13 02:30:42 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, dos_filename );
|
2019-08-11 16:28:50 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, fullpath );
|
2008-04-13 02:30:42 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, parent_directory );
|
2019-08-11 16:28:26 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, title );
|
2005-11-10 12:06:15 +01:00
|
|
|
|
2003-01-21 21:14:36 +01:00
|
|
|
if (sei.fMask & SEE_MASK_NOCLOSEPROCESS) {
|
|
|
|
DWORD exitcode;
|
2007-12-11 21:14:13 +01:00
|
|
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
|
GetExitCodeProcess(sei.hProcess, &exitcode);
|
2003-01-21 21:14:36 +01:00
|
|
|
ExitProcess(exitcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitProcess(0);
|
|
|
|
}
|