https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0d4591c6722361a1778d4…
commit 0d4591c6722361a1778d4284306462df54f60925
Author:     Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Mon Nov 5 00:22:30 2018 +0100
Commit:     Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Mon Nov 5 00:24:16 2018 +0100
    [SCHEDSVC] Start jobs on timeout
    - Start jobs on timeout
    - Add job flags to the idl file
---
 base/services/schedsvc/job.c      | 45 ++++++++++++++++++++++-----------------
 base/services/schedsvc/precomp.h  |  2 ++
 sdk/include/reactos/idl/atsvc.idl |  8 +++++++
 3 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/base/services/schedsvc/job.c b/base/services/schedsvc/job.c
index 0d6a29ea6a..e1a8f013b2 100644
--- a/base/services/schedsvc/job.c
+++ b/base/services/schedsvc/job.c
@@ -91,8 +91,8 @@ ReScheduleJob(
     /* Remove the job from the start list */
     RemoveEntryList(&pJob->StartEntry);
-    /* No repetition, remove the job */
-    if (pJob->DaysOfMonth == 0 && pJob->DaysOfWeek == 0)
+    /* Non-periodical job, remove it */
+    if ((pJob->Flags & JOB_RUN_PERIODICALLY) == 0)
     {
         /* Remove the job from the registry */
         DeleteJob(pJob);
@@ -120,12 +120,9 @@ ReScheduleJob(
 VOID
 RunNextJob(VOID)
 {
-#if 0
     PROCESS_INFORMATION ProcessInformation;
     STARTUPINFOW StartupInfo;
-    WCHAR CommandLine[256];
     BOOL bRet;
-#endif
     PJOB pNextJob;
     if (IsListEmpty(&StartListHead))
@@ -136,29 +133,39 @@ RunNextJob(VOID)
     pNextJob = CONTAINING_RECORD((&StartListHead)->Flink, JOB, StartEntry);
-    ERR("Run job %ld: %S\n", pNextJob->JobId, pNextJob->Command);
+    TRACE("Run job %ld: %S\n", pNextJob->JobId, pNextJob->Command);
-#if 0
-    bRet = CreateProcess(NULL,
-                         CommandLine,
-                         NULL,
-                         NULL,
-                         FALSE,
-                         CREATE_NEW_CONSOLE | CREATE_SEPARATE_WOW_VDM,
-                         NULL,
-                         NULL,
-                         &StartupInfo,
-                         &ProcessInformation);
+    ZeroMemory(&StartupInfo, sizeof(StartupInfo));
+    StartupInfo.cb = sizeof(StartupInfo);
+    StartupInfo.lpTitle = pNextJob->Command;
+    StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
+    StartupInfo.wShowWindow = SW_SHOWDEFAULT;
+
+    if ((pNextJob->Flags & JOB_NONINTERACTIVE) == 0)
+    {
+        StartupInfo.dwFlags |= STARTF_INHERITDESKTOP;
+        StartupInfo.lpDesktop = L"WinSta0\\Default";
+    }
+
+    bRet = CreateProcessW(NULL,
+                          pNextJob->Command,
+                          NULL,
+                          NULL,
+                          FALSE,
+                          CREATE_NEW_CONSOLE,
+                          NULL,
+                          NULL,
+                          &StartupInfo,
+                          &ProcessInformation);
     if (bRet == FALSE)
     {
-        // FIXME: Log the failure!
+        ERR("CreateProcessW() failed (Error %lu)\n", GetLastError());
     }
     else
     {
         CloseHandle(ProcessInformation.hThread);
         CloseHandle(ProcessInformation.hProcess);
     }
-#endif
     ReScheduleJob(pNextJob);
 }
diff --git a/base/services/schedsvc/precomp.h b/base/services/schedsvc/precomp.h
index 8fc590ba7f..992e16796d 100644
--- a/base/services/schedsvc/precomp.h
+++ b/base/services/schedsvc/precomp.h
@@ -11,6 +11,8 @@
 #include <winbase.h>
 #include <winreg.h>
 #include <winsvc.h>
+#include <winuser.h>
+#include <undocuser.h>
 #include <ndk/rtlfuncs.h>
diff --git a/sdk/include/reactos/idl/atsvc.idl b/sdk/include/reactos/idl/atsvc.idl
index b91dbfcc86..7dc6dc6cd0 100644
--- a/sdk/include/reactos/idl/atsvc.idl
+++ b/sdk/include/reactos/idl/atsvc.idl
@@ -31,6 +31,14 @@ typedef struct _AT_ENUM_CONTAINER
     [size_is( EntriesRead)] LPAT_ENUM Buffer;
 } AT_ENUM_CONTAINER, *PAT_ENUM_CONTAINER, *LPAT_ENUM_CONTAINER;
+cpp_quote("#define JOB_RUN_PERIODICALLY  1")
+cpp_quote("#define JOB_EXEC_ERROR        2")
+cpp_quote("#define JOB_RUNS_TODAY        4")
+cpp_quote("#define JOB_ADD_CURRENT_DATE  8")
+cpp_quote("#define JOB_NONINTERACTIVE   16")
+cpp_quote("#define JOB_INPUT_FLAGS
(JOB_RUN_PERIODICALLY|JOB_ADD_CURRENT_DATE|JOB_NONINTERACTIVE)")
+cpp_quote("#define JOB_OUTPUT_FLAGS
(JOB_RUN_PERIODICALLY|JOB_EXEC_ERROR|JOB_RUNS_TODAY|JOB_NONINTERACTIVE)")
+
 [
     uuid(1FF70682-0A51-30E8-076D-740BE8CEE98B),
     version(1.0),