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 *****************************************************************/
30 #define WIN32_NO_STATUS
32 #define NTOS_MODE_USER
33 #include <ndk/ntndk.h>
41 #include <samlib/samlib.h>
42 #include <syssetup/syssetup.h>
56 /* GLOBALS ******************************************************************/
58 PSID DomainSid
= NULL
;
61 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
63 /* FUNCTIONS ****************************************************************/
66 DebugPrint(char* fmt
,...)
72 vsprintf(buffer
, fmt
, ap
);
75 strcat(buffer
, "\nRebooting now!");
87 PROCESS_INFORMATION ProcInfo
;
89 WCHAR InstallName
[] = L
"vmwinst.exe";
91 ZeroMemory(&si
, sizeof(STARTUPINFO
));
92 si
.cb
= sizeof(STARTUPINFO
);
94 if(CreateProcess(NULL
, InstallName
, NULL
, NULL
, TRUE
, NORMAL_PRIORITY_CLASS
,
95 NULL
, NULL
, &si
, &ProcInfo
))
97 WaitForSingleObject(ProcInfo
.hProcess
, INFINITE
);
98 CloseHandle(ProcInfo
.hThread
);
99 CloseHandle(ProcInfo
.hProcess
);
107 HRESULT
CreateShellLink(LPCTSTR linkPath
, LPCTSTR cmd
, LPCTSTR arg
, LPCTSTR dir
, LPCTSTR iconPath
, int icon_nr
, LPCTSTR comment
)
112 WCHAR buffer
[MAX_PATH
];
113 #endif /* _UNICODE */
115 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
119 hr
= psl
->lpVtbl
->SetPath(psl
, cmd
);
123 hr
= psl
->lpVtbl
->SetArguments(psl
, arg
);
128 hr
= psl
->lpVtbl
->SetWorkingDirectory(psl
, dir
);
133 hr
= psl
->lpVtbl
->SetIconLocation(psl
, iconPath
, icon_nr
);
138 hr
= psl
->lpVtbl
->SetDescription(psl
, comment
);
141 hr
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
146 hr
= ppf
->lpVtbl
->Save(ppf
, linkPath
, TRUE
);
148 MultiByteToWideChar(CP_ACP
, 0, linkPath
, -1, buffer
, MAX_PATH
);
150 hr
= ppf
->lpVtbl
->Save(ppf
, buffer
, TRUE
);
151 #endif /* _UNICODE */
153 ppf
->lpVtbl
->Release(ppf
);
156 psl
->lpVtbl
->Release(psl
);
164 CreateShortcut(int csidl
, LPCTSTR folder
, LPCTSTR linkName
, LPCTSTR command
, UINT nIdTitle
)
166 TCHAR path
[MAX_PATH
];
170 if (!SHGetSpecialFolderPath(0, path
, csidl
, TRUE
))
175 p
= PathAddBackslash(p
);
179 p
= PathAddBackslash(p
);
180 _tcscpy(p
, linkName
);
182 if (!LoadString(hDllInstance
, nIdTitle
, title
, 256))
185 return SUCCEEDED(CreateShellLink(path
, command
, _T(""), NULL
, NULL
, 0, title
));
190 CreateShortcutFolder(int csidl
, UINT nID
, LPTSTR name
, int nameLen
)
192 TCHAR path
[MAX_PATH
];
195 if (!SHGetSpecialFolderPath(0, path
, csidl
, TRUE
))
198 if (!LoadString(hDllInstance
, nID
, name
, nameLen
))
201 p
= PathAddBackslash(path
);
204 return CreateDirectory(path
, NULL
) || GetLastError()==ERROR_ALREADY_EXISTS
;
209 CreateRandomSid (PSID
*Sid
)
211 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
212 LARGE_INTEGER SystemTime
;
215 NtQuerySystemTime (&SystemTime
);
216 Seed
= &SystemTime
.u
.LowPart
;
218 RtlAllocateAndInitializeSid (&SystemAuthority
,
220 SECURITY_NT_NON_UNIQUE_RID
,
233 AppendRidToSid (PSID
*Dst
,
237 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
241 RidCount
= *RtlSubAuthorityCountSid (Src
);
243 for (i
= 0; i
< RidCount
; i
++)
244 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
248 Rid
[RidCount
] = NewRid
;
252 RtlAllocateAndInitializeSid (RtlIdentifierAuthoritySid (Src
),
266 RestartDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
271 SendDlgItemMessage(hWnd
, IDC_RESTART_PROGRESS
, PBM_SETRANGE
, 0,
273 SetTimer(hWnd
, 1, 50, NULL
);
281 hWndProgress
= GetDlgItem(hWnd
, IDC_RESTART_PROGRESS
);
282 Position
= SendMessage(hWndProgress
, PBM_GETPOS
, 0, 0);
286 SendMessage(hWndProgress
, PBM_SETPOS
, Position
+ 1, 0);
305 CreateTempDir(LPCWSTR VarName
)
307 TCHAR szTempDir
[MAX_PATH
];
308 TCHAR szBuffer
[MAX_PATH
];
312 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
313 _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"),
318 DebugPrint("Error: %lu\n", GetLastError());
323 dwLength
= MAX_PATH
* sizeof(TCHAR
);
324 if (RegQueryValueEx(hKey
,
331 DebugPrint("Error: %lu\n", GetLastError());
337 if (!ExpandEnvironmentStrings(szBuffer
,
341 DebugPrint("Error: %lu\n", GetLastError());
346 /* Create profiles directory */
347 if (!CreateDirectory(szTempDir
, NULL
))
349 if (GetLastError() != ERROR_ALREADY_EXISTS
)
351 DebugPrint("Error: %lu\n", GetLastError());
362 ProcessSysSetupInf(VOID
)
364 INFCONTEXT InfContext
;
365 TCHAR LineBuffer
[256];
368 if (!SetupFindFirstLine(hSysSetupInf
,
369 _T("DeviceInfsToInstall"),
378 if (!SetupGetStringField(&InfContext
,
387 if (!SetupDiInstallClass(NULL
, LineBuffer
, DI_QUIETINSTALL
, NULL
))
392 while (SetupFindNextLine(&InfContext
, &InfContext
));
399 InstallReactOS (HINSTANCE hInstance
)
401 TCHAR sAccessories
[256];
405 OutputDebugStringA ("InstallReactOS() called\n");
407 if (!InitializeSetupActionLog (FALSE
))
409 OutputDebugStringA ("InitializeSetupActionLog() failed\n");
412 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
413 L
"ReactOS Setup starting");
415 LogItem (SYSSETUP_SEVERITY_FATAL_ERROR
,
418 LogItem (SYSSETUP_SEVERITY_INFORMATION
,
419 L
"ReactOS Setup finished");
421 TerminateSetupActionLog ();
424 UNICODE_STRING SidString
;
428 if (!InitializeProfiles ())
430 DebugPrint ("InitializeProfiles() failed\n");
436 /* create desktop shortcuts */
437 CreateShortcut(CSIDL_DESKTOP
, NULL
, _T("Command Prompt.lnk"), _T("cmd.exe"), IDS_CMT_CMD
);
439 /* create program startmenu shortcuts */
440 CreateShortcut(CSIDL_PROGRAMS
, NULL
, _T("winefile.lnk"), _T("winefile.exe"), IDS_CMT_WINEFILE
);
442 /* create and fill Accessories subfolder */
443 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_ACCESSORIES
, sAccessories
, 256)) {
444 CreateShortcut(CSIDL_PROGRAMS
, sAccessories
, _T("Command Prompt.lnk"), _T("cmd.exe"), IDS_CMT_CMD
);
445 CreateShortcut(CSIDL_PROGRAMS
, sAccessories
, _T("notepad.lnk"), _T("notepad.exe"), IDS_CMT_NOTEPAD
);
446 CreateShortcut(CSIDL_PROGRAMS
, sAccessories
, _T("explorer.lnk"), _T("explorer.exe"), IDS_CMT_EXPLORER
);
447 CreateShortcut(CSIDL_PROGRAMS
, sAccessories
, _T("regedit.lnk"), _T("regedit.exe"), IDS_CMT_REGEDIT
);
450 /* create Games subfolder and fill if the exe is available */
451 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_GAMES
, sGames
, 256)) {
452 /* Check for existence */
453 if( (_access( "c:\\reactos\\system32\\sol.exe", 0 )) != -1 )
454 CreateShortcut(CSIDL_PROGRAMS
, sGames
, _T("Solitaire.lnk"), _T("sol.exe"), IDS_CMT_SOLITAIRE
);
460 /* Create the semi-random Domain-SID */
461 CreateRandomSid (&DomainSid
);
462 if (DomainSid
== NULL
)
464 DebugPrint ("Domain-SID creation failed!\n");
469 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
470 DebugPrint ("Domain-SID: %wZ\n", &SidString
);
471 RtlFreeUnicodeString (&SidString
);
474 /* Initialize the Security Account Manager (SAM) */
475 if (!SamInitializeSAM ())
477 DebugPrint ("SamInitializeSAM() failed!\n");
478 RtlFreeSid (DomainSid
);
482 /* Set the Domain SID (aka Computer SID) */
483 if (!SamSetDomainSid (DomainSid
))
485 DebugPrint ("SamSetDomainSid() failed!\n");
486 RtlFreeSid (DomainSid
);
490 /* Append the Admin-RID */
491 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
494 RtlConvertSidToUnicodeString (&SidString
, DomainSid
, TRUE
);
495 DebugPrint ("Admin-SID: %wZ\n", &SidString
);
496 RtlFreeUnicodeString (&SidString
);
499 /* Create the Administrator account */
500 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
502 /* Check what the error was.
503 * If the Admin Account already exists, then it means Setup
504 * wasn't allowed to finish properly. Instead of rebooting
505 * and not completing it, let it restart instead
507 LastError
= GetLastError();
508 if (LastError
!= ERROR_USER_EXISTS
)
510 DebugPrint("SamCreateUser() failed!\n");
511 RtlFreeSid(AdminSid
);
512 RtlFreeSid(DomainSid
);
517 /* Create the Administrator profile */
518 if (!CreateUserProfileW(AdminSid
, L
"Administrator"))
520 DebugPrint("CreateUserProfileW() failed!\n");
521 RtlFreeSid(AdminSid
);
522 RtlFreeSid(DomainSid
);
526 RtlFreeSid(AdminSid
);
527 RtlFreeSid(DomainSid
);
529 CreateTempDir(L
"TEMP");
530 CreateTempDir(L
"TMP");
532 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
536 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
538 DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
542 if (!ProcessSysSetupInf())
544 DebugPrint("ProcessSysSetupInf() failed!\n");
550 SetupCloseInfFile(hSysSetupInf
);
556 DialogBox(hDllInstance
,
557 MAKEINTRESOURCE(IDD_RESTART
),
569 SetupChangeFontSize(HANDLE hWnd
,
570 LPCWSTR lpszFontSize
)