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 SERVICE_STATUS_PROCESS ServiceStatus
;
477 SC_HANDLE hSCManager
= NULL
;
478 SC_HANDLE hService
= NULL
;
479 DWORD dwStartTickCount
;
480 DWORD dwOldCheckPoint
;
481 DWORD BytesNeeded
= 0;
486 hSCManager
= OpenSCManager(NULL
, NULL
, 0);
487 if (hSCManager
== NULL
)
490 hService
= OpenServiceW(hSCManager
,
492 SERVICE_CHANGE_CONFIG
| SERVICE_START
| SERVICE_QUERY_STATUS
);
493 if (hService
== NULL
)
496 ret
= ChangeServiceConfigW(hService
,
501 NULL
, NULL
, NULL
, NULL
);
505 ret
= StartServiceW(hService
, 0, NULL
);
508 /* If the service is already running, just return TRUE */
509 ret
= GetLastError() == ERROR_SERVICE_ALREADY_RUNNING
;
513 ret
= QueryServiceStatusEx(hService
,
514 SC_STATUS_PROCESS_INFO
,
515 (LPBYTE
)&ServiceStatus
,
516 sizeof(SERVICE_STATUS_PROCESS
),
521 /* We don't want to wait for more than 30 seconds */
523 dwStartTickCount
= GetTickCount();
525 /* Loop until it's running */
526 while (ServiceStatus
.dwCurrentState
!= SERVICE_RUNNING
)
528 dwOldCheckPoint
= ServiceStatus
.dwCheckPoint
;
529 dwWaitTime
= ServiceStatus
.dwWaitHint
/ 10;
531 /* Get the latest status info */
532 if (!QueryServiceStatusEx(hService
,
533 SC_STATUS_PROCESS_INFO
,
534 (LPBYTE
)&ServiceStatus
,
535 sizeof(SERVICE_STATUS_PROCESS
),
538 /* Something went wrong... */
542 /* Is the service making progress? */
543 if (ServiceStatus
.dwCheckPoint
> dwOldCheckPoint
)
545 /* It is, get the latest tickcount to reset the max wait time */
546 dwStartTickCount
= GetTickCount();
547 dwOldCheckPoint
= ServiceStatus
.dwCheckPoint
;
551 /* It's not, make sure we haven't exceeded our wait time */
552 if (GetTickCount() >= dwStartTickCount
+ dwMaxWait
)
554 /* We have, give up */
559 /* Adjust the wait hint times */
560 if (dwWaitTime
< 200)
562 else if (dwWaitTime
> 10000)
565 /* Wait before trying again */
569 ret
= ServiceStatus
.dwCurrentState
== SERVICE_RUNNING
;
572 if (hSCManager
!= NULL
)
573 CloseServiceHandle(hSCManager
);
574 if (hService
!= NULL
)
575 CloseServiceHandle(hService
);
581 StatusMessageWindowProc(
587 UNREFERENCED_PARAMETER(wParam
);
595 if (!LoadStringW(hDllInstance
, IDS_STATUS_INSTALL_DEV
, szMsg
, sizeof(szMsg
)/sizeof(szMsg
[0])))
597 SetDlgItemTextW(hwndDlg
, IDC_STATUSLABEL
, szMsg
);
606 ShowStatusMessageThread(
607 IN LPVOID lpParameter
)
609 HWND
*phWnd
= (HWND
*)lpParameter
;
613 hWnd
= CreateDialogParam(
615 MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG
),
617 StatusMessageWindowProc
,
623 ShowWindow(hWnd
, SW_SHOW
);
625 /* Message loop for the Status window */
626 while (GetMessage(&Msg
, NULL
, 0, 0))
628 TranslateMessage(&Msg
);
629 DispatchMessage(&Msg
);
647 return ERROR_INVALID_PARAMETER
;
650 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
651 if (rc
!= ERROR_SUCCESS
)
653 if (dwType
!= REG_SZ
)
654 return ERROR_FILE_NOT_FOUND
;
655 Value
= HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
657 return ERROR_NOT_ENOUGH_MEMORY
;
658 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)Value
, &cbData
);
659 if (rc
!= ERROR_SUCCESS
)
661 HeapFree(GetProcessHeap(), 0, Value
);
664 /* NULL-terminate the string */
665 Value
[cbData
/ sizeof(WCHAR
)] = '\0';
668 return ERROR_SUCCESS
;
674 HKEY ControlKey
= NULL
;
675 LPWSTR SystemStartOptions
= NULL
;
676 LPWSTR CurrentOption
, NextOption
; /* Pointers into SystemStartOptions */
677 BOOL ConsoleBoot
= FALSE
;
682 L
"SYSTEM\\CurrentControlSet\\Control",
687 rc
= ReadRegSzKey(ControlKey
, L
"SystemStartOptions", &SystemStartOptions
);
688 if (rc
!= ERROR_SUCCESS
)
691 /* Check for CMDCONS in SystemStartOptions */
692 CurrentOption
= SystemStartOptions
;
693 while (CurrentOption
)
695 NextOption
= wcschr(CurrentOption
, L
' ');
698 if (wcsicmp(CurrentOption
, L
"CONSOLE") == 0)
700 DPRINT("Found %S. Switching to console boot\n", CurrentOption
);
704 CurrentOption
= NextOption
? NextOption
+ 1 : NULL
;
708 if (ControlKey
!= NULL
)
709 RegCloseKey(ControlKey
);
710 HeapFree(GetProcessHeap(), 0, SystemStartOptions
);
719 hSysSetupInf
= SetupOpenInfFileW(
724 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
726 DebugPrint("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
730 if (!InstallSysSetupInfDevices())
732 DebugPrint("InstallSysSetupInfDevices() failed!\n");
733 SetupCloseInfFile(hSysSetupInf
);
737 if(!InstallSysSetupInfComponents())
739 DebugPrint("InstallSysSetupInfComponents() failed!\n");
740 SetupCloseInfFile(hSysSetupInf
);
744 if (!IsConsoleBoot())
749 ShowStatusMessageThread
,
755 if (!EnableUserModePnpManager())
757 DebugPrint("EnableUserModePnpManager() failed!\n");
758 SetupCloseInfFile(hSysSetupInf
);
763 if (CMP_WaitNoPendingInstallEvents(INFINITE
) != WAIT_OBJECT_0
)
765 DebugPrint("CMP_WaitNoPendingInstallEvents() failed!\n");
766 SetupCloseInfFile(hSysSetupInf
);
776 InstallLiveCD(IN HINSTANCE hInstance
)
778 STARTUPINFOW StartupInfo
;
779 PROCESS_INFORMATION ProcessInformation
;
782 if (!CommonInstall())
784 SetupCloseInfFile(hSysSetupInf
);
787 StartupInfo
.cb
= sizeof(STARTUPINFOW
);
788 StartupInfo
.lpReserved
= NULL
;
789 StartupInfo
.lpDesktop
= NULL
;
790 StartupInfo
.lpTitle
= NULL
;
791 StartupInfo
.dwFlags
= 0;
792 StartupInfo
.cbReserved2
= 0;
793 StartupInfo
.lpReserved2
= 0;
794 res
= CreateProcessW(
804 &ProcessInformation
);
813 L
"You can shutdown your computer, or press ENTER to reboot",
821 CreateShortcuts(VOID
)
827 /* Create desktop shortcuts */
828 CreateShortcut(CSIDL_DESKTOP
, NULL
, IDS_SHORT_CMD
, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD
, TRUE
);
830 /* Create program startmenu shortcuts */
831 CreateShortcut(CSIDL_PROGRAMS
, NULL
, IDS_SHORT_EXPLORER
, _T("%SystemRoot%\\explorer.exe"), IDS_CMT_EXPLORER
, TRUE
);
832 CreateShortcut(CSIDL_PROGRAMS
, NULL
, IDS_SHORT_DOWNLOADER
, _T("%SystemRoot%\\system32\\rapps.exe"), IDS_CMT_DOWNLOADER
, TRUE
);
834 /* Create administrative tools startmenu shortcuts */
835 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_SERVICE
, _T("%SystemRoot%\\system32\\servman.exe"), IDS_CMT_SERVMAN
, TRUE
);
836 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_DEVICE
, _T("%SystemRoot%\\system32\\devmgmt.exe"), IDS_CMT_DEVMGMT
, TRUE
);
837 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_EVENTVIEW
, _T("%SystemRoot%\\system32\\eventvwr.exe"), IDS_CMT_EVENTVIEW
, TRUE
);
838 CreateShortcut(CSIDL_COMMON_ADMINTOOLS
, NULL
, IDS_SHORT_MSCONFIG
, _T("%SystemRoot%\\system32\\msconfig.exe"), IDS_CMT_MSCONFIG
, TRUE
);
840 /* Create and fill Accessories subfolder */
841 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_ACCESSORIES
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
843 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CALC
, _T("%SystemRoot%\\system32\\calc.exe"), IDS_CMT_CALC
, TRUE
);
844 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CMD
, _T("%SystemRoot%\\system32\\cmd.exe"), IDS_CMT_CMD
, TRUE
);
845 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_NOTEPAD
, _T("%SystemRoot%\\system32\\notepad.exe"), IDS_CMT_NOTEPAD
, TRUE
);
846 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_RDESKTOP
, _T("%SystemRoot%\\system32\\mstsc.exe"), IDS_CMT_RDESKTOP
, TRUE
);
847 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNAP
, _T("%SystemRoot%\\system32\\screenshot.exe"), IDS_CMT_SCREENSHOT
, TRUE
);
848 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_WORDPAD
, _T("%SystemRoot%\\system32\\wordpad.exe"), IDS_CMT_WORDPAD
, TRUE
);
849 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_PAINT
, _T("%SystemRoot%\\system32\\paint.exe"), IDS_CMT_PAINT
, TRUE
);
852 /* Create System Tools subfolder and fill if the exe is available */
853 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_TOOLS
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
855 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_CHARMAP
, _T("%SystemRoot%\\system32\\charmap.exe"), IDS_CMT_CHARMAP
, TRUE
);
856 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_KBSWITCH
, _T("%SystemRoot%\\system32\\kbswitch.exe"), IDS_CMT_KBSWITCH
, TRUE
);
857 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_REGEDIT
, _T("%SystemRoot%\\regedit.exe"), IDS_CMT_REGEDIT
, TRUE
);
858 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_DXDIAG
, _T("%SystemRoot%\\system32\\dxdiag.exe"), IDS_CMT_DXDIAG
, TRUE
);
861 /* Create Accessibility subfolder and fill if the exe is available */
862 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_ACCESSIBILITY
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
864 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_MAGNIFY
, _T("%SystemRoot%\\system32\\magnify.exe"), IDS_CMT_MAGNIFY
, TRUE
);
867 /* Create Entertainment subfolder and fill if the exe is available */
868 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_SYS_ENTERTAINMENT
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
870 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_MPLAY32
, _T("%SystemRoot%\\system32\\mplay32.exe"), IDS_CMT_MPLAY32
, TRUE
);
871 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNDVOL32
, _T("%SystemRoot%\\system32\\sndvol32.exe"), IDS_CMT_SNDVOL32
, TRUE
);
872 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SNDREC32
, _T("%SystemRoot%\\system32\\sndrec32.exe"), IDS_CMT_SNDREC32
, TRUE
);
875 /* Create Games subfolder and fill if the exe is available */
876 if (CreateShortcutFolder(CSIDL_PROGRAMS
, IDS_GAMES
, szFolder
, sizeof(szFolder
)/sizeof(szFolder
[0])))
878 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SOLITAIRE
, _T("%SystemRoot%\\system32\\sol.exe"), IDS_CMT_SOLITAIRE
, TRUE
);
879 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_WINEMINE
, _T("%SystemRoot%\\system32\\winemine.exe"), IDS_CMT_WINEMINE
, TRUE
);
880 CreateShortcut(CSIDL_PROGRAMS
, szFolder
, IDS_SHORT_SPIDER
, _T("%SystemRoot%\\system32\\spider.exe"), IDS_CMT_SPIDER
, TRUE
);
889 SetSetupType(DWORD dwSetupType
)
894 dwError
= RegOpenKeyExW(
900 if (dwError
!= ERROR_SUCCESS
)
903 dwError
= RegSetValueExW(
908 (LPBYTE
)&dwSetupType
,
911 if (dwError
!= ERROR_SUCCESS
)
918 InstallReactOS(HINSTANCE hInstance
)
920 TCHAR szBuffer
[MAX_PATH
];
923 TOKEN_PRIVILEGES privs
;
925 InitializeSetupActionLog(FALSE
);
926 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"Installing ReactOS");
928 if (!InitializeProfiles())
930 DebugPrint("InitializeProfiles() failed");
934 if (!CreateShortcuts())
936 DebugPrint("InitializeProfiles() failed");
940 /* Initialize the Security Account Manager (SAM) */
941 if (!SamInitializeSAM())
943 DebugPrint("SamInitializeSAM() failed!");
947 /* Create the semi-random Domain-SID */
948 if (!CreateRandomSid(&DomainSid
))
950 DebugPrint("Domain-SID creation failed!");
954 /* Set the Domain SID (aka Computer SID) */
955 if (!SamSetDomainSid(DomainSid
))
957 DebugPrint("SamSetDomainSid() failed!");
958 RtlFreeSid(DomainSid
);
962 /* Append the Admin-RID */
963 AppendRidToSid(&AdminSid
, DomainSid
, DOMAIN_USER_RID_ADMIN
);
965 CreateTempDir(L
"TEMP");
966 CreateTempDir(L
"TMP");
968 if (GetWindowsDirectory(szBuffer
, sizeof(szBuffer
) / sizeof(TCHAR
)))
970 PathAddBackslash(szBuffer
);
971 _tcscat(szBuffer
, _T("system"));
972 CreateDirectory(szBuffer
, NULL
);
975 if (!CommonInstall())
980 /* Create the Administrator account */
981 if (!SamCreateUser(L
"Administrator", L
"", AdminSid
))
983 /* Check what the error was.
984 * If the Admin Account already exists, then it means Setup
985 * wasn't allowed to finish properly. Instead of rebooting
986 * and not completing it, let it restart instead
988 LastError
= GetLastError();
989 if (LastError
!= ERROR_USER_EXISTS
)
991 DebugPrint("SamCreateUser() failed!");
992 RtlFreeSid(AdminSid
);
993 RtlFreeSid(DomainSid
);
998 RtlFreeSid(AdminSid
);
999 RtlFreeSid(DomainSid
);
1001 /* ROS HACK, as long as NtUnloadKey is not implemented */
1003 NTSTATUS Status
= NtUnloadKey(NULL
);
1004 if (Status
== STATUS_NOT_IMPLEMENTED
)
1006 /* Create the Administrator profile */
1007 PROFILEINFOW ProfileInfo
;
1010 #define LOGON32_LOGON_NETWORK 3
1011 ret
= LogonUserW(L
"Administrator", L
"", L
"", LOGON32_LOGON_NETWORK
, LOGON32_PROVIDER_DEFAULT
, &hToken
);
1014 DebugPrint("LogonUserW() failed!");
1017 ZeroMemory(&ProfileInfo
, sizeof(PROFILEINFOW
));
1018 ProfileInfo
.dwSize
= sizeof(PROFILEINFOW
);
1019 ProfileInfo
.lpUserName
= L
"Administrator";
1020 ProfileInfo
.dwFlags
= PI_NOUI
;
1021 LoadUserProfileW(hToken
, &ProfileInfo
);
1022 CloseHandle(hToken
);
1026 DPRINT1("ROS HACK not needed anymore. Please remove it\n");
1029 /* END OF ROS HACK */
1031 SetupCloseInfFile(hSysSetupInf
);
1034 LogItem(SYSSETUP_SEVERITY_INFORMATION
, L
"Installing ReactOS done");
1035 TerminateSetupActionLog();
1037 /* Get shutdown privilege */
1038 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &token
))
1040 DebugPrint("OpenProcessToken() failed!");
1043 if (!LookupPrivilegeValue(
1046 &privs
.Privileges
[0].Luid
))
1048 DebugPrint("LookupPrivilegeValue() failed!");
1051 privs
.PrivilegeCount
= 1;
1052 privs
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1053 if (AdjustTokenPrivileges(
1058 (PTOKEN_PRIVILEGES
)NULL
,
1061 DebugPrint("AdjustTokenPrivileges() failed!");
1065 ExitWindowsEx(EWX_REBOOT
, 0);
1074 SetupChangeFontSize(
1076 IN LPCWSTR lpszFontSize
)
1078 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1086 SetupChangeLocaleEx(HWND hWnd
,
1088 LPCWSTR lpSrcRootPath
,
1093 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1101 SetupChangeLocale(HWND hWnd
, LCID Lcid
)
1103 return SetupChangeLocaleEx(hWnd
, Lcid
, NULL
, 0, 0, 0);