eb096462b7e7de0be7f3b7f806235101681e9920
[reactos.git] / reactos / subsys / smss / initrun.c
1 /* $Id: init.c 13449 2005-02-06 21:55:07Z ea $
2 *
3 * initrun.c - Run all programs in the boot execution list
4 *
5 * ReactOS Operating System
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
22 * MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 */
26
27 #include "smss.h"
28
29 //#define NDEBUG
30 #include <debug.h>
31
32 HANDLE Children[2] = {0, 0}; /* csrss, winlogon */
33
34
35 static NTSTATUS STDCALL
36 SmpRunBootAppsQueryRoutine(PWSTR ValueName,
37 ULONG ValueType,
38 PVOID ValueData,
39 ULONG ValueLength,
40 PVOID Context,
41 PVOID EntryContext)
42 {
43 PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
44 RTL_PROCESS_INFO ProcessInfo;
45 UNICODE_STRING ImagePathString;
46 UNICODE_STRING CommandLineString;
47 WCHAR Description[256];
48 WCHAR ImageName[256];
49 WCHAR ImagePath[256];
50 WCHAR CommandLine[256];
51 PWSTR p1, p2;
52 ULONG len;
53 NTSTATUS Status;
54
55 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
56 DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
57
58 if (ValueType != REG_SZ)
59 {
60 return(STATUS_SUCCESS);
61 }
62
63 /* Extract the description */
64 p1 = wcschr((PWSTR)ValueData, L' ');
65 len = p1 - (PWSTR)ValueData;
66 memcpy(Description,ValueData, len * sizeof(WCHAR));
67 Description[len] = 0;
68
69 /* Extract the image name */
70 p1++;
71 p2 = wcschr(p1, L' ');
72 if (p2 != NULL)
73 len = p2 - p1;
74 else
75 len = wcslen(p1);
76 memcpy(ImageName, p1, len * sizeof(WCHAR));
77 ImageName[len] = 0;
78
79 /* Extract the command line */
80 if (p2 == NULL)
81 {
82 CommandLine[0] = 0;
83 }
84 else
85 {
86 p2++;
87 wcscpy(CommandLine, p2);
88 }
89
90 DPRINT("Running %S...\n", Description);
91 DPRINT("ImageName: '%S'\n", ImageName);
92 DPRINT("CommandLine: '%S'\n", CommandLine);
93
94 /* initialize executable path */
95 wcscpy(ImagePath, L"\\SystemRoot\\system32\\");
96 wcscat(ImagePath, ImageName);
97 wcscat(ImagePath, L".exe");
98
99 RtlInitUnicodeString(&ImagePathString,
100 ImagePath);
101
102 RtlInitUnicodeString(&CommandLineString,
103 CommandLine);
104
105 RtlCreateProcessParameters(&ProcessParameters,
106 &ImagePathString,
107 NULL,
108 NULL,
109 &CommandLineString,
110 NULL,
111 NULL,
112 NULL,
113 NULL,
114 NULL);
115
116 Status = RtlCreateUserProcess(&ImagePathString,
117 OBJ_CASE_INSENSITIVE,
118 ProcessParameters,
119 NULL,
120 NULL,
121 NULL,
122 FALSE,
123 NULL,
124 NULL,
125 &ProcessInfo);
126 if (!NT_SUCCESS(Status))
127 {
128 DPRINT1("Running %s failed (Status %lx)\n", Description, Status);
129 return(STATUS_SUCCESS);
130 }
131
132 RtlDestroyProcessParameters(ProcessParameters);
133
134 /* Wait for process termination */
135 NtWaitForSingleObject(ProcessInfo.ProcessHandle,
136 FALSE,
137 NULL);
138
139 NtClose(ProcessInfo.ThreadHandle);
140 NtClose(ProcessInfo.ProcessHandle);
141
142 return(STATUS_SUCCESS);
143 }
144
145
146 /*
147 * Run native applications listed in the registry.
148 *
149 * Key:
150 * \Registry\Machine\SYSTEM\CurrentControlSet\Control\Session Manager
151 *
152 * Value (format: "<description> <executable> <command line>":
153 * BootExecute = "autocheck autochk *"
154 */
155 NTSTATUS
156 SmRunBootApplications(VOID)
157 {
158 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
159 NTSTATUS Status;
160
161 RtlZeroMemory(&QueryTable,
162 sizeof(QueryTable));
163
164 QueryTable[0].Name = L"BootExecute";
165 QueryTable[0].QueryRoutine = SmpRunBootAppsQueryRoutine;
166
167 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
168 L"\\Session Manager",
169 QueryTable,
170 NULL,
171 NULL);
172 if (!NT_SUCCESS(Status))
173 {
174 DPRINT1("%s: RtlQueryRegistryValues() failed! (Status %lx)\n",
175 __FUNCTION__,
176 Status);
177 }
178
179 return(Status);
180 }
181
182
183 /* EOF */