Announcement

Collapse
No announcement yet.

Windows Herunterfahren

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Windows Herunterfahren

    Hallo Forum,

    Ich suche nach einem Befehl (Möglichkeit) Windows2000 aus einem Programm zu beenden (Herunterzufahren)

    Ich kenne diese Befehle:
    ExitWindowsEx(EWX_REBOOT,0);
    ExitWindowsEx(EWX_SHUTDOWN,0);

    Leider funktionieren sie nur unter Win 9x, ME (vielleicht auch NT4)

    Danke, Max

  • #2
    Hi

    http://www.lezim.de/main/programmierung/winc/breakon.htm

    das müsste dir hefen

    MfG

    LezimG

    Comment


    • #3
      Max,

      Du brauchst bei NT oder 2000 die SE_SHUTDOWN_NAME Rechte bevor du die Maschine einfach herunterfahren kannst.

      Das geht so:<br>
      void ShutdownMachine ()<br>
      {<br>
      if (IsWindowsNT())<br>
      {<br>
      HANDLE hToken;<br>
      TOKEN_PRIVILEGES tkp;<br>
      <br>
      // For WindowsNT a process cannot reboot the system <br>without
      // the SE_SHUTDOWN_NAME privilege<br>
      <br>
      // Get a token for this process.<br>
      if (!OpenProcessToken(GetCurrentProcess(), <br>TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))<br>
      return false;<br>

      // Get the LUID for the shutdown privilege.<br>
      LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);<br>

      tkp.PrivilegeCount = 1; // one privilege to set<br>
      tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;<br>

      // Get the shutdown privilege for this process.<br>
      AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);<br>

      // Cannot test the return value of AdjustTokenPrivileges.<br>
      <br>
      if (GetLastError() != ERROR_SUCCESS)<br>
      {<br>
      // Well - you can't expect it to work every time!!!<br>
      return FALSE;<br>
      }<br>
      ExitWindowsEx(EWX_POWEROFF, NULL); // poweroff just works with NT/2000<br>
      }<br>
      <br>
      ExitWindowsEx(EWX_SHUTDOWN, NULL); // poweroff just works with NT/2000<br>
      return true;<br>
      }<br>
      <br>
      <br>
      Die Routine IsWindowsNT ist nur eine eigene Routine, welche TRUE liefert wenn die lokale Maschine ein NT/2000 System ist.<br>
      <br>
      Gruss <br>
      <br>
      Chri

      Comment

      Working...
      X