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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * PURPOSE: System setup
23 * FILE: dll/win32/syssetup/install.c
24 * PROGRAMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
29 #define WIN32_NO_STATUS
31 #define NTOS_MODE_USER
32 #include <ndk/ntndk.h>
40 #include <samlib/samlib.h>
41 #include <syssetup/syssetup.h>
56 CMP_WaitNoPendingInstallEvents(DWORD dwTimeout
);
58 /* GLOBALS ******************************************************************/
60 PSID DomainSid
= NULL
;
63 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
65 /* FUNCTIONS ****************************************************************/
68 DebugPrint(char* fmt
,...)
74 vsprintf(buffer
, fmt
, ap
);
77 LogItem(SYSSETUP_SEVERITY_FATAL_ERROR
, L
"Failed");
79 strcat(buffer
, "\nRebooting now!");
87 HRESULT
CreateShellLink(LPCTSTR linkPath
, LPCTSTR cmd
, LPCTSTR arg
, LPCTSTR dir
, LPCTSTR iconPath
, int icon_nr
, LPCTSTR comment
)
92 WCHAR buffer
[MAX_PATH
];
95 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
99 hr
= psl
->lpVtbl
->SetPath(psl
, cmd
);
103 hr
= psl
->lpVtbl
->SetArguments(psl
, arg
);
108 hr
= psl
->lpVtbl
->SetWorkingDirectory(psl
, dir
);
113 hr
= psl
->lpVtbl
->SetIconLocation(psl
, iconPath
, icon_nr
);
118 hr
= psl
->lpVtbl
->SetDescription(psl
, comment
);
121 hr
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
126 hr
= ppf
->lpVtbl
->Save(ppf
, linkPath
, TRUE
);
128 MultiByteToWideChar(CP_ACP
, 0, linkPath
, -1, buffer
, MAX_PATH
);
130 hr
= ppf
->lpVtbl
->Save(ppf
, buffer
, TRUE
);
131 #endif /* _UNICODE */
133 ppf
->lpVtbl
->Release(ppf
);
136 psl
->lpVtbl
->Release(psl
);
144 CreateShortcut(int csidl
, LPCTSTR folder
, UINT nIdName
, LPCTSTR command
, UINT nIdTitle
, BOOL bCheckExistence
)
146 TCHAR path
[MAX_PATH
];
147 TCHAR exeName
[MAX_PATH
];
151 TCHAR szWorkingDir
[MAX_PATH
];
152 LPTSTR lpWorkingDir
= NULL
;
156 if (ExpandEnvironmentStrings(command
,
158 sizeof(path
) / sizeof(path
[0])) == 0)
166 if ((_taccess(path
, 0 )) == -1)
167 /* Expected error, don't return FALSE */
171 dwLen
= GetFullPathName(path
,
172 sizeof(szWorkingDir
) / sizeof(szWorkingDir
[0]),
175 if (dwLen
!= 0 && dwLen
<= sizeof(szWorkingDir
) / sizeof(szWorkingDir
[0]))
177 /* Save the file name */
178 _tcscpy(exeName
, lpFilePart
);
180 if (lpFilePart
!= NULL
)
182 /* We're only interested in the path. Cut the file name off.
183 Also remove the trailing backslash unless the working directory
184 is only going to be a drive, ie. C:\ */
185 *(lpFilePart
--) = _T('\0');
186 if (!(lpFilePart
- szWorkingDir
== 2 && szWorkingDir
[1] == _T(':') &&
187 szWorkingDir
[2] == _T('\\')))
189 *lpFilePart
= _T('\0');
193 lpWorkingDir
= szWorkingDir
;
197 if (!SHGetSpecialFolderPath(0, path
, csidl
, TRUE
))
202 p
= PathAddBackslash(p
);
206 p
= PathAddBackslash(p
);
208 if (!LoadString(hDllInstance
, nIdName
, name
, sizeof(name
)/sizeof(name
[0])))
212 if (!LoadString(hDllInstance
, nIdTitle
, title
, sizeof(title
)/sizeof(title
[0])))
215 // FIXME: we should pass 'command' straight in here, but shell32 doesn't expand it
216 return SUCCEEDED(CreateShellLink(path
, exeName
, _T(""), lpWorkingDir
, NULL
, 0, title
));
221 CreateShortcutFolder(int csidl
, UINT nID
, LPTSTR name
, int nameLen
)
223 TCHAR path
[MAX_PATH
];
226 if (!SHGetSpecialFolderPath(0, path
, csidl
, TRUE
))
229 if (!LoadString(hDllInstance
, nID
, name
, nameLen
))
232 p
= PathAddBackslash(path
);
235 return CreateDirectory(path
, NULL
) || GetLastError()==ERROR_ALREADY_EXISTS
;
243 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
244 LARGE_INTEGER SystemTime
;
248 NtQuerySystemTime(&SystemTime
);
249 Seed
= &SystemTime
.u
.LowPart
;
251 Status
= RtlAllocateAndInitializeSid(
254 SECURITY_NT_NON_UNIQUE
,
263 return NT_SUCCESS(Status
);
273 ULONG Rid
[8] = {0, 0, 0, 0, 0, 0, 0, 0};
277 RidCount
= *RtlSubAuthorityCountSid (Src
);
279 for (i
= 0; i
< RidCount
; i
++)
280 Rid
[i
] = *RtlSubAuthoritySid (Src
, i
);
284 Rid
[RidCount
] = NewRid
;
288 RtlAllocateAndInitializeSid(
289 RtlIdentifierAuthoritySid(Src
),
307 WCHAR szTempDir
[MAX_PATH
];
308 WCHAR szBuffer
[MAX_PATH
];
312 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
313 L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
318 DebugPrint("Error: %lu\n", GetLastError());
323 dwLength
= MAX_PATH
* sizeof(WCHAR
);
324 if (RegQueryValueExW(hKey
,
331 DebugPrint("Error: %lu\n", GetLastError());
337 if (!ExpandEnvironmentStringsW(szBuffer
,
341 DebugPrint("Error: %lu\n", GetLastError());
346 /* Create profiles directory */
347 if (!CreateDirectoryW(szTempDir
, NULL
))
349 if (GetLastError() != ERROR_ALREADY_EXISTS
)
351 DebugPrint("Error: %lu\n", GetLastError());
362 InstallSysSetupInfDevices(VOID
)
364 INFCONTEXT InfContext
;
365 WCHAR LineBuffer
[256];
368 if (!SetupFindFirstLineW(hSysSetupInf
,
369 L
"DeviceInfsToInstall",
378 if (!SetupGetStringFieldW(&InfContext
,
381 sizeof(LineBuffer
)/sizeof(LineBuffer
[0]),
387 if (!SetupDiInstallClassW(NULL
, LineBuffer
, DI_QUIETINSTALL
, NULL
))
392 while (SetupFindNextLine(&InfContext
, &InfContext
));
397 InstallSysSetupInfComponents(VOID
)
399 INFCONTEXT InfContext
;
400 WCHAR NameBuffer
[256];
401 WCHAR SectionBuffer
[256];
402 HINF hComponentInf
= INVALID_HANDLE_VALUE
;
404 if (!SetupFindFirstLineW(hSysSetupInf
,
409 DPRINT("No Inf.Always section found\n");
415 if (!SetupGetStringFieldW(&InfContext
,
416 1, // Get the component name
418 sizeof(NameBuffer
)/sizeof(NameBuffer
[0]),
421 DebugPrint("Error while trying to get component name \n");
425 if (!SetupGetStringFieldW(&InfContext
,
426 2, // Get the component install section
428 sizeof(SectionBuffer
)/sizeof(SectionBuffer
[0]),
431 DebugPrint("Error while trying to get component install section \n");
435 DPRINT("Trying to execute install section '%S' from '%S' \n", SectionBuffer
, NameBuffer
);
437 hComponentInf
= SetupOpenInfFileW(NameBuffer
,
442 if (hComponentInf
== INVALID_HANDLE_VALUE
)
444 DebugPrint("SetupOpenInfFileW() failed to open '%S' (Error: %lu)\n", NameBuffer
,GetLastError());
448 if (!SetupInstallFromInfSectionW(NULL
,
455 SetupDefaultQueueCallbackW
,
460 DebugPrint("Error while trying to install : %S (Error: %lu)\n", NameBuffer
, GetLastError());
461 SetupCloseInfFile(hComponentInf
);
465 SetupCloseInfFile(hComponentInf
);
467 while (SetupFindNextLine(&InfContext
, &InfContext
));
474 EnableUserModePnpManager(VOID
)
476 SC_HANDLE hSCManager
= NULL
;
477 SC_HANDLE hService
= NULL
;
480 hSCManager
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
);
481 if (hSCManager
== NULL
)
483 DPRINT1("Unable to open the service control manager.\n");
487 hService
= OpenServiceW(hSCManager
,
489 SERVICE_CHANGE_CONFIG
| SERVICE_START
);
490 if (hService
== NULL
)
492 DPRINT1("Unable to open PlugPlay service\n");
496 ret
= ChangeServiceConfigW(hService
,
501 NULL
, NULL
, NULL
, NULL
);
504 DPRINT1("Unable to change the service configuration\n");
508 ret
= StartServiceW(hService
, 0, NULL
);
509 if ((!ret
) && (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
))
511 DPRINT1("Unable to start service\n");
518 if (hSCManager
!= NULL
)
519 CloseServiceHandle(hSCManager
);
520 if (hService
!= NULL
)
521 CloseServiceHandle(hService
);
526 static INT_PTR CALLBACK
527 StatusMessageWindowProc(
533 UNREFERENCED_PARAMETER(wParam
);
541 if (!LoadStringW(hDllInstance
, IDS_STATUS_INSTALL_DEV
, szMsg
, sizeof(szMsg
)/sizeof(szMsg
[0])))
543 SetDlgItemTextW(hwndDlg
, IDC_STATUSLABEL
, szMsg
);
552 ShowStatusMessageThread(
553 IN LPVOID lpParameter
)
555 HWND
*phWnd
= (HWND
*)lpParameter
;
559 hWnd
= CreateDialogParam(
561 MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG
),
563 StatusMessageWindowProc
,
569 ShowWindow(hWnd
, SW_SHOW
);
571 /* Message loop for the Status window */
572 while (GetMessage(&Msg
, NULL
, 0, 0))
574 TranslateMessage(&Msg
);
575 DispatchMessage(&Msg
);
593 return ERROR_INVALID_PARAMETER
;
596 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
597 if (rc
!= ERROR_SUCCESS
)
599 if (dwType
!= REG_SZ
)
600 return ERROR_FILE_NOT_FOUND
;
601 Value
= HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
603 return ERROR_NOT_ENOUGH_MEMORY
;
604 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)Value
, &cbData
);
605 if (rc
!= ERROR_SUCCESS
)
607 HeapFree(GetProcessHeap(), 0, Value
);
610 /* NULL-terminate the string */
611 Value
[cbData
/ sizeof(WCHAR
)] = '\0';
614 return ERROR_SUCCESS
;
620 HKEY ControlKey
= NULL
;
621 LPWSTR SystemStartOptions
= NULL
;
622 LPWSTR CurrentOption
, NextOption
; /* Pointers into SystemStartOptions */
623 BOOL ConsoleBoot
= FALSE
;
628 L
"SYSTEM\\CurrentControlSet\\Control",
633 rc
= ReadRegSzKey(ControlKey
, L
"SystemStartOptions", &SystemStartOptions
);
634 if (rc
!= ERROR_SUCCESS
)
637 /* Check for CMDCONS in SystemStartOptions */
638 CurrentOption
= SystemStartOptions
;
639 while (CurrentOption
)
641 NextOption
= wcschr(CurrentOption
, L
' ');
644 if (wcsicmp(CurrentOption
, L
"CONSOLE") == 0)
646 DPRINT("Found %S. Switching to console boot\n", CurrentOption
);
650 CurrentOption
= NextOption
? NextOption
+ 1 : NULL
;
654 if (ControlKey
!= NULL
)
655 RegCloseKey(ControlKey
);
656 HeapFree(GetProcessHeap(), 0, SystemStartOptions
);
665 hSysSetupInf
= SetupOpenInfFileW(
670 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
672 DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
676 if (!InstallSysSetupInfDevices())
678 DebugPrint("InstallSysSetupInfDevices() failed!\n");
679 SetupCloseInfFile(hSysSetupInf
);
683 if(!InstallSysSetupInfComponents())
685 DebugPrint("InstallSysSetupInfComponents() failed!\n");
686 SetupCloseInfFile(hSysSetupInf
);
690 if (!IsConsoleBoot())
695 ShowStatusMessageThread
,
701 if (!EnableUserModePnpManager())
703 DebugPrint("EnableUserModePnpManager() failed!\n");
704 SetupCloseInfFile(hSysSetupInf
);
709 if (CMP_WaitNoPendingInstallEvents(INFINITE
) != WAIT_OBJECT_0
)
711 DebugPrint("CMP_WaitNoPendingInstallEvents() failed!\n");
712 SetupCloseInfFile(hSysSetupInf
);
722 InstallLiveCD(IN HINSTANCE hInstance
)
724 STARTUPINFOW StartupInfo
;
725 PROCESS_INFORMATION ProcessInformation
;
728 if (!CommonInstall())
730 SetupCloseInfFile(hSysSetupInf
);
733 StartupInfo
.cb
= sizeof(STARTUPINFOW
);
734 StartupInfo
.lpReserved
= NULL
;
735 StartupInfo
.lpDesktop
= NULL
;
736 StartupInfo
.lpTitle
= NULL
;
737 StartupInfo
.dwFlags
= 0;
738 StartupInfo
.cbReserved2
= 0;
739 StartupInfo
.lpReserved2
= 0;
740 res
= CreateProcessW(
750 &ProcessInformation
);
759 L
"You can shutdown your computer, or press ENTER to reboot",
767 CreateShortcuts(VOID
)
773 /* Create desktop shortcuts */
774 CreateShortcut(CSIDL_DESKTOP
, NULL
, IDS_SHORT_CMD
, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD
, TRUE
);
775 CreateShortcut(CSIDL_DESKTOP
, NULL
, IDS_SHORT_DOWNLOADER
, _T("%SystemRoot%\\system32\\rapps.exe"), IDS_CMT_DOWNLOADER
, TRUE
);
777 /* Create program startmenu shortcuts */
778 CreateShortcut(CSIDL_PROGRAMS
, NULL
, IDS_SHORT_EXPLORER
, _T("%SystemRoot%\\explorer.exe"), IDS_CMT_EXPLORER
, TRUE
);
779 CreateShortcut(CSIDL_PROGRAMS
, NULL
, IDS_SHORT_DOWNLOADER
, _T("%SystemRoot%\\system32\\rapps.exe"), IDS_CMT_DOWNLOADER
, TRUE
);
781 /* Create administrative tools startmenu shortcuts */
782 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_SERVICE
, _T("%SystemRoot%\\system32\\servman.exe"), IDS_CMT_SERVMAN
, TRUE
);
783 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_DEVICE
, _T("%SystemRoot%\\system32\\devmgmt.exe"), IDS_CMT_DEVMGMT
, TRUE
);
784 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_EVENTVIEW
, _T("%SystemRoot%\\system32\\eventvwr.exe"), IDS_CMT_EVENTVIEW
, TRUE
);
785 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_MSCONFIG
, _T("%SystemRoot%\\system32\\msconfig.exe"), IDS_CMT_MSCONFIG
, TRUE
);
787 /* Create and fill Accessories subfolder */
788 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_ACCESSORIES
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
790 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CALC
, _T("%SystemRoot%\\system32\\calc.exe"), IDS_CMT_CALC
, TRUE
);
791 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CMD
, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD
, TRUE
);
792 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_NOTEPAD
, _T("%SystemRoot%\\system32\\notepad.exe"), IDS_CMT_NOTEPAD
, TRUE
);
793 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_RDESKTOP
, _T("%SystemRoot%\\system32\\mstsc.exe"), IDS_CMT_RDESKTOP
, TRUE
);
794 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNAP
, _T("%SystemRoot%\\system32\\screenshot.exe"), IDS_CMT_SCREENSHOT
, TRUE
);
795 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_WORDPAD
, _T("%SystemRoot%\\system32\\wordpad.exe"), IDS_CMT_WORDPAD
, TRUE
);
796 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_PAINT
, _T("%SystemRoot%\\system32\\paint.exe"), IDS_CMT_PAINT
, TRUE
);
799 /* Create System Tools subfolder and fill if the exe is available */
800 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_TOOLS
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
802 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CHARMAP
, _T("%SystemRoot%\\system32\\charmap.exe"), IDS_CMT_CHARMAP
, TRUE
);
803 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_KBSWITCH
, _T("%SystemRoot%\\system32\\kbswitch.exe"), IDS_CMT_KBSWITCH
, TRUE
);
804 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_REGEDIT
, _T("%SystemRoot%\\regedit.exe"), IDS_CMT_REGEDIT
, TRUE
);
805 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_DXDIAG
, _T("%SystemRoot%\\system32\\dxdiag.exe"), IDS_CMT_DXDIAG
, TRUE
);
808 /* Create Accessibility subfolder and fill if the exe is available */
809 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_ACCESSIBILITY
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
811 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_MAGNIFY
, _T("%SystemRoot%\\system32\\magnify.exe"), IDS_CMT_MAGNIFY
, TRUE
);
814 /* Create Entertainment subfolder and fill if the exe is available */
815 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_ENTERTAINMENT
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
817 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_MPLAY32
, _T("%SystemRoot%\\system32\\mplay32.exe"), IDS_CMT_MPLAY32
, TRUE
);
818 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNDVOL32
, _T("%SystemRoot%\\system32\\sndvol32.exe"), IDS_CMT_SNDVOL32
, TRUE
);
819 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNDREC32
, _T("%SystemRoot%\\system32\\sndrec32.exe"), IDS_CMT_SNDREC32
, TRUE
);
822 /* Create Games subfolder and fill if the exe is available */
823 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_GAMES
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
825 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SOLITAIRE
, _T("%SystemRoot%\\system32\\sol.exe"), IDS_CMT_SOLITAIRE
, TRUE
);
826 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_WINEMINE
, _T("%SystemRoot%\\system32\\winmine.exe"), IDS_CMT_WINEMINE
, TRUE
);
827 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SPIDER
, _T("%SystemRoot%\\system32\\spider.exe"), IDS_CMT_SPIDER
, TRUE
);
836 SetSetupType(DWORD dwSetupType
)
841 dwError
= RegOpenKeyExW(
847 if (dwError
!= ERROR_SUCCESS
)
850 dwError
= RegSetValueExW(
855 (LPBYTE
)&dwSetupType
,
858 if (dwError
!= ERROR_SUCCESS
)
865 InstallReactOS(HINSTANCE hInstance
)
867 TCHAR szBuffer
[MAX_PATH
];
870 TOKEN_PRIVILEGES privs
;
873 InitializeSetupActionLog(FALSE
);
874 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"Installing ReactOS");
876 if (!InitializeProfiles())
878 DebugPrint("InitializeProfiles() failed");
882 if (!CreateShortcuts())
884 DebugPrint("InitializeProfiles() failed");
888 /* Initialize the Security Account Manager (SAM) */
889 if (!SamInitializeSAM())
891 DebugPrint("SamInitializeSAM() failed!");
895 /* Create the semi-random Domain-SID */
896 if (!CreateRandomSid(&DomainSid
))
898 DebugPrint("Domain-SID creation failed!");
902 /* Set the Domain SID (aka Computer SID) */
903 if (!SamSetDomainSid(DomainSid
))
905 DebugPrint("SamSetDomainSid() failed!");
906 RtlFreeSid(DomainSid
);
910 /* Append the Admin-RID */
911 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
913 CreateTempDir(L
"TEMP");
914 CreateTempDir(L
"TMP");
916 if (GetWindowsDirectory(szBuffer
, sizeof(szBuffer
) / sizeof(TCHAR
)))
918 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
919 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
922 &hKey
) == ERROR_SUCCESS
)
929 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
936 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
941 PathAddBackslash(szBuffer
);
942 _tcscat(szBuffer
, _T("system"));
943 CreateDirectory(szBuffer
, NULL
);
946 if (!CommonInstall())
951 /* Create the Administrator account */
952 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
954 /* Check what the error was.
955 * If the Admin Account already exists, then it means Setup
956 * wasn't allowed to finish properly. Instead of rebooting
957 * and not completing it, let it restart instead
959 LastError
= GetLastError();
960 if (LastError
!= ERROR_USER_EXISTS
)
962 DebugPrint("SamCreateUser() failed!");
963 RtlFreeSid(AdminSid
);
964 RtlFreeSid(DomainSid
);
969 RtlFreeSid(AdminSid
);
970 RtlFreeSid(DomainSid
);
972 /* ROS HACK, as long as NtUnloadKey is not implemented */
974 NTSTATUS Status
= NtUnloadKey(NULL
);
975 if (Status
== STATUS_NOT_IMPLEMENTED
)
977 /* Create the Administrator profile */
978 PROFILEINFOW ProfileInfo
;
981 #define LOGON32_LOGON_NETWORK 3
982 ret
= LogonUserW(L
"Administrator", L
"", L
"", LOGON32_LOGON_NETWORK
, LOGON32_PROVIDER_DEFAULT
, &hToken
);
985 DebugPrint("LogonUserW() failed!");
988 ZeroMemory(&ProfileInfo
, sizeof(PROFILEINFOW
));
989 ProfileInfo
.dwSize
= sizeof(PROFILEINFOW
);
990 ProfileInfo
.lpUserName
= L
"Administrator";
991 ProfileInfo
.dwFlags
= PI_NOUI
;
992 LoadUserProfileW(hToken
, &ProfileInfo
);
997 DPRINT1("ROS HACK not needed anymore. Please remove it\n");
1000 /* END OF ROS HACK */
1002 SetupCloseInfFile(hSysSetupInf
);
1005 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"Installing ReactOS done");
1006 TerminateSetupActionLog();
1008 /* Get shutdown privilege */
1009 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &token
))
1011 DebugPrint("OpenProcessToken() failed!");
1014 if (!LookupPrivilegeValue(
1017 &privs
.Privileges
[0].Luid
))
1019 DebugPrint("LookupPrivilegeValue() failed!");
1022 privs
.PrivilegeCount
= 1;
1023 privs
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1024 if (AdjustTokenPrivileges(
1029 (PTOKEN_PRIVILEGES
)NULL
,
1032 DebugPrint("AdjustTokenPrivileges() failed!");
1036 ExitWindowsEx(EWX_REBOOT
, 0);
1045 SetupChangeFontSize(
1047 IN LPCWSTR lpszFontSize
)
1049 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1057 SetupChangeLocaleEx(HWND hWnd
,
1059 LPCWSTR lpSrcRootPath
,
1064 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1072 SetupChangeLocale(HWND hWnd
, LCID Lcid
)
1074 return SetupChangeLocaleEx(hWnd
, Lcid
, NULL
, 0, 0, 0);