View

MFC redemarrer Windows

  1. // Fonction pour redemarrer Windows avec les MFC
  2. void RestartWindows(void)
  3. {
  4.         // Declaration
  5.         HANDLE hToken;
  6.         TOKEN_PRIVILEGES tkp;
  7.         // Get a token for this process.
  8.         OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
  9.         // Get the LUID for the shutdown privilege. 
  10.         LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);
  11.         tkp.PrivilegeCount = 1// one privilege to set   
  12.         tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  13.         // Get the shutdown privilege for this process. 
  14.         AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
  15.         // Shut down the system and force all applications to close. 
  16.         ExitWindowsEx(EWX_REBOOT| EWX_FORCE, 0);
  17. }

You may also like