Announcement

Collapse
No announcement yet.

Windows 2000 herunterfahren

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

  • Windows 2000 herunterfahren

    Wie kann ich meinen Win 2000 Rechner herunterfahren?
    Weiß das es mit ExitWindowsEx(EWX_Shutdown,0)geht aber ich brauche noch irgend ein Privileg.
    Wie setze ich dieses?

  • #2
    Benutz doch einfach mal die Suchfunktion.
    Das Thema wurde schon einige Male behandelt

    Comment


    • #3
      Entschuldige das späte Posten, habe dein Problem gerade erst gesehen.
      <pre><font color="#000000"><b>type</b></font>
      TRebootOperation = (reLogOff, reReboot, reShutDown, reSuspend, reHibernate);

      <font color="#000000"><b>type</b></font>
      TWinExit = <font color="#000000"><b>class</b></font>(TComponent)
      <font color="#000000"><b>protected</b></font>
      FOperation: TRebootOperation;
      FPowerOff: boolean;
      FForceTerminateProcesses: boolean;
      <font color="#000000"><b>function</b></font> SetShutdownPrivilege(Enable: boolean): boolean;
      <font color="#000000"><b>public</b></font>
      <font color="#000000"><b>constructor</b></font> Create(AOwner: TComponent); <font color="#000000"><b>override</b></font>;
      <font color="#000000"><b>function</b></font> Execute: boolean;
      <font color="#000000"><b>published</b></font>
      <font color="#000000"><b>property</b></font> Operation: TRebootOperation <font color="#000000"><b>read</b></font> FOperation <font color="#000000"><b>write</b></font> FOperation <font color="#000000"><b>default</b></font> reReboot;
      <font color="#000000"><b>property</b></font> PowerOff: boolean <font color="#000000"><b>read</b></font> FPowerOff <font color="#000000"><b>write</b></font> FPowerOff <font color="#000000"><b>default</b></font> false;
      <font color="#000000"><b>property</b></font> ForceTerminateProcesses: boolean <font color="#000000"><b>read</b></font> FForceTerminateProcesses <font color="#000000"><b>write</b></font> FForceTerminateProcesses <font color="#000000"><b>default</b></font> false;
      <font color="#000000"><b>end</b></font>;

      <font color="#000000"><b>implementation</b></font>

      <font color="#000000"><b>const</b></font> cRebootFlags: <font color="#000000"><b>array</b></font>[TRebootOperation] <font color="#000000"><b>of</b></font> integer = (EWX_LOGOFF, EWX_REBOOT, EWX_SHUTDOWN, <font color="#0000FF">0</font>, <font color="#0000FF">0</font>);
      cPowerOff = EWX_POWEROFF;
      cForceTerminateProcesses = EWX_FORCE;
      cPrivilegeName = <font color="#000080">'SeShutdownPrivilege'</font>;

      <font color="#000000"><b>constructor</b></font> TWinExit.Create(AOwner: TComponent);
      <font color="#000000"><b>begin</b></font>
      <font color="#000000"><b>inherited</b></font> Create(AOwner);
      Operation:= reReboot;
      PowerOff:= false;
      ForceTerminateProcesses:= false;
      <font color="#000000"><b>end</b></font>;
      </pre>
      MfG Ol

      Comment


      • #4
        Teil 2
        <pre><font color="#000000"><b>function</b></font> TWinExit.SetShutdownPrivilege(Enable: boolean): boolean;
        <font color="#000000"><b>var</b></font> PrevPrivileges: TTokenPrivileges;
        Privileges: TTokenPrivileges;
        Token: THandle;
        dwRetLen: DWord;
        <font color="#000000"><b>begin</b></font>
        Result:= False;
        OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES <font color="#000000"><b>or</b></font> TOKEN_QUERY, Token);
        Privileges.PrivilegeCount:= <font color="#0000FF">1</font>;
        <font color="#000000"><b>if</b></font> LookupPrivilegeValue(<font color="#000000"><b>nil</b></font>, PChar(cPrivilegeName), Privileges.Privileges[<font color="#0000FF">0</font>].LUID) <font color="#000000"><b>then</b></font>
        <font color="#000000"><b>begin</b></font>
        <font color="#000000"><b>if</b></font> Enable <font color="#000000"><b>then</b></font> Privileges.Privileges[<font color="#0000FF">0</font>].Attributes:= SE_PRIVILEGE_ENABLED
        <font color="#000000"><b>else</b></font> Privileges.Privileges[<font color="#0000FF">0</font>].Attributes:= <font color="#0000FF">0</font>;
        dwRetLen:= <font color="#0000FF">0</font>;
        Result:= AdjustTokenPrivileges(Token, False, Privileges, SizeOf(PrevPrivileges), PrevPrivileges, dwRetLen);
        <font color="#000000"><b>end</b></font>;
        CloseHandle(Token);
        <font color="#000000"><b>end</b></font>;

        <font color="#000000"><b>function</b></font> TWinExit.Execute: boolean;
        <font color="#000000"><b>var</b></font> Flags: integer;
        <font color="#000000"><b>begin</b></font>
        SetShutdownPrivilege(true);
        <font color="#000000"><b>if</b></font> Operation <font color="#000000"><b>in</b></font> [reLogOff..reShutDown] <font color="#000000"><b>then</b></font>
        <font color="#000000"><b>begin</b></font>
        Flags:= cRebootFlags[FOperation];
        <font color="#000000"><b>if</b></font> FPowerOff <font color="#000000"><b>then</b></font> Flags:= Flags <font color="#000000"><b>or</b></font> cPowerOff;
        <font color="#000000"><b>if</b></font> FForceTerminateProcesses <font color="#000000"><b>then</b></font> Flags:= Flags <font color="#000000"><b>or</b></font> cForceTerminateProcesses;
        Result:= ExitWindowsEx(Flags, <font color="#0000FF">0</font>);
        <font color="#000000"><b>end</b></font> <font color="#000000"><b>else</b></font> Result:= SetSystemPowerState(Operation = reSuspend, FForceTerminateProcesses);
        SetShutdownPrivilege(false);
        <font color="#000000"><b>end</b></font>;</pre>
        MfG Ol

        Comment


        • #5
          <B>ExitWindowsEX(EWX_FORCE,0);</B&gt

          Comment


          • #6
            @Ole: das geht auch ein bisschen einfacher - trotz der Rechte. )<br><br>
            @GruppeCN: ist das ´ne Frage oder ´ne Antwort? Wenn es eine Antwort ist, dann fehlen zur vollständigen Lösung aber 90%. Das hättest du (ihr? wg. Gruppe) aber wissen können, wenn du das erste Posting richtig gelesen hättest:<br><br>
            <i>&gt;&gt; Wie kann ich meinen Win 2000 Rechner herunterfahren?<br>
            &gt;&gt; Weiß das es mit <b>ExitWindowsEx(EWX_Shutdown,0)</b> geht<br>
            &gt;&gt; aber ich brauche noch irgend ein Privileg.<br>
            &gt;&gt; Wie setze ich dieses?</i><br><br>
            Gruß,<br>
            Mathias

            Comment

            Working...
            X