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.17 2004/10/19 14:33:07 ekohl 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
;
316 if (!InitializeProfiles ())
318 DebugPrint ("InitializeProfiles() failed\n");
322 /* Create the semi-random Domain-SID */
323 CreateRandomSid (&DomainSid
);
324 if (DomainSid
== NULL
)
326 DebugPrint ("Domain-SID creation failed!\n");
331 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
332 DebugPrint ("Domain-SID: %wZ\n", &SidString
);
333 RtlFreeUnicodeString (&SidString
);
336 /* Initialize the Security Account Manager (SAM) */
337 if (!SamInitializeSAM ())
339 DebugPrint ("SamInitializeSAM() failed!\n");
340 RtlFreeSid (DomainSid
);
344 /* Set the Domain SID (aka Computer SID) */
345 if (!SamSetDomainSid (DomainSid
))
347 DebugPrint ("SamSetDomainSid() failed!\n");
348 RtlFreeSid (DomainSid
);
352 /* Append the Admin-RID */
353 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
356 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
357 DebugPrint ("Admin-SID: %wZ\n", &SidString
);
358 RtlFreeUnicodeString (&SidString
);
361 /* Create the Administrator account */
362 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
364 DebugPrint("SamCreateUser() failed!\n");
365 RtlFreeSid(AdminSid
);
366 RtlFreeSid(DomainSid
);
370 /* Create the Administrator profile */
371 if (!CreateUserProfileW(AdminSid
, L
"Administrator"))
373 DebugPrint("CreateUserProfileW() failed!\n");
374 RtlFreeSid(AdminSid
);
375 RtlFreeSid(DomainSid
);
379 RtlFreeSid(AdminSid
);
380 RtlFreeSid(DomainSid
);
382 CreateTempDir(L
"TEMP");
383 CreateTempDir(L
"TMP");
385 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
389 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
391 DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
395 if (!ProcessSysSetupInf())
397 DebugPrint("ProcessSysSetupInf() failed!\n");
403 SetupCloseInfFile(hSysSetupInf
);
409 DialogBox(hDllInstance
,
410 MAKEINTRESOURCE(IDD_RESTART
),
422 SetupChangeFontSize(HANDLE hWnd
,
423 LPCWSTR lpszFontSize
)