Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.6 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // MSOOBE.CPP - WinMain and initialization code for MSOOBE stub EXE
  7. //
  8. // HISTORY:
  9. //
  10. // 1/27/99 a-jaswed Created.
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <util.h>
  16. #include "msoobe.h"
  17. /*******************************************************************
  18. NAME: WinMain
  19. SYNOPSIS: App entry point
  20. ********************************************************************/
  21. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  22. {
  23. int iReturn = 0;
  24. int iCount = 0;
  25. PTEB pteb = NULL;
  26. WCHAR szLogfile[MAX_PATH];
  27. ExpandEnvironmentStrings(
  28. L"%SystemRoot%\\system32\\oobe\\msoobe.err",
  29. szLogfile,
  30. sizeof(szLogfile)/sizeof(szLogfile[0]));
  31. //
  32. // call our DLL to run the OOBE
  33. //
  34. HINSTANCE hObMain;
  35. do
  36. {
  37. hObMain = LoadLibrary(OOBE_MAIN_DLL);
  38. if (hObMain)
  39. {
  40. iCount = 0;
  41. PFNMsObWinMain pfnWinMain = NULL;
  42. if (pfnWinMain = (PFNMsObWinMain)GetProcAddress(hObMain, MSOBMAIN_ENTRY))
  43. {
  44. iReturn = pfnWinMain(hInstance, hPrevInstance, GetCommandLine( ), nCmdShow);
  45. }
  46. FreeLibrary(hObMain);
  47. }
  48. else
  49. {
  50. TCHAR szMsg[256];
  51. TCHAR szCount[10];
  52. wsprintf(szMsg, TEXT("LoadLibrary(OOBE_MAIN_DLL) failed. GetLastError=%d"), GetLastError());
  53. wsprintf(szCount, L"Failure%d",iCount);
  54. WritePrivateProfileString(szCount, L"LoadLibrary", szMsg,szLogfile);
  55. pteb = NtCurrentTeb();
  56. if (pteb)
  57. {
  58. wsprintf(szMsg, TEXT("Teb.LastStatusValue = %lx"), pteb->LastStatusValue);
  59. WritePrivateProfileString(szCount, L"NtCurrentTeb" ,szMsg,szLogfile);
  60. }
  61. iCount++;
  62. }
  63. } while ((hObMain == NULL) && (iCount <= 10)); // && (iMsgRet == IDYES));
  64. if (iCount > 10)
  65. {
  66. #define REGSTR_PATH_SYSTEMSETUPKEY L"System\\Setup"
  67. #define REGSTR_VALUE_SETUPTYPE L"SetupType"
  68. #define REGSTR_VALUE_SHUTDOWNREQUIRED L"SetupShutdownRequired"
  69. HKEY hKey;
  70. // failed 10 times to LoadLibrary msobmain.dll, tell the user
  71. WCHAR szTitle [MAX_PATH] = L"\0";
  72. WCHAR szMsg [MAX_PATH] = L"\0";
  73. DWORD dwValue = 2;
  74. // Make sure Winlogon starts us again.
  75. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_SYSTEMSETUPKEY,
  76. 0,KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
  77. {
  78. RegSetValueEx(hKey, REGSTR_VALUE_SETUPTYPE, 0, REG_DWORD,
  79. (BYTE*)&dwValue, sizeof(dwValue) );
  80. dwValue = ShutdownReboot;
  81. RegSetValueEx(hKey, REGSTR_VALUE_SHUTDOWNREQUIRED, 0,
  82. REG_DWORD, (BYTE*)&dwValue, sizeof(dwValue)
  83. );
  84. }
  85. #ifdef PRERELEASE
  86. LoadString(GetModuleHandle(NULL), IDS_APPNAME, szTitle, MAX_PATH);
  87. LoadString(GetModuleHandle(NULL), IDS_SETUPFAILURE, szMsg, MAX_PATH);
  88. MessageBox(NULL, szMsg, szTitle, MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
  89. #endif
  90. }
  91. ExitProcess(iReturn);
  92. return iReturn;
  93. }