update for HEAD-2003050101
[reactos.git] / subsys / system / winlogon / setup.c
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 2003 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /* $Id$
20  * COPYRIGHT:       See COPYING in the top level directory
21  * PROJECT:         ReactOS winlogon
22  * FILE:            subsys/system/winlogon/setup.h
23  * PURPOSE:         Setup support functions
24  * PROGRAMMER:      Eric Kohl
25  */
26
27 /* INCLUDES *****************************************************************/
28
29 #include <windows.h>
30 #include <stdio.h>
31 #include <lsass/ntsecapi.h>
32 #include <wchar.h>
33
34 #include "setup.h"
35
36 #define NDEBUG
37 #include <debug.h>
38
39
40 /* FUNCTIONS ****************************************************************/
41
42 DWORD
43 GetSetupType(VOID)
44 {
45   DWORD dwError;
46   HANDLE hKey;
47   DWORD dwType;
48   DWORD dwSize;
49   DWORD dwSetupType;
50
51   dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
52                          "SYSTEM\\Setup", //TEXT("SYSTEM\\Setup"),
53                          0,
54                          KEY_QUERY_VALUE,
55                          &hKey);
56   if (dwError != ERROR_SUCCESS)
57     {
58       return 0;
59     }
60
61   dwSize = sizeof(DWORD);
62   dwError = RegQueryValueEx (hKey,
63                              "SetupType", //TEXT("SetupType"),
64                              NULL,
65                              &dwType,
66                              (LPBYTE)&dwSetupType,
67                              &dwSize);
68   RegCloseKey (hKey);
69   if (dwError != ERROR_SUCCESS || dwType != REG_DWORD)
70     {
71       return 0;
72     }
73
74   return dwSetupType;
75 }
76
77
78 BOOL
79 SetSetupType (DWORD dwSetupType)
80 {
81   DWORD dwError;
82   HANDLE hKey;
83
84   dwError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
85                          "SYSTEM\\Setup", //TEXT("SYSTEM\\Setup"),
86                          0,
87                          KEY_QUERY_VALUE,
88                          &hKey);
89   if (dwError != ERROR_SUCCESS)
90     {
91       return FALSE;
92     }
93
94   dwError = RegSetValueEx (hKey,
95                            "SetupType", //TEXT("SetupType"),
96                            0,
97                            REG_DWORD,
98                            (LPBYTE)&dwSetupType,
99                            sizeof(DWORD));
100   RegCloseKey (hKey);
101   if (dwError != ERROR_SUCCESS)
102     {
103       return FALSE;
104     }
105
106   return TRUE;
107 }
108
109
110 BOOL
111 RunSetup (VOID)
112 {
113   PROCESS_INFORMATION ProcessInformation;
114   STARTUPINFO StartupInfo;
115   CHAR CommandLine[MAX_PATH];
116   BOOLEAN Result;
117   DWORD dwError;
118   HANDLE hKey;
119   DWORD dwType;
120   DWORD dwSize;
121   DWORD dwExitCode;
122
123   DPRINT ("RunSetup() called\n");
124
125   dwError = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
126                           "SYSTEM\\Setup",
127                           0,
128                           KEY_QUERY_VALUE,
129                           &hKey);
130   if (dwError != ERROR_SUCCESS)
131     {
132       return FALSE;
133     }
134
135   dwSize = MAX_PATH;
136   dwError = RegQueryValueEx (hKey,
137                              "CmdLine",
138                              NULL,
139                              &dwType,
140                              (LPBYTE)CommandLine,
141                              &dwSize);
142   RegCloseKey (hKey);
143   if (dwError != ERROR_SUCCESS || dwType != REG_SZ)
144     {
145       return FALSE;
146     }
147
148   DPRINT ("Winlogon: Should run '%s' now.\n", CommandLine);
149
150   StartupInfo.cb = sizeof(StartupInfo);
151   StartupInfo.lpReserved = NULL;
152   StartupInfo.lpDesktop = NULL;
153   StartupInfo.lpTitle = NULL;
154   StartupInfo.dwFlags = 0;
155   StartupInfo.cbReserved2 = 0;
156   StartupInfo.lpReserved2 = 0;
157
158   DPRINT ("Winlogon: Creating new setup process\n");
159
160   Result = CreateProcess (NULL,
161                           CommandLine,
162                           NULL,
163                           NULL,
164                           FALSE,
165                           DETACHED_PROCESS,
166                           NULL,
167                           NULL,
168                           &StartupInfo,
169                           &ProcessInformation);
170   if (!Result)
171     {
172       DPRINT ("Winlogon: Failed to run setup process\n");
173       return FALSE;
174     }
175
176   /* Wait for process termination */
177   WaitForSingleObject (ProcessInformation.hProcess, INFINITE);
178
179   GetExitCodeProcess (ProcessInformation.hProcess, &dwExitCode);
180
181   CloseHandle (ProcessInformation.hThread);
182   CloseHandle (ProcessInformation.hProcess);
183
184   if (dwExitCode == 0)
185     {
186       SetSetupType (0);
187     }
188
189   DPRINT ("Winlogon: RunSetup() done.\n");
190
191   return TRUE;
192 }
193
194
195 /* EOF */