Sync with trunk r58687.
[reactos.git] / base / system / winlogon / setup.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Winlogon
4 * FILE: base/system/winlogon/setup.c
5 * PURPOSE: Setup support functions
6 * PROGRAMMERS: Eric Kohl
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include "winlogon.h"
12
13 WINE_DEFAULT_DEBUG_CHANNEL(winlogon);
14
15 /* FUNCTIONS ****************************************************************/
16
17 DWORD
18 GetSetupType(VOID)
19 {
20 DWORD dwError;
21 HKEY hKey;
22 DWORD dwType;
23 DWORD dwSize;
24 DWORD dwSetupType;
25
26 TRACE("GetSetupType()\n");
27
28 /* Open key */
29 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
30 L"SYSTEM\\Setup",
31 0,
32 KEY_QUERY_VALUE,
33 &hKey);
34 if (dwError != ERROR_SUCCESS)
35 return 0;
36
37 /* Read key */
38 dwSize = sizeof(DWORD);
39 dwError = RegQueryValueExW(hKey,
40 L"SetupType",
41 NULL,
42 &dwType,
43 (LPBYTE)&dwSetupType,
44 &dwSize);
45
46 /* Close key, and check if returned values are correct */
47 RegCloseKey(hKey);
48 if (dwError != ERROR_SUCCESS || dwType != REG_DWORD || dwSize != sizeof(DWORD))
49 return 0;
50
51 TRACE("GetSetupType() returns %lu\n", dwSetupType);
52 return dwSetupType;
53 }
54
55
56 static
57 DWORD
58 WINAPI
59 RunSetupThreadProc(IN LPVOID lpParameter)
60 {
61 PROCESS_INFORMATION ProcessInformation;
62 STARTUPINFOW StartupInfo;
63 WCHAR Shell[MAX_PATH];
64 WCHAR CommandLine[MAX_PATH];
65 BOOL Result;
66 DWORD dwError;
67 HKEY hKey;
68 DWORD dwType;
69 DWORD dwSize;
70 DWORD dwExitCode;
71
72 TRACE("RunSetup() called\n");
73
74 /* Open key */
75 dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
76 L"SYSTEM\\Setup",
77 0,
78 KEY_QUERY_VALUE,
79 &hKey);
80 if (dwError != ERROR_SUCCESS)
81 return FALSE;
82
83 /* Read key */
84 dwSize = (sizeof(Shell) / sizeof(Shell[0])) - 1;
85 dwError = RegQueryValueExW(hKey,
86 L"CmdLine",
87 NULL,
88 &dwType,
89 (LPBYTE)Shell,
90 &dwSize);
91 RegCloseKey(hKey);
92 if (dwError != ERROR_SUCCESS)
93 return FALSE;
94
95 /* Finish string */
96 Shell[dwSize / sizeof(WCHAR)] = UNICODE_NULL;
97
98 /* Expand string (if applicable) */
99 if (dwType == REG_EXPAND_SZ)
100 ExpandEnvironmentStringsW(Shell, CommandLine, MAX_PATH);
101 else if (dwType == REG_SZ)
102 wcscpy(CommandLine, Shell);
103 else
104 return FALSE;
105
106 TRACE("Should run '%s' now\n", debugstr_w(CommandLine));
107
108 /* Start process */
109 StartupInfo.cb = sizeof(StartupInfo);
110 StartupInfo.lpReserved = NULL;
111 StartupInfo.lpDesktop = NULL;
112 StartupInfo.lpTitle = NULL;
113 StartupInfo.dwFlags = 0;
114 StartupInfo.cbReserved2 = 0;
115 StartupInfo.lpReserved2 = 0;
116
117 Result = CreateProcessW(NULL,
118 CommandLine,
119 NULL,
120 NULL,
121 FALSE,
122 DETACHED_PROCESS,
123 NULL,
124 NULL,
125 &StartupInfo,
126 &ProcessInformation);
127 if (!Result)
128 {
129 TRACE("Failed to run setup process\n");
130 return FALSE;
131 }
132
133 /* Wait for process termination */
134 WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
135
136 GetExitCodeProcess(ProcessInformation.hProcess, &dwExitCode);
137
138 /* Close handles */
139 CloseHandle(ProcessInformation.hThread);
140 CloseHandle(ProcessInformation.hProcess);
141
142 TRACE ("RunSetup() done\n");
143
144 return TRUE;
145 }
146
147
148 BOOL
149 RunSetup(VOID)
150 {
151 HANDLE hThread;
152
153 hThread = CreateThread(NULL,
154 0,
155 RunSetupThreadProc,
156 NULL,
157 0,
158 NULL);
159
160 return hThread != NULL;
161 }
162
163 /* EOF */