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 *****************************************************************/
42 #include <ndk/cmfuncs.h>
48 CMP_WaitNoPendingInstallEvents(DWORD dwTimeout
);
51 SetupStartService(LPCWSTR lpServiceName
, BOOL bWait
);
53 /* GLOBALS ******************************************************************/
55 HINF hSysSetupInf
= INVALID_HANDLE_VALUE
;
58 /* FUNCTIONS ****************************************************************/
61 FatalError(char *pszFmt
,...)
67 vsprintf(szBuffer
, pszFmt
, ap
);
70 LogItem(NULL
, L
"Failed");
72 strcat(szBuffer
, "\nRebooting now!");
92 HRESULT hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellLink
, (LPVOID
*)&psl
);
96 hr
= IShellLinkW_SetPath(psl
, pszCmd
);
100 hr
= IShellLinkW_SetArguments(psl
, pszArg
);
105 hr
= IShellLinkW_SetWorkingDirectory(psl
, pszDir
);
110 hr
= IShellLinkW_SetIconLocation(psl
, pszIconPath
, iIconNr
);
115 hr
= IShellLinkW_SetDescription(psl
, pszComment
);
118 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
122 hr
= IPersistFile_Save(ppf
, pszLinkPath
, TRUE
);
123 IPersistFile_Release(ppf
);
126 IShellLinkW_Release(psl
);
138 LPCWSTR pszDescription
,
140 LPCWSTR pszWorkingDir
)
142 WCHAR szPath
[MAX_PATH
];
143 WCHAR szExeName
[MAX_PATH
];
144 WCHAR szWorkingDirBuf
[MAX_PATH
];
149 if (ExpandEnvironmentStringsW(pszCommand
, szPath
, ARRAYSIZE(szPath
)) == 0)
151 wcscpy(szPath
, pszCommand
);
154 if (_waccess(szPath
, 0) == -1)
155 /* Expected error, don't return FALSE */
158 dwLen
= GetFullPathNameW(szPath
,
159 ARRAYSIZE(szWorkingDirBuf
),
162 if (dwLen
!= 0 && dwLen
<= ARRAYSIZE(szWorkingDirBuf
))
164 /* Since those should only be called with (.exe) files,
165 lpFilePart has not to be NULL */
166 ASSERT(lpFilePart
!= NULL
);
168 /* Save the file name */
169 wcscpy(szExeName
, lpFilePart
);
171 if (pszWorkingDir
== NULL
|| pszWorkingDir
[0] == L
'\0')
173 /* We're only interested in the path. Cut the file name off.
174 Also remove the trailing backslash unless the working directory
175 is only going to be a drive, ie. C:\ */
176 *(lpFilePart
--) = L
'\0';
177 if (!(lpFilePart
- szWorkingDirBuf
== 2 && szWorkingDirBuf
[1] == L
':' &&
178 szWorkingDirBuf
[2] == L
'\\'))
182 pszWorkingDir
= szWorkingDirBuf
;
185 else if (pszWorkingDir
&& pszWorkingDir
[0] == L
'\0')
187 pszWorkingDir
= NULL
;
190 wcscpy(szPath
, pszFolder
);
192 Ptr
= PathAddBackslash(szPath
);
194 wcscpy(Ptr
, pszName
);
196 // FIXME: we should pass 'command' straight in here, but shell32 doesn't expand it
197 return SUCCEEDED(CreateShellLink(szPath
, szExeName
, L
"", pszWorkingDir
, szExeName
, iIconNr
, pszDescription
));
201 static BOOL
CreateShortcutsFromSection(HINF hinf
, LPWSTR pszSection
, LPCWSTR pszFolder
)
205 WCHAR szCommand
[MAX_PATH
];
206 WCHAR szName
[MAX_PATH
];
207 WCHAR szDescription
[MAX_PATH
];
208 WCHAR szDirectory
[MAX_PATH
];
211 if (!SetupFindFirstLine(hinf
, pszSection
, NULL
, &Context
))
216 dwFieldCount
= SetupGetFieldCount(&Context
);
217 if (dwFieldCount
< 4)
220 if (!SetupGetStringFieldW(&Context
, 1, szCommand
, ARRAYSIZE(szCommand
), NULL
))
223 if (!SetupGetStringFieldW(&Context
, 2, szName
, ARRAYSIZE(szName
), NULL
))
226 if (!SetupGetStringFieldW(&Context
, 3, szDescription
, ARRAYSIZE(szDescription
), NULL
))
229 if (!SetupGetIntField(&Context
, 4, &iIconNr
))
232 if (dwFieldCount
< 5 || !SetupGetStringFieldW(&Context
, 5, szDirectory
, ARRAYSIZE(szDirectory
), NULL
))
233 szDirectory
[0] = L
'\0';
235 wcscat(szName
, L
".lnk");
237 CreateShortcut(pszFolder
, szName
, szCommand
, szDescription
, iIconNr
, szDirectory
);
239 } while (SetupFindNextLine(&Context
, &Context
));
244 static BOOL
CreateShortcuts(HINF hinf
, LPCWSTR szSection
)
247 WCHAR szPath
[MAX_PATH
];
248 WCHAR szFolder
[MAX_PATH
];
249 WCHAR szFolderSection
[MAX_PATH
];
254 if (!SetupFindFirstLine(hinf
, szSection
, NULL
, &Context
))
259 if (SetupGetFieldCount(&Context
) < 2)
262 if (!SetupGetStringFieldW(&Context
, 0, szFolderSection
, ARRAYSIZE(szFolderSection
), NULL
))
265 if (!SetupGetIntField(&Context
, 1, &csidl
))
268 if (!SetupGetStringFieldW(&Context
, 2, szFolder
, ARRAYSIZE(szFolder
), NULL
))
271 if (FAILED(SHGetFolderPathAndSubDirW(NULL
, csidl
|CSIDL_FLAG_CREATE
, (HANDLE
)-1, SHGFP_TYPE_DEFAULT
, szFolder
, szPath
)))
274 CreateShortcutsFromSection(hinf
, szFolderSection
, szPath
);
276 } while (SetupFindNextLine(&Context
, &Context
));
287 WCHAR szTempDir
[MAX_PATH
];
288 WCHAR szBuffer
[MAX_PATH
];
292 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
293 L
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
296 &hKey
) != ERROR_SUCCESS
)
298 FatalError("Error: %lu\n", GetLastError());
303 dwLength
= sizeof(szBuffer
);
304 if (RegQueryValueExW(hKey
,
309 &dwLength
) != ERROR_SUCCESS
)
311 FatalError("Error: %lu\n", GetLastError());
316 if (!ExpandEnvironmentStringsW(szBuffer
, szTempDir
, ARRAYSIZE(szTempDir
)))
318 FatalError("Error: %lu\n", GetLastError());
322 /* Create profiles directory */
323 if (!CreateDirectoryW(szTempDir
, NULL
))
325 if (GetLastError() != ERROR_ALREADY_EXISTS
)
327 FatalError("Error: %lu\n", GetLastError());
337 InstallSysSetupInfDevices(VOID
)
339 INFCONTEXT InfContext
;
340 WCHAR szLineBuffer
[256];
343 if (!SetupFindFirstLineW(hSysSetupInf
,
344 L
"DeviceInfsToInstall",
353 if (!SetupGetStringFieldW(&InfContext
,
356 ARRAYSIZE(szLineBuffer
),
362 if (!SetupDiInstallClassW(NULL
, szLineBuffer
, DI_QUIETINSTALL
, NULL
))
367 while (SetupFindNextLine(&InfContext
, &InfContext
));
373 InstallSysSetupInfComponents(VOID
)
375 INFCONTEXT InfContext
;
376 WCHAR szNameBuffer
[256];
377 WCHAR szSectionBuffer
[256];
378 HINF hComponentInf
= INVALID_HANDLE_VALUE
;
380 if (!SetupFindFirstLineW(hSysSetupInf
,
385 DPRINT("No Inf.Always section found\n");
391 if (!SetupGetStringFieldW(&InfContext
,
392 1, // Get the component name
394 ARRAYSIZE(szNameBuffer
),
397 FatalError("Error while trying to get component name \n");
401 if (!SetupGetStringFieldW(&InfContext
,
402 2, // Get the component install section
404 ARRAYSIZE(szSectionBuffer
),
407 FatalError("Error while trying to get component install section \n");
411 DPRINT("Trying to execute install section '%S' from '%S' \n", szSectionBuffer
, szNameBuffer
);
413 hComponentInf
= SetupOpenInfFileW(szNameBuffer
,
418 if (hComponentInf
== INVALID_HANDLE_VALUE
)
420 FatalError("SetupOpenInfFileW() failed to open '%S' (Error: %lu)\n", szNameBuffer
, GetLastError());
424 if (!SetupInstallFromInfSectionW(NULL
,
431 SetupDefaultQueueCallbackW
,
436 FatalError("Error while trying to install : %S (Error: %lu)\n", szNameBuffer
, GetLastError());
437 SetupCloseInfFile(hComponentInf
);
441 SetupCloseInfFile(hComponentInf
);
443 while (SetupFindNextLine(&InfContext
, &InfContext
));
452 RegisterTypeLibraries (HINF hinf
, LPCWSTR szSection
)
454 INFCONTEXT InfContext
;
456 WCHAR szName
[MAX_PATH
];
457 WCHAR szPath
[MAX_PATH
];
463 /* Begin iterating the entries in the inf section */
464 res
= SetupFindFirstLine(hinf
, szSection
, NULL
, &InfContext
);
465 if (!res
) return FALSE
;
469 /* Get the name of the current type library */
470 if (!SetupGetStringFieldW(&InfContext
, 1, szName
, ARRAYSIZE(szName
), NULL
))
472 FatalError("SetupGetStringFieldW failed\n");
476 if (!SetupGetIntField(&InfContext
, 2, &csidl
))
477 csidl
= CSIDL_SYSTEM
;
479 hret
= SHGetFolderPathW(NULL
, csidl
, NULL
, 0, szPath
);
482 FatalError("SHGetFolderPathW failed hret=0x%lx\n", hret
);
486 p
= PathAddBackslash(szPath
);
489 hmod
= LoadLibraryW(szName
);
492 FatalError("LoadLibraryW failed\n");
496 __wine_register_resources(hmod
);
498 } while (SetupFindNextLine(&InfContext
, &InfContext
));
504 EnableUserModePnpManager(VOID
)
506 SC_HANDLE hSCManager
= NULL
;
507 SC_HANDLE hService
= NULL
;
510 hSCManager
= OpenSCManagerW(NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
);
511 if (hSCManager
== NULL
)
513 DPRINT1("Unable to open the service control manager.\n");
514 DPRINT1("Last Error %d\n", GetLastError());
518 hService
= OpenServiceW(hSCManager
,
520 SERVICE_CHANGE_CONFIG
| SERVICE_START
);
521 if (hService
== NULL
)
523 DPRINT1("Unable to open PlugPlay service\n");
527 bRet
= ChangeServiceConfigW(hService
,
532 NULL
, NULL
, NULL
, NULL
);
535 DPRINT1("Unable to change the service configuration\n");
539 bRet
= StartServiceW(hService
, 0, NULL
);
540 if (!bRet
&& (GetLastError() != ERROR_SERVICE_ALREADY_RUNNING
))
542 DPRINT1("Unable to start service\n");
549 if (hService
!= NULL
)
550 CloseServiceHandle(hService
);
551 if (hSCManager
!= NULL
)
552 CloseServiceHandle(hSCManager
);
556 static INT_PTR CALLBACK
557 StatusMessageWindowProc(
563 UNREFERENCED_PARAMETER(wParam
);
571 if (!LoadStringW(hDllInstance
, IDS_STATUS_INSTALL_DEV
, szMsg
, ARRAYSIZE(szMsg
)))
573 SetDlgItemTextW(hwndDlg
, IDC_STATUSLABEL
, szMsg
);
581 ShowStatusMessageThread(
582 IN LPVOID lpParameter
)
584 HWND
*phWnd
= (HWND
*)lpParameter
;
588 hWnd
= CreateDialogParam(hDllInstance
,
589 MAKEINTRESOURCE(IDD_STATUSWINDOW_DLG
),
591 StatusMessageWindowProc
,
597 ShowWindow(hWnd
, SW_SHOW
);
599 /* Message loop for the Status window */
600 while (GetMessage(&Msg
, NULL
, 0, 0))
602 TranslateMessage(&Msg
);
603 DispatchMessage(&Msg
);
621 return ERROR_INVALID_PARAMETER
;
624 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, &dwType
, NULL
, &cbData
);
625 if (rc
!= ERROR_SUCCESS
)
627 if (dwType
!= REG_SZ
)
628 return ERROR_FILE_NOT_FOUND
;
629 pwszValue
= HeapAlloc(GetProcessHeap(), 0, cbData
+ sizeof(WCHAR
));
631 return ERROR_NOT_ENOUGH_MEMORY
;
632 rc
= RegQueryValueExW(hKey
, pszKey
, NULL
, NULL
, (LPBYTE
)pwszValue
, &cbData
);
633 if (rc
!= ERROR_SUCCESS
)
635 HeapFree(GetProcessHeap(), 0, pwszValue
);
638 /* NULL-terminate the string */
639 pwszValue
[cbData
/ sizeof(WCHAR
)] = '\0';
642 return ERROR_SUCCESS
;
648 HKEY hControlKey
= NULL
;
649 LPWSTR pwszSystemStartOptions
= NULL
;
650 LPWSTR pwszCurrentOption
, pwszNextOption
; /* Pointers into SystemStartOptions */
651 BOOL bConsoleBoot
= FALSE
;
654 rc
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
655 L
"SYSTEM\\CurrentControlSet\\Control",
659 if (rc
!= ERROR_SUCCESS
)
662 rc
= ReadRegSzKey(hControlKey
, L
"SystemStartOptions", &pwszSystemStartOptions
);
663 if (rc
!= ERROR_SUCCESS
)
666 /* Check for CONSOLE switch in SystemStartOptions */
667 pwszCurrentOption
= pwszSystemStartOptions
;
668 while (pwszCurrentOption
)
670 pwszNextOption
= wcschr(pwszCurrentOption
, L
' ');
672 *pwszNextOption
= L
'\0';
673 if (wcsicmp(pwszCurrentOption
, L
"CONSOLE") == 0)
675 DPRINT("Found %S. Switching to console boot\n", pwszCurrentOption
);
679 pwszCurrentOption
= pwszNextOption
? pwszNextOption
+ 1 : NULL
;
683 if (hControlKey
!= NULL
)
684 RegCloseKey(hControlKey
);
685 if (pwszSystemStartOptions
)
686 HeapFree(GetProcessHeap(), 0, pwszSystemStartOptions
);
695 hSysSetupInf
= SetupOpenInfFileW(L
"syssetup.inf",
699 if (hSysSetupInf
== INVALID_HANDLE_VALUE
)
701 FatalError("SetupOpenInfFileW() failed to open 'syssetup.inf' (Error: %lu)\n", GetLastError());
705 if (!InstallSysSetupInfDevices())
707 FatalError("InstallSysSetupInfDevices() failed!\n");
711 if(!InstallSysSetupInfComponents())
713 FatalError("InstallSysSetupInfComponents() failed!\n");
717 if (!IsConsoleBoot())
721 hThread
= CreateThread(NULL
,
723 ShowStatusMessageThread
,
728 CloseHandle(hThread
);
731 if (!EnableUserModePnpManager())
733 FatalError("EnableUserModePnpManager() failed!\n");
737 if (CMP_WaitNoPendingInstallEvents(INFINITE
) != WAIT_OBJECT_0
)
739 FatalError("CMP_WaitNoPendingInstallEvents() failed!\n");
749 SetupCloseInfFile(hSysSetupInf
);
753 /* Install a section of a .inf file
754 * Returns TRUE if success, FALSE if failure. Error code can
755 * be retrieved with GetLastError()
762 IN LPCWSTR InfSection OPTIONAL
,
763 IN LPCWSTR InfService OPTIONAL
)
765 WCHAR Buffer
[MAX_PATH
];
766 HINF hInf
= INVALID_HANDLE_VALUE
;
768 PVOID Context
= NULL
;
771 /* Get Windows directory */
772 BufferSize
= ARRAYSIZE(Buffer
) - 5 - wcslen(InfFile
);
773 if (GetWindowsDirectoryW(Buffer
, BufferSize
) > BufferSize
)
775 /* Function failed */
776 SetLastError(ERROR_GEN_FAILURE
);
779 /* We have enough space to add some information in the buffer */
780 if (Buffer
[wcslen(Buffer
) - 1] != '\\')
781 wcscat(Buffer
, L
"\\");
782 wcscat(Buffer
, L
"Inf\\");
783 wcscat(Buffer
, InfFile
);
785 /* Install specified section */
786 hInf
= SetupOpenInfFileW(Buffer
, NULL
, INF_STYLE_WIN4
, NULL
);
787 if (hInf
== INVALID_HANDLE_VALUE
)
790 Context
= SetupInitDefaultQueueCallback(hWnd
);
795 if (ret
&& InfSection
)
797 ret
= SetupInstallFromInfSectionW(
799 InfSection
, SPINST_ALL
,
800 NULL
, NULL
, SP_COPY_NEWER
,
801 SetupDefaultQueueCallbackW
, Context
,
804 if (ret
&& InfService
)
806 ret
= SetupInstallServicesFromInfSectionW(hInf
, InfService
, 0);
811 SetupTermDefaultQueueCallback(Context
);
812 if (hInf
!= INVALID_HANDLE_VALUE
)
813 SetupCloseInfFile(hInf
);
818 InstallLiveCD(IN HINSTANCE hInstance
)
820 STARTUPINFOW StartupInfo
;
821 PROCESS_INFORMATION ProcessInformation
;
824 /* Hack: Install TCP/IP protocol driver */
825 bRes
= InstallInfSection(NULL
,
827 L
"MS_TCPIP.PrimaryInstall",
828 L
"MS_TCPIP.PrimaryInstall.Services");
829 if (!bRes
&& GetLastError() != ERROR_FILE_NOT_FOUND
)
831 DPRINT("InstallInfSection() failed with error 0x%lx\n", GetLastError());
835 /* Start the TCP/IP protocol driver */
836 SetupStartService(L
"Tcpip", FALSE
);
839 if (!CommonInstall())
842 /* Register components */
845 if (!SetupInstallFromInfSectionW(NULL
,
846 hSysSetupInf
, L
"RegistrationPhase2",
848 0, NULL
, 0, NULL
, NULL
, NULL
, NULL
))
850 DPRINT1("SetupInstallFromInfSectionW failed!\n");
853 RegisterTypeLibraries(hSysSetupInf
, L
"TypeLibraries");
855 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
857 DPRINT1("Catching exception\n");
861 SetupCloseInfFile(hSysSetupInf
);
864 ZeroMemory(&StartupInfo
, sizeof(StartupInfo
));
865 StartupInfo
.cb
= sizeof(StartupInfo
);
866 bRes
= CreateProcessW(L
"userinit.exe",
875 &ProcessInformation
);
879 CloseHandle(ProcessInformation
.hThread
);
880 CloseHandle(ProcessInformation
.hProcess
);
887 L
"Failed to load LiveCD! You can shutdown your computer, or press ENTER to reboot.",
895 SetSetupType(DWORD dwSetupType
)
900 dwError
= RegOpenKeyExW(
906 if (dwError
!= ERROR_SUCCESS
)
909 dwError
= RegSetValueExW(
914 (LPBYTE
)&dwSetupType
,
917 if (dwError
!= ERROR_SUCCESS
)
923 static DWORD CALLBACK
924 HotkeyThread(LPVOID Parameter
)
929 DPRINT("HotkeyThread start\n");
931 hotkey
= GlobalAddAtomW(L
"Setup Shift+F10 Hotkey");
933 if (!RegisterHotKey(NULL
, hotkey
, MOD_SHIFT
, VK_F10
))
934 DPRINT1("RegisterHotKey failed with %lu\n", GetLastError());
936 while (GetMessage(&msg
, NULL
, 0, 0))
938 if (msg
.hwnd
== NULL
&& msg
.message
== WM_HOTKEY
&& msg
.wParam
== hotkey
)
940 STARTUPINFOW si
= { sizeof(si
) };
941 PROCESS_INFORMATION pi
;
943 if (CreateProcessW(L
"cmd.exe",
954 CloseHandle(pi
.hProcess
);
955 CloseHandle(pi
.hThread
);
959 DPRINT1("Failed to launch command prompt: %lu\n", GetLastError());
964 UnregisterHotKey(NULL
, hotkey
);
965 GlobalDeleteAtom(hotkey
);
967 DPRINT("HotkeyThread terminate\n");
974 InitializeDefaultUserLocale(VOID
)
984 struct {LCTYPE LCType
; PWSTR pValue
;} LocaleData
[] = {
986 {LOCALE_SDECIMAL
, L
"sDecimal"},
987 {LOCALE_STHOUSAND
, L
"sThousand"},
988 {LOCALE_SNEGATIVESIGN
, L
"sNegativeSign"},
989 {LOCALE_SPOSITIVESIGN
, L
"sPositiveSign"},
990 {LOCALE_SGROUPING
, L
"sGrouping"},
991 {LOCALE_SLIST
, L
"sList"},
992 {LOCALE_SNATIVEDIGITS
, L
"sNativeDigits"},
993 {LOCALE_INEGNUMBER
, L
"iNegNumber"},
994 {LOCALE_IDIGITS
, L
"iDigits"},
995 {LOCALE_ILZERO
, L
"iLZero"},
996 {LOCALE_IMEASURE
, L
"iMeasure"},
997 {LOCALE_IDIGITSUBSTITUTION
, L
"NumShape"},
1000 {LOCALE_SCURRENCY
, L
"sCurrency"},
1001 {LOCALE_SMONDECIMALSEP
, L
"sMonDecimalSep"},
1002 {LOCALE_SMONTHOUSANDSEP
, L
"sMonThousandSep"},
1003 {LOCALE_SMONGROUPING
, L
"sMonGrouping"},
1004 {LOCALE_ICURRENCY
, L
"iCurrency"},
1005 {LOCALE_INEGCURR
, L
"iNegCurr"},
1006 {LOCALE_ICURRDIGITS
, L
"iCurrDigits"},
1009 {LOCALE_STIMEFORMAT
, L
"sTimeFormat"},
1010 {LOCALE_STIME
, L
"sTime"},
1011 {LOCALE_S1159
, L
"s1159"},
1012 {LOCALE_S2359
, L
"s2359"},
1013 {LOCALE_ITIME
, L
"iTime"},
1014 {LOCALE_ITIMEMARKPOSN
, L
"iTimePrefix"},
1015 {LOCALE_ITLZERO
, L
"iTLZero"},
1018 {LOCALE_SLONGDATE
, L
"sLongDate"},
1019 {LOCALE_SSHORTDATE
, L
"sShortDate"},
1020 {LOCALE_SDATE
, L
"sDate"},
1021 {LOCALE_IFIRSTDAYOFWEEK
, L
"iFirstDayOfWeek"},
1022 {LOCALE_IFIRSTWEEKOFYEAR
, L
"iFirstWeekOfYear"},
1023 {LOCALE_IDATE
, L
"iDate"},
1024 {LOCALE_ICALENDARTYPE
, L
"iCalendarType"},
1027 {LOCALE_SCOUNTRY
, L
"sCountry"},
1028 {LOCALE_SLANGUAGE
, L
"sLanguage"},
1029 {LOCALE_ICOUNTRY
, L
"iCountry"},
1032 ret
= RegOpenKeyExW(HKEY_USERS
,
1033 L
".DEFAULT\\Control Panel\\International",
1035 KEY_READ
| KEY_WRITE
,
1037 if (ret
!= ERROR_SUCCESS
)
1042 dwSize
= 9 * sizeof(WCHAR
);
1043 ret
= RegQueryValueExW(hLocaleKey
,
1049 if (ret
!= ERROR_SUCCESS
)
1052 lcid
= (LCID
)wcstoul(szBuffer
, &ptr
, 16);
1057 while (LocaleData
[i
].pValue
!= NULL
)
1059 if (GetLocaleInfoW(lcid
,
1060 LocaleData
[i
].LCType
| LOCALE_NOUSEROVERRIDE
,
1062 ARRAYSIZE(szBuffer
)))
1064 RegSetValueExW(hLocaleKey
,
1065 LocaleData
[i
].pValue
,
1069 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1076 RegCloseKey(hLocaleKey
);
1082 InstallReactOS(HINSTANCE hInstance
)
1084 WCHAR szBuffer
[MAX_PATH
];
1086 TOKEN_PRIVILEGES privs
;
1089 HANDLE hHotkeyThread
;
1092 InitializeSetupActionLog(FALSE
);
1093 LogItem(NULL
, L
"Installing ReactOS");
1095 if (!InitializeProfiles())
1097 FatalError("InitializeProfiles() failed");
1101 CreateTempDir(L
"TEMP");
1102 CreateTempDir(L
"TMP");
1104 InitializeDefaultUserLocale();
1106 if (GetWindowsDirectoryW(szBuffer
, ARRAYSIZE(szBuffer
)))
1108 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1109 L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
1112 &hKey
) == ERROR_SUCCESS
)
1114 RegSetValueExW(hKey
,
1119 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1121 RegSetValueExW(hKey
,
1126 (wcslen(szBuffer
) + 1) * sizeof(WCHAR
));
1131 PathAddBackslash(szBuffer
);
1132 wcscat(szBuffer
, L
"system");
1133 CreateDirectory(szBuffer
, NULL
);
1136 hHotkeyThread
= CreateThread(NULL
, 0, HotkeyThread
, NULL
, 0, NULL
);
1138 /* Hack: Install TCP/IP protocol driver */
1139 ret
= InstallInfSection(NULL
,
1141 L
"MS_TCPIP.PrimaryInstall",
1142 L
"MS_TCPIP.PrimaryInstall.Services");
1143 if (!ret
&& GetLastError() != ERROR_FILE_NOT_FOUND
)
1145 DPRINT("InstallInfSection() failed with error 0x%lx\n", GetLastError());
1149 /* Start the TCP/IP protocol driver */
1150 SetupStartService(L
"Tcpip", FALSE
);
1154 if (!CommonInstall())
1161 SetAutoAdminLogon();
1163 hShortcutsInf
= SetupOpenInfFileW(L
"shortcuts.inf",
1167 if (hShortcutsInf
== INVALID_HANDLE_VALUE
)
1169 FatalError("Failed to open shortcuts.inf");
1173 if (!CreateShortcuts(hShortcutsInf
, L
"ShortcutFolders"))
1175 FatalError("CreateShortcuts() failed");
1179 SetupCloseInfFile(hShortcutsInf
);
1181 SetupCloseInfFile(hSysSetupInf
);
1186 PostThreadMessage(GetThreadId(hHotkeyThread
), WM_QUIT
, 0, 0);
1187 CloseHandle(hHotkeyThread
);
1190 LogItem(NULL
, L
"Installing ReactOS done");
1191 TerminateSetupActionLog();
1193 if (AdminInfo
.Name
!= NULL
)
1194 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Name
);
1196 if (AdminInfo
.Domain
!= NULL
)
1197 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Domain
);
1199 if (AdminInfo
.Password
!= NULL
)
1200 RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo
.Password
);
1202 /* Get shutdown privilege */
1203 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &token
))
1205 FatalError("OpenProcessToken() failed!");
1208 if (!LookupPrivilegeValue(NULL
,
1210 &privs
.Privileges
[0].Luid
))
1212 FatalError("LookupPrivilegeValue() failed!");
1215 privs
.PrivilegeCount
= 1;
1216 privs
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1217 if (AdjustTokenPrivileges(token
,
1221 (PTOKEN_PRIVILEGES
)NULL
,
1224 FatalError("AdjustTokenPrivileges() failed!");
1228 ExitWindowsEx(EWX_REBOOT
, 0);
1237 SetupChangeFontSize(
1239 IN LPCWSTR lpszFontSize
)
1241 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1249 SetupChangeLocaleEx(HWND hWnd
,
1251 LPCWSTR lpSrcRootPath
,
1256 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1264 SetupChangeLocale(HWND hWnd
, LCID Lcid
)
1266 return SetupChangeLocaleEx(hWnd
, Lcid
, NULL
, 0, 0, 0);
1273 LPCWSTR lpServiceName
,
1276 SC_HANDLE hManager
= NULL
;
1277 SC_HANDLE hService
= NULL
;
1278 DWORD dwError
= ERROR_SUCCESS
;
1280 hManager
= OpenSCManagerW(NULL
,
1282 SC_MANAGER_ALL_ACCESS
);
1283 if (hManager
== NULL
)
1285 dwError
= GetLastError();
1289 hService
= OpenServiceW(hManager
,
1292 if (hService
== NULL
)
1294 dwError
= GetLastError();
1298 if (!StartService(hService
, 0, NULL
))
1300 dwError
= GetLastError();
1305 if (hService
!= NULL
)
1306 CloseServiceHandle(hService
);
1308 if (hManager
!= NULL
)
1309 CloseServiceHandle(hManager
);