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.
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 *****************************************************************/
52 /* GLOBALS ******************************************************************/
54 PSID DomainSid
= NULL
;
57 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
59 /* FUNCTIONS ****************************************************************/
62 DebugPrint(char* fmt
,...)
68 vsprintf(buffer
, fmt
, ap
);
71 strcat(buffer
, "\nRebooting now!");
83 PROCESS_INFORMATION ProcInfo
;
86 ZeroMemory(&si
, sizeof(STARTUPINFO
));
87 si
.cb
= sizeof(STARTUPINFO
);
89 if(CreateProcess(NULL
, _T("vmwinst.exe"), NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
90 NULL
, NULL
, &si
, &ProcInfo
))
92 WaitForSingleObject(ProcInfo
.hProcess
, INFINITE
);
93 CloseHandle(ProcInfo
.hThread
);
94 CloseHandle(ProcInfo
.hProcess
);
102 HRESULT
CreateShellLink(LPCSTR linkPath
, LPCSTR cmd
, LPCSTR arg
, LPCSTR dir
, LPCSTR iconPath
, int icon_nr
, LPCSTR comment
)
106 WCHAR buffer
[MAX_PATH
];
108 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
112 hr
= psl
->lpVtbl
->SetPath(psl
, cmd
);
116 hr
= psl
->lpVtbl
->SetArguments(psl
, arg
);
121 hr
= psl
->lpVtbl
->SetWorkingDirectory(psl
, dir
);
126 hr
= psl
->lpVtbl
->SetIconLocation(psl
, iconPath
, icon_nr
);
131 hr
= psl
->lpVtbl
->SetDescription(psl
, comment
);
134 hr
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
138 MultiByteToWideChar(CP_ACP
, 0, linkPath
, -1, buffer
, MAX_PATH
);
140 hr
= ppf
->lpVtbl
->Save(ppf
, buffer
, TRUE
);
142 ppf
->lpVtbl
->Release(ppf
);
145 psl
->lpVtbl
->Release(psl
);
160 SHGetSpecialFolderPathA(0, path
, CSIDL_DESKTOP
, TRUE
);
161 p
= PathAddBackslashA(path
);
163 strcpy(p
, "Command Prompt.lnk");
164 CreateShellLink(path
, "cmd.exe", "", NULL
, NULL
, 0, "Open command prompt");
171 CreateRandomSid (PSID
*Sid
)
173 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
174 LARGE_INTEGER SystemTime
;
177 NtQuerySystemTime (&SystemTime
);
178 Seed
= &SystemTime
.u
.LowPart
;
180 RtlAllocateAndInitializeSid (&SystemAuthority
,
182 SECURITY_NT_NON_UNIQUE_RID
,
195 AppendRidToSid (PSID
*Dst
,
199 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
203 RidCount
= *RtlSubAuthorityCountSid (Src
);
205 for (i
= 0; i
< RidCount
; i
++)
206 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
210 Rid
[RidCount
] = NewRid
;
214 RtlAllocateAndInitializeSid (RtlIdentifierAuthoritySid (Src
),
228 RestartDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
233 SendDlgItemMessage(hWnd
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
235 SetTimer(hWnd
, 0, 50, NULL
);
243 hWndProgress
= GetDlgItem(hWnd
, IDC_RESTART_PROGRESS
);
244 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
248 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
267 CreateTempDir(LPCWSTR VarName
)
269 TCHAR szTempDir
[MAX_PATH
];
270 TCHAR szBuffer
[MAX_PATH
];
274 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
275 _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"),
280 DebugPrint("Error: %lu\n", GetLastError());
285 dwLength
= MAX_PATH
* sizeof(TCHAR
);
286 if (RegQueryValueEx(hKey
,
293 DebugPrint("Error: %lu\n", GetLastError());
299 if (!ExpandEnvironmentStrings(szBuffer
,
303 DebugPrint("Error: %lu\n", GetLastError());
308 /* Create profiles directory */
309 if (!CreateDirectory(szTempDir
, NULL
))
311 if (GetLastError() != ERROR_ALREADY_EXISTS
)
313 DebugPrint("Error: %lu\n", GetLastError());
324 ProcessSysSetupInf(VOID
)
326 INFCONTEXT InfContext
;
327 TCHAR LineBuffer
[256];
330 if (!SetupFindFirstLine(hSysSetupInf
,
331 _T("DeviceInfsToInstall"),
340 if (!SetupGetStringField(&InfContext
,
349 if (!SetupDiInstallClass(NULL
, LineBuffer
, DI_QUIETINSTALL
, NULL
))
354 while (SetupFindNextLine(&InfContext
, &InfContext
));
361 InstallReactOS (HINSTANCE hInstance
)
364 OutputDebugStringA ("InstallReactOS() called\n");
366 if (!InitializeSetupActionLog (FALSE
))
368 OutputDebugStringA ("InitializeSetupActionLog() failed\n");
371 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
372 L
"ReactOS Setup starting");
374 LogItem (SYSSETUP_SEVERITY_FATAL_ERROR
,
377 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
378 L
"ReactOS Setup finished");
380 TerminateSetupActionLog ();
383 UNICODE_STRING SidString
;
387 if (!InitializeProfiles ())
389 DebugPrint ("InitializeProfiles() failed\n");
395 /* Create the semi-random Domain-SID */
396 CreateRandomSid (&DomainSid
);
397 if (DomainSid
== NULL
)
399 DebugPrint ("Domain-SID creation failed!\n");
404 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
405 DebugPrint ("Domain-SID: %wZ\n", &SidString
);
406 RtlFreeUnicodeString (&SidString
);
409 /* Initialize the Security Account Manager (SAM) */
410 if (!SamInitializeSAM ())
412 DebugPrint ("SamInitializeSAM() failed!\n");
413 RtlFreeSid (DomainSid
);
417 /* Set the Domain SID (aka Computer SID) */
418 if (!SamSetDomainSid (DomainSid
))
420 DebugPrint ("SamSetDomainSid() failed!\n");
421 RtlFreeSid (DomainSid
);
425 /* Append the Admin-RID */
426 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
429 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
430 DebugPrint ("Admin-SID: %wZ\n", &SidString
);
431 RtlFreeUnicodeString (&SidString
);
434 /* Create the Administrator account */
435 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
437 /* Check what the error was.
438 * If the Admin Account already exists, then it means Setup
439 * wasn't allowed to finish properly. Instead of rebooting
440 * and not completing it, let it restart instead
442 LastError
= GetLastError();
443 if (LastError
!= ERROR_USER_EXISTS
)
445 DebugPrint("SamCreateUser() failed!\n");
446 RtlFreeSid(AdminSid
);
447 RtlFreeSid(DomainSid
);
452 /* Create the Administrator profile */
453 if (!CreateUserProfileW(AdminSid
, L
"Administrator"))
455 DebugPrint("CreateUserProfileW() failed!\n");
456 RtlFreeSid(AdminSid
);
457 RtlFreeSid(DomainSid
);
461 RtlFreeSid(AdminSid
);
462 RtlFreeSid(DomainSid
);
464 CreateTempDir(L
"TEMP");
465 CreateTempDir(L
"TMP");
467 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
471 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
473 DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
477 if (!ProcessSysSetupInf())
479 DebugPrint("ProcessSysSetupInf() failed!\n");
485 SetupCloseInfFile(hSysSetupInf
);
491 DialogBox(hDllInstance
,
492 MAKEINTRESOURCE(IDD_RESTART
),
504 SetupChangeFontSize(HANDLE hWnd
,
505 LPCWSTR lpszFontSize
)