3 * Copyright (C) 2003 ReactOS Team
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.
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.
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.
19 /* $Id: install.c,v 1.18 2004/11/09 15:02:35 ion Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * PURPOSE: System setup
24 * FILE: lib/syssetup/install.c
25 * PROGRAMER: Eric Kohl
28 /* INCLUDES *****************************************************************/
47 VOID WINAPI
CreateCmdLink(VOID
);
50 /* GLOBALS ******************************************************************/
52 PSID DomainSid
= NULL
;
55 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
57 /* FUNCTIONS ****************************************************************/
60 DebugPrint(char* fmt
,...)
66 vsprintf(buffer
, fmt
, ap
);
69 strcat(buffer
, "\nRebooting now!");
81 PROCESS_INFORMATION ProcInfo
;
84 ZeroMemory(&si
, sizeof(STARTUPINFO
));
85 si
.cb
= sizeof(STARTUPINFO
);
87 if(CreateProcessA(NULL
, "vmwinst.exe", NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
88 NULL
, NULL
, &si
, &ProcInfo
))
90 WaitForSingleObject(ProcInfo
.hProcess
, INFINITE
);
91 CloseHandle(ProcInfo
.hThread
);
92 CloseHandle(ProcInfo
.hProcess
);
101 CreateRandomSid (PSID
*Sid
)
103 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
104 LARGE_INTEGER SystemTime
;
107 NtQuerySystemTime (&SystemTime
);
108 Seed
= &SystemTime
.u
.LowPart
;
110 RtlAllocateAndInitializeSid (&SystemAuthority
,
112 SECURITY_NT_NON_UNIQUE_RID
,
125 AppendRidToSid (PSID
*Dst
,
129 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
133 RidCount
= *RtlSubAuthorityCountSid (Src
);
135 for (i
= 0; i
< RidCount
; i
++)
136 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
140 Rid
[RidCount
] = NewRid
;
144 RtlAllocateAndInitializeSid (RtlIdentifierAuthoritySid (Src
),
158 RestartDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
163 SendDlgItemMessage(hWnd
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
165 SetTimer(hWnd
, 0, 50, NULL
);
173 hWndProgress
= GetDlgItem(hWnd
, IDC_RESTART_PROGRESS
);
174 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
178 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
197 CreateTempDir(LPCWSTR VarName
)
199 WCHAR szTempDir
[MAX_PATH
];
200 WCHAR szBuffer
[MAX_PATH
];
204 if (RegOpenKeyExW (HKEY_LOCAL_MACHINE
,
205 L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
210 DebugPrint("Error: %lu\n", GetLastError());
215 dwLength
= MAX_PATH
* sizeof(WCHAR
);
216 if (RegQueryValueExW (hKey
,
223 DebugPrint("Error: %lu\n", GetLastError());
229 if (!ExpandEnvironmentStringsW (szBuffer
,
233 DebugPrint("Error: %lu\n", GetLastError());
238 /* Create profiles directory */
239 if (!CreateDirectoryW (szTempDir
, NULL
))
241 if (GetLastError () != ERROR_ALREADY_EXISTS
)
243 DebugPrint("Error: %lu\n", GetLastError());
254 ProcessSysSetupInf(VOID
)
256 INFCONTEXT InfContext
;
257 TCHAR LineBuffer
[256];
260 if (!SetupFindFirstLine(hSysSetupInf
,
261 _T("DeviceInfsToInstall"),
270 if (!SetupGetStringField(&InfContext
,
279 if (!SetupDiInstallClass(NULL
, LineBuffer
, DI_QUIETINSTALL
, NULL
))
284 while (SetupFindNextLine(&InfContext
, &InfContext
));
291 InstallReactOS (HINSTANCE hInstance
)
294 OutputDebugStringA ("InstallReactOS() called\n");
296 if (!InitializeSetupActionLog (FALSE
))
298 OutputDebugStringA ("InitializeSetupActionLog() failed\n");
301 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
302 L
"ReactOS Setup starting");
304 LogItem (SYSSETUP_SEVERITY_FATAL_ERROR
,
307 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
308 L
"ReactOS Setup finished");
310 TerminateSetupActionLog ();
313 UNICODE_STRING SidString
;
317 if (!InitializeProfiles ())
319 DebugPrint ("InitializeProfiles() failed\n");
323 /* Create the semi-random Domain-SID */
324 CreateRandomSid (&DomainSid
);
325 if (DomainSid
== NULL
)
327 DebugPrint ("Domain-SID creation failed!\n");
332 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
333 DebugPrint ("Domain-SID: %wZ\n", &SidString
);
334 RtlFreeUnicodeString (&SidString
);
337 /* Initialize the Security Account Manager (SAM) */
338 if (!SamInitializeSAM ())
340 DebugPrint ("SamInitializeSAM() failed!\n");
341 RtlFreeSid (DomainSid
);
345 /* Set the Domain SID (aka Computer SID) */
346 if (!SamSetDomainSid (DomainSid
))
348 DebugPrint ("SamSetDomainSid() failed!\n");
349 RtlFreeSid (DomainSid
);
353 /* Append the Admin-RID */
354 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
357 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
358 DebugPrint ("Admin-SID: %wZ\n", &SidString
);
359 RtlFreeUnicodeString (&SidString
);
362 /* Create the Administrator account */
363 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
365 /* Check what the error was.
366 * If the Admin Account already exists, then it means Setup
367 * wasn't allowed to finish properly. Instead of rebooting
368 * and not completing it, let it restart instead
370 LastError
= GetLastError();
371 if (LastError
!= ERROR_USER_EXISTS
) {
372 DebugPrint("SamCreateUser() failed!\n");
373 RtlFreeSid(AdminSid
);
374 RtlFreeSid(DomainSid
);
379 /* Create the Administrator profile */
380 if (!CreateUserProfileW(AdminSid
, L
"Administrator"))
382 DebugPrint("CreateUserProfileW() failed!\n");
383 RtlFreeSid(AdminSid
);
384 RtlFreeSid(DomainSid
);
388 RtlFreeSid(AdminSid
);
389 RtlFreeSid(DomainSid
);
391 CreateTempDir(L
"TEMP");
392 CreateTempDir(L
"TMP");
394 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
398 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
400 DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
404 if (!ProcessSysSetupInf())
406 DebugPrint("ProcessSysSetupInf() failed!\n");
412 SetupCloseInfFile(hSysSetupInf
);
418 DialogBox(hDllInstance
,
419 MAKEINTRESOURCE(IDD_RESTART
),
431 SetupChangeFontSize(HANDLE hWnd
,
432 LPCWSTR lpszFontSize
)