From: Vijay Kiran Kamuju <infyquest(a)gmail.com> --- programs/schtasks/schtasks.c | 78 +++++++++++++++++++----------- programs/schtasks/tests/schtasks.c | 24 +++++++-- 2 files changed, 69 insertions(+), 33 deletions(-) diff --git a/programs/schtasks/schtasks.c b/programs/schtasks/schtasks.c index 1c6350f925b..7fc94205dac 100644 --- a/programs/schtasks/schtasks.c +++ b/programs/schtasks/schtasks.c @@ -132,7 +132,7 @@ static BSTR read_file_to_bstr(const WCHAR *file_name) return ret; } -static BOOL search_option(WCHAR *option, hash_args inputs[], int icount) +static int search_option(WCHAR *option, hash_args inputs[], int icount) { int i; for (i = 0; i < icount; i++) { @@ -216,9 +216,12 @@ static int change_command(int argc, WCHAR *argv[]) static int create_command(int argc, WCHAR *argv[]) { - hash_args create_args[4] = { {L"/tn", TRUE, FALSE}, + hash_args create_args[7] = { {L"/tn", TRUE, FALSE}, {L"/xml", TRUE, FALSE}, {L"/f", TRUE, TRUE}, + {L"/tr", FALSE, FALSE}, + {L"/sc", FALSE, FALSE}, + {L"/rl", FALSE, FALSE}, {L"/ru", FALSE, FALSE} }; ITaskFolder *root = NULL; LONG flags = TASK_CREATE; @@ -227,7 +230,7 @@ static int create_command(int argc, WCHAR *argv[]) BSTR str, xml; HRESULT hres; - if (!check_args(argc, argv, create_args, 4 )) + if (!check_args(argc, argv, create_args, 7 )) return E_FAIL; if (!create_args[0].value) { @@ -235,35 +238,54 @@ static int create_command(int argc, WCHAR *argv[]) return E_FAIL; } - if (!create_args[1].value) { - ERR("Missing /xml argument\n"); - return E_FAIL; - } - if (create_args[2].enable) flags = TASK_CREATE_OR_UPDATE; - xml = read_file_to_bstr(create_args[1].value); - if (!xml) - return E_FAIL; + if (!create_args[3].value && !create_args[4].value) { + if (!create_args[1].value) { + ERR("Missing /xml argument\n"); + return E_FAIL; + } else { + xml = read_file_to_bstr(create_args[1].value); + if (!xml) + return 1; + + root = get_tasks_root_folder(); + if (!root) { + SysFreeString(xml); + return 1; + } + + V_VT(&empty) = VT_EMPTY; + str = SysAllocString(create_args[0].value); + hres = ITaskFolder_RegisterTask(root, str, xml, flags, empty, empty, + TASK_LOGON_NONE, empty, &task); + + SysFreeString(str); + SysFreeString(xml); + ITaskFolder_Release(root); + if (FAILED(hres)) + return 1; - root = get_tasks_root_folder(); - if (!root) { - SysFreeString(xml); - return 1; + IRegisteredTask_Release(task); + return 0; + } + } else { + if (create_args[1].value) { + ERR("/xml option can only be used with /ru /f /tn\n"); + return E_FAIL; + } + if (!create_args[3].value) { + ERR("Missing /tr argument\n"); + return E_FAIL; + } else { + if (!create_args[4].value) { + ERR("Missing /sc argument\n"); + return E_FAIL; + } + } + return 0; } - - V_VT(&empty) = VT_EMPTY; - str = SysAllocString(create_args[0].value); - hres = ITaskFolder_RegisterTask(root, str, xml, flags, empty, empty, - TASK_LOGON_NONE, empty, &task); - SysFreeString(str); - SysFreeString(xml); - ITaskFolder_Release(root); - if (FAILED(hres)) - return 1; - - IRegisteredTask_Release(task); - return 0; + return E_FAIL; } static int delete_command(int argc, WCHAR *argv[]) diff --git a/programs/schtasks/tests/schtasks.c b/programs/schtasks/tests/schtasks.c index 8323fe5fd86..35900a641f5 100644 --- a/programs/schtasks/tests/schtasks.c +++ b/programs/schtasks/tests/schtasks.c @@ -32,6 +32,7 @@ static ITaskFolder *root; typedef struct _schtask_test { const char *cmd; DWORD expect; + BOOL todo; } schtask_test; static const char xml_a[] = @@ -97,8 +98,9 @@ static BOOL check_win_version(int min_major, int min_minor) } #define is_win10_plus() check_win_version(10, 0) -#define run_command(a, e) _run_command(__LINE__, a, e) -static BOOL _run_command(unsigned line, const char *cmd, DWORD expected) +#define run_command(a, e) _run_command(__LINE__, a, e, FALSE) +#define run_command_todo(a, e) _run_command(__LINE__, a, e, TRUE) +static BOOL _run_command(unsigned line, const char *cmd, DWORD expected, BOOL todo) { STARTUPINFOA si = {sizeof(STARTUPINFOA)}; PROCESS_INFORMATION pi; @@ -128,7 +130,10 @@ static BOOL _run_command(unsigned line, const char *cmd, DWORD expected) CloseHandle(pi.hThread); CloseHandle(pi.hProcess); - ok_(__FILE__,line)(ret == expected, "Expected %lu, got = %lu\n", expected, ret); + if (todo) + todo_wine ok_(__FILE__,line)(ret == expected, "Expected %lu, got = %lu\n", expected, ret); + else + ok_(__FILE__,line)(ret == expected, "Expected %lu, got = %lu\n", expected, ret); return r; } @@ -215,7 +220,10 @@ static void run_command_list(schtask_test *cmdlist, int len) for (i = 0; i < len; i++) { - run_command(cmdlist[i].cmd, cmdlist[i].expect); + if (cmdlist[i].todo) + run_command_todo(cmdlist[i].cmd, cmdlist[i].expect); + else + run_command(cmdlist[i].cmd, cmdlist[i].expect); } } @@ -235,11 +243,17 @@ START_TEST(schtasks) { "/create /xml test.xml /tn wine\\winetest /xml", E_FAIL }, { "/create /xml test.xml /tn wine\\winetest /tn test", E_FAIL }, { "/create /xml test.xml /tn wine\\winetest /xml empty.xml", E_FAIL }, + { "/create /xml test.xml /tn wine\\winetest /tr c:\\windows\\hh.exe", E_FAIL }, { "/change /tn wine\\winetest /enable", 0 }, { "/create /xml test.xml /f /tn wine\\winetest", 0 }, { "/create /xml test.xml /tn wine\\winetest", 1 }, + { "/create /xml test.xml /f /tn wine\\winetest /tr c:\\windows\\hh.exe", E_FAIL }, { "/Delete /f /tn wine\\winetest", 0 }, - { "/create /tn wine\\winetest", E_FAIL } }; + { "/create /tn wine\\winetest", E_FAIL }, + { "/create /tn wine\\winetest /tr c:\\windows\\hh.exe", E_FAIL, FALSE }, + { "/create /tn wine\\winetest /tr c:\\windows\\hh.exe /sc wine", E_FAIL, TRUE }, + { "/create /tn wine\\winetest /tr c:\\windows\\hh.exe /sc daily", 0 }, + { "/DELETE /f /tn wine\\winetest", 0, TRUE } }; static WCHAR wineW[] = L"\\wine"; static WCHAR wine_testW[] = L"\\wine\\test"; DWORD r; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5151