fixed some memory leaks
[reactos.git] / reactos / subsys / smss / initrun.c
1 /* $Id$
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 /**********************************************************************
36 * SmpRunBootAppsQueryRoutine/6
37 */
38 static NTSTATUS STDCALL
39 SmpRunBootAppsQueryRoutine(PWSTR ValueName,
40 ULONG ValueType,
41 PVOID ValueData,
42 ULONG ValueLength,
43 PVOID Context,
44 PVOID EntryContext)
45 {
46 WCHAR Description [MAX_PATH];
47 WCHAR ImageName [MAX_PATH];
48 WCHAR ImagePath [MAX_PATH];
49 WCHAR CommandLine [MAX_PATH];
50 PWSTR p1, p2;
51 ULONG len;
52 NTSTATUS Status;
53
54 DPRINT("ValueName '%S' Type %lu Length %lu\n", ValueName, ValueType, ValueLength);
55 DPRINT("ValueData '%S'\n", (PWSTR)ValueData);
56
57 if (ValueType != REG_SZ)
58 {
59 return(STATUS_SUCCESS);
60 }
61
62 /* Extract the description */
63 p1 = wcschr((PWSTR)ValueData, L' ');
64 len = p1 - (PWSTR)ValueData;
65 memcpy(Description,ValueData, len * sizeof(WCHAR));
66 Description[len] = 0;
67
68 /* Extract the image name */
69 p1++;
70 p2 = wcschr(p1, L' ');
71 if (p2 != NULL)
72 len = p2 - p1;
73 else
74 len = wcslen(p1);
75 memcpy(ImageName, p1, len * sizeof(WCHAR));
76 ImageName[len] = 0;
77
78 /* Extract the command line */
79 if (p2 == NULL)
80 {
81 CommandLine[0] = 0;
82 }
83 else
84 {
85 p2++;
86 wcscpy(CommandLine, p2);
87 }
88
89 DPRINT("Running %S...\n", Description);
90 DPRINT("ImageName: '%S'\n", ImageName);
91 DPRINT("CommandLine: '%S'\n", CommandLine);
92
93 /* initialize executable path */
94 wcscpy(ImagePath, L"\\SystemRoot\\system32\\");
95 wcscat(ImagePath, ImageName);
96 wcscat(ImagePath, L".exe");
97
98 /* Create NT process */
99 Status = SmCreateUserProcess (ImagePath,
100 CommandLine,
101 TRUE, /* wait */
102 NULL, NULL);
103 if (!NT_SUCCESS(Status))
104 {
105 DPRINT1("SM: %s: running '$S' failed (Status=0x%08lx)\n",
106 __FUNCTION__, Status);
107 }
108 return(STATUS_SUCCESS);
109 }
110
111
112 /**********************************************************************
113 * SmRunBootApplications/0
114 *
115 * DESCRIPTION
116 *
117 * Run native applications listed in the registry.
118 *
119 * Key:
120 * \Registry\Machine\SYSTEM\CurrentControlSet\Control\Session Manager
121 *
122 * Value (format: "<description> <executable> <command line>":
123 * BootExecute = "autocheck autochk *"
124 */
125 NTSTATUS
126 SmRunBootApplications(VOID)
127 {
128 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
129 NTSTATUS Status;
130
131 RtlZeroMemory(&QueryTable,
132 sizeof(QueryTable));
133
134 QueryTable[0].Name = L"BootExecute";
135 QueryTable[0].QueryRoutine = SmpRunBootAppsQueryRoutine;
136
137 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
138 L"\\Session Manager",
139 QueryTable,
140 NULL,
141 NULL);
142 if (!NT_SUCCESS(Status))
143 {
144 DPRINT1("%s: RtlQueryRegistryValues() failed! (Status %lx)\n",
145 __FUNCTION__,
146 Status);
147 }
148
149 return(Status);
150 }
151
152
153 /* EOF */