* Sync with recent trunk (r52637).
[reactos.git] / base / system / smss / initrun.c
1 /*
2 * PROJECT: ReactOS Session Manager
3 * LICENSE: GPL v2 or later - See COPYING in the top level directory
4 * FILE: base/system/smss/initrun.c
5 * PURPOSE: Run all programs in the boot execution list.
6 * PROGRAMMERS: ReactOS Development Team
7 */
8
9 /* INCLUDES ******************************************************************/
10 #include "smss.h"
11
12 #define NDEBUG
13 #include <debug.h>
14
15 //HANDLE Children[2] = {0, 0}; /* csrss, winlogon */
16
17
18 /**********************************************************************
19 * SmpRunBootAppsQueryRoutine/6
20 */
21 static NTSTATUS NTAPI
22 SmpRunBootAppsQueryRoutine(PWSTR ValueName,
23 ULONG ValueType,
24 PVOID ValueData,
25 ULONG ValueLength,
26 PVOID Context,
27 PVOID EntryContext)
28 {
29 WCHAR Description [MAX_PATH];
30 WCHAR ImageName [MAX_PATH];
31 WCHAR ImagePath [MAX_PATH];
32 WCHAR CommandLine [MAX_PATH];
33 PWSTR p1, p2;
34 ULONG len;
35 NTSTATUS Status;
36
37 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
38 DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
39
40 if (ValueType != REG_SZ)
41 {
42 return(STATUS_SUCCESS);
43 }
44
45 /* Extract the description */
46 p1 = wcschr((PWSTR)ValueData, L' ');
47 len = p1 - (PWSTR)ValueData;
48 memcpy(Description,ValueData, len * sizeof(WCHAR));
49 Description[len] = 0;
50
51 /* Extract the image name */
52 p1++;
53 p2 = wcschr(p1, L' ');
54 if (p2 != NULL)
55 len = p2 - p1;
56 else
57 len = wcslen(p1);
58 memcpy(ImageName, p1, len * sizeof(WCHAR));
59 ImageName[len] = 0;
60
61 /* Extract the command line */
62 if (p2 == NULL)
63 {
64 CommandLine[0] = 0;
65 }
66 else
67 {
68 p2++;
69 wcscpy(CommandLine, p2);
70 }
71
72 DPRINT("Running %S...\n", Description);
73 DPRINT("ImageName: '%S'\n", ImageName);
74 DPRINT("CommandLine: '%S'\n", CommandLine);
75
76 /* initialize executable path */
77 wcscpy(ImagePath, L"\\SystemRoot\\system32\\");
78 wcscat(ImagePath, ImageName);
79 wcscat(ImagePath, L".exe");
80
81 /* Create NT process */
82 Status = SmCreateUserProcess (ImagePath,
83 CommandLine,
84 SM_CREATE_FLAG_WAIT,
85 NULL, NULL);
86 if (!NT_SUCCESS(Status))
87 {
88 DPRINT1("SM: %s: running '%S' failed (Status=0x%08lx)\n",
89 __FUNCTION__, ImagePath, Status);
90 }
91 return(STATUS_SUCCESS);
92 }
93
94
95 /**********************************************************************
96 * SmRunBootApplications/0
97 *
98 * DESCRIPTION
99 *
100 * Run native applications listed in the registry.
101 *
102 * Key:
103 * \Registry\Machine\SYSTEM\CurrentControlSet\Control\Session Manager
104 *
105 * Value (format: "<description> <executable> <command line>":
106 * BootExecute = "autocheck autochk *"
107 */
108 NTSTATUS
109 SmRunBootApplications(VOID)
110 {
111 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
112 NTSTATUS Status;
113
114 RtlZeroMemory(&QueryTable,
115 sizeof(QueryTable));
116
117 QueryTable[0].Name = L"BootExecute";
118 QueryTable[0].QueryRoutine = SmpRunBootAppsQueryRoutine;
119
120 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
121 L"\\Session Manager",
122 QueryTable,
123 NULL,
124 NULL);
125 if (!NT_SUCCESS(Status))
126 {
127 DPRINT1("%s: RtlQueryRegistryValues() failed! (Status %lx)\n",
128 __FUNCTION__,
129 Status);
130 }
131
132 return(Status);
133 }
134
135
136 /* EOF */