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 *****************************************************************/
31 #define NTOS_MODE_USER
32 #include <ndk/ntndk.h>
39 #include <samlib/samlib.h>
54 /* GLOBALS ******************************************************************/
56 PSID DomainSid
= NULL
;
59 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
61 /* FUNCTIONS ****************************************************************/
64 DebugPrint(char* fmt
,...)
70 vsprintf(buffer
, fmt
, ap
);
73 strcat(buffer
, "\nRebooting now!");
85 PROCESS_INFORMATION ProcInfo
;
87 WCHAR InstallName
[] = L
"vmwinst.exe";
89 ZeroMemory(&si
, sizeof(STARTUPINFO
));
90 si
.cb
= sizeof(STARTUPINFO
);
92 if(CreateProcess(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
93 NULL
, NULL
, &si
, &ProcInfo
))
95 WaitForSingleObject(ProcInfo
.hProcess
, INFINITE
);
96 CloseHandle(ProcInfo
.hThread
);
97 CloseHandle(ProcInfo
.hProcess
);
105 HRESULT
CreateShellLink(LPCTSTR linkPath
, LPCTSTR cmd
, LPCTSTR arg
, LPCTSTR dir
, LPCTSTR iconPath
, int icon_nr
, LPCTSTR comment
)
110 WCHAR buffer
[MAX_PATH
];
111 #endif /* _UNICODE */
113 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
117 hr
= psl
->lpVtbl
->SetPath(psl
, cmd
);
121 hr
= psl
->lpVtbl
->SetArguments(psl
, arg
);
126 hr
= psl
->lpVtbl
->SetWorkingDirectory(psl
, dir
);
131 hr
= psl
->lpVtbl
->SetIconLocation(psl
, iconPath
, icon_nr
);
136 hr
= psl
->lpVtbl
->SetDescription(psl
, comment
);
139 hr
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
144 hr
= ppf
->lpVtbl
->Save(ppf
, linkPath
, TRUE
);
146 MultiByteToWideChar(CP_ACP
, 0, linkPath
, -1, buffer
, MAX_PATH
);
148 hr
= ppf
->lpVtbl
->Save(ppf
, buffer
, TRUE
);
149 #endif /* _UNICODE */
151 ppf
->lpVtbl
->Release(ppf
);
154 psl
->lpVtbl
->Release(psl
);
164 TCHAR path
[MAX_PATH
];
169 SHGetSpecialFolderPath(0, path
, CSIDL_DESKTOP
, TRUE
);
170 p
= PathAddBackslash(path
);
172 _tcscpy(p
, _T("Command Prompt.lnk"));
173 CreateShellLink(path
, _T("cmd.exe"), _T(""), NULL
, NULL
, 0, _T("Open command prompt"));
180 CreateRandomSid (PSID
*Sid
)
182 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
183 LARGE_INTEGER SystemTime
;
186 NtQuerySystemTime (&SystemTime
);
187 Seed
= &SystemTime
.u
.LowPart
;
189 RtlAllocateAndInitializeSid (&SystemAuthority
,
191 SECURITY_NT_NON_UNIQUE_RID
,
204 AppendRidToSid (PSID
*Dst
,
208 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
212 RidCount
= *RtlSubAuthorityCountSid (Src
);
214 for (i
= 0; i
< RidCount
; i
++)
215 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
219 Rid
[RidCount
] = NewRid
;
223 RtlAllocateAndInitializeSid (RtlIdentifierAuthoritySid (Src
),
237 RestartDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
242 SendDlgItemMessage(hWnd
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
244 SetTimer(hWnd
, 0, 50, NULL
);
252 hWndProgress
= GetDlgItem(hWnd
, IDC_RESTART_PROGRESS
);
253 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
257 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
276 CreateTempDir(LPCWSTR VarName
)
278 TCHAR szTempDir
[MAX_PATH
];
279 TCHAR szBuffer
[MAX_PATH
];
283 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
284 _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"),
289 DebugPrint("Error: %lu\n", GetLastError());
294 dwLength
= MAX_PATH
* sizeof(TCHAR
);
295 if (RegQueryValueEx(hKey
,
302 DebugPrint("Error: %lu\n", GetLastError());
308 if (!ExpandEnvironmentStrings(szBuffer
,
312 DebugPrint("Error: %lu\n", GetLastError());
317 /* Create profiles directory */
318 if (!CreateDirectory(szTempDir
, NULL
))
320 if (GetLastError() != ERROR_ALREADY_EXISTS
)
322 DebugPrint("Error: %lu\n", GetLastError());
333 ProcessSysSetupInf(VOID
)
335 INFCONTEXT InfContext
;
336 TCHAR LineBuffer
[256];
339 if (!SetupFindFirstLine(hSysSetupInf
,
340 _T("DeviceInfsToInstall"),
349 if (!SetupGetStringField(&InfContext
,
358 if (!SetupDiInstallClass(NULL
, LineBuffer
, DI_QUIETINSTALL
, NULL
))
363 while (SetupFindNextLine(&InfContext
, &InfContext
));
370 InstallReactOS (HINSTANCE hInstance
)
373 OutputDebugStringA ("InstallReactOS() called\n");
375 if (!InitializeSetupActionLog (FALSE
))
377 OutputDebugStringA ("InitializeSetupActionLog() failed\n");
380 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
381 L
"ReactOS Setup starting");
383 LogItem (SYSSETUP_SEVERITY_FATAL_ERROR
,
386 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
387 L
"ReactOS Setup finished");
389 TerminateSetupActionLog ();
392 UNICODE_STRING SidString
;
396 if (!InitializeProfiles ())
398 DebugPrint ("InitializeProfiles() failed\n");
404 /* Create the semi-random Domain-SID */
405 CreateRandomSid (&DomainSid
);
406 if (DomainSid
== NULL
)
408 DebugPrint ("Domain-SID creation failed!\n");
413 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
414 DebugPrint ("Domain-SID: %wZ\n", &SidString
);
415 RtlFreeUnicodeString (&SidString
);
418 /* Initialize the Security Account Manager (SAM) */
419 if (!SamInitializeSAM ())
421 DebugPrint ("SamInitializeSAM() failed!\n");
422 RtlFreeSid (DomainSid
);
426 /* Set the Domain SID (aka Computer SID) */
427 if (!SamSetDomainSid (DomainSid
))
429 DebugPrint ("SamSetDomainSid() failed!\n");
430 RtlFreeSid (DomainSid
);
434 /* Append the Admin-RID */
435 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
438 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
439 DebugPrint ("Admin-SID: %wZ\n", &SidString
);
440 RtlFreeUnicodeString (&SidString
);
443 /* Create the Administrator account */
444 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
446 /* Check what the error was.
447 * If the Admin Account already exists, then it means Setup
448 * wasn't allowed to finish properly. Instead of rebooting
449 * and not completing it, let it restart instead
451 LastError
= GetLastError();
452 if (LastError
!= ERROR_USER_EXISTS
)
454 DebugPrint("SamCreateUser() failed!\n");
455 RtlFreeSid(AdminSid
);
456 RtlFreeSid(DomainSid
);
461 /* Create the Administrator profile */
462 if (!CreateUserProfileW(AdminSid
, L
"Administrator"))
464 DebugPrint("CreateUserProfileW() failed!\n");
465 RtlFreeSid(AdminSid
);
466 RtlFreeSid(DomainSid
);
470 RtlFreeSid(AdminSid
);
471 RtlFreeSid(DomainSid
);
473 CreateTempDir(L
"TEMP");
474 CreateTempDir(L
"TMP");
476 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
480 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
482 DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
486 if (!ProcessSysSetupInf())
488 DebugPrint("ProcessSysSetupInf() failed!\n");
494 SetupCloseInfFile(hSysSetupInf
);
500 DialogBox(hDllInstance
,
501 MAKEINTRESOURCE(IDD_RESTART
),
513 SetupChangeFontSize(HANDLE hWnd
,
514 LPCWSTR lpszFontSize
)