reactos操作系统实现(68)

前面介绍怎么样调用动态连接库里的InstallReactOS函数,下面就来分析这个函数的代码,看看这个函数是怎么运行向导界面,又做了些什么样的工作。如下:

#001  DWORD WINAPI

#002  InstallReactOS(HINSTANCE hInstance)

#003  {

#004      TCHAR szBuffer[MAX_PATH];

#005      DWORD LastError;

#006      HANDLE token;

#007      TOKEN_PRIVILEGES privs;

#008 

 

ReactOS目录里创建安装的LOG文件。

#009      InitializeSetupActionLog(FALSE);

#010      LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS");

#011 

 

初始化注册配置相关项。

#012      if (!InitializeProfiles())

#013      {

#014          DebugPrint("InitializeProfiles() failed");

#015          return 0;

#016      }

#017 

 

创建桌面、菜单、文件关联的快捷方式。

#018      if (!CreateShortcuts())

#019      {

#020          DebugPrint("InitializeProfiles() failed");

#021          return 0;

#022      }

#023 

 

创建安全相关的帐号管理。

#024      /* Initialize the Security Account Manager (SAM) */

#025      if (!SamInitializeSAM())

#026      {

#027          DebugPrint("SamInitializeSAM() failed!");

#028          return 0;

#029      }

#030 

 

为安装用户提供一个随便的电脑名称。

#031      /* Create the semi-random Domain-SID */

#032      if (!CreateRandomSid(&DomainSid))

#033      {

#034          DebugPrint("Domain-SID creation failed!");

#035          return 0;

#036      }

#037 

 

把这个电脑名称保存到注册表。

#038      /* Set the Domain SID (aka Computer SID) */

#039      if (!SamSetDomainSid(DomainSid))

#040      {

#041          DebugPrint("SamSetDomainSid() failed!");

#042          RtlFreeSid(DomainSid);

#043          return 0;

#044      }

#045 

#046      /* Append the Admin-RID */

#047      AppendRidToSid(&AdminSid, DomainSid, DOMAIN_USER_RID_ADMIN);

#048 

 

创建管理员帐号。

#049      /* Create the Administrator account */

#050      if (!SamCreateUser(L"Administrator", L"", AdminSid))

#051      {

#052          /* Check what the error was.

#053           * If the Admin Account already exists, then it means Setup

#054           * wasn't allowed to finish properly. Instead of rebooting

#055           * and not completing it, let it restart instead

#056           */

#057          LastError = GetLastError();

#058          if (LastError != ERROR_USER_EXISTS)

#059          {

#060              DebugPrint("SamCreateUser() failed!");

#061              RtlFreeSid(AdminSid);

#062              RtlFreeSid(DomainSid);

#063              return 0;

#064          }

#065      }

#066 

#067      RtlFreeSid(AdminSid);

#068      RtlFreeSid(DomainSid);

#069 

 

以管理员的帐号登录。

#070      /* ROS HACK, as long as NtUnloadKey is not implemented */

#071      {

#072          NTSTATUS Status = NtUnloadKey(NULL);

#073          if (Status == STATUS_NOT_IMPLEMENTED)

#074          {

#075              /* Create the Administrator profile */

#076              PROFILEINFOW ProfileInfo;

#077              HANDLE hToken;

#078              BOOL ret;

#079  #define LOGON32_LOGON_NETWORK 3

#080              ret = LogonUserW(L"Administrator", L"", L"", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &hToken);

#081              if (!ret)

#082              {

#083                  DebugPrint("LogonUserW() failed!");

#084                  return 0;

#085              }

#086              ZeroMemory(&ProfileInfo, sizeof(PROFILEINFOW));

#087              ProfileInfo.dwSize = sizeof(PROFILEINFOW);

#088              ProfileInfo.lpUserName = L"Administrator";

#089              ProfileInfo.dwFlags = PI_NOUI;

#090              LoadUserProfileW(hToken, &ProfileInfo);

#091              CloseHandle(hToken);

#092          }

#093          else

#094          {

#095              DPRINT1("ROS HACK not needed anymore. Please remove it/n");

#096          }

#097      }

#098      /* END OF ROS HACK */

#099 

 

创建系统工作的临时目录。

#100      CreateTempDir(L"TEMP");

#101      CreateTempDir(L"TMP");

#102 

 

创建system目录。

#103      if (GetWindowsDirectory(szBuffer, sizeof(szBuffer) / sizeof(TCHAR)))

#104      {

#105          PathAddBackslash(szBuffer);

#106          _tcscat(szBuffer, _T("system"));

#107          CreateDirectory(szBuffer, NULL);

#108      }

#109 

 

根据syssetup.inf文件来安装相应的组件,还安装PNP管理器。

#110      if (!CommonInstall())

#111          return 0;

#112 

 

初始化让用户选择输入参数的向导界面。

#113      InstallWizard();

#114 

 

关闭syssetup.inf文件。

#115      SetupCloseInfFile(hSysSetupInf);

 

设置系统安装的类型。

#116      SetSetupType(0);

#117 

#118      LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS done");

 

关闭安装的LOG文件。

#119      TerminateSetupActionLog();

#120 

 

获取关闭系统的特权。

#121      /* Get shutdown privilege */

#122      if (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))

#123      {

#124          DebugPrint("OpenProcessToken() failed!");

#125          return 0;

#126      }

#127      if (!LookupPrivilegeValue(

#128          NULL,

#129          SE_SHUTDOWN_NAME,

#130          &privs.Privileges[0].Luid))

#131      {

#132          DebugPrint("LookupPrivilegeValue() failed!");

#133          return 0;

#134      }

#135      privs.PrivilegeCount = 1;

#136      privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

#137      if (AdjustTokenPrivileges(

#138          token,

#139          FALSE,

#140          &privs,

#141          0,

#142          (PTOKEN_PRIVILEGES)NULL,

#143          NULL) == 0)

#144      {

#145          DebugPrint("AdjustTokenPrivileges() failed!");

#146          return 0;

#147      }

#148 

 

退系统,并重新启动。

#149      ExitWindowsEx(EWX_REBOOT, 0);

#150      return 0;

#151  }

你可能感兴趣的:(react)