Windows reboot/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Windows reboot/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Zurück zur Seite [[code examples/de|Code Beispiele]].\ | |
| 2 | + | ||
| 3 | + | Dieser Artikel beschäftigt sich mit der Windowsprogrammierung.\ | |
| 4 | + | Die Prozedur beendet bzw. rebootet Windows.\ | |
| 5 | + | ||
| 6 | + | ``` pascal | |
| 7 | + | { | |
| 8 | + | Bedeutung der Windowskonstanten: | |
| 9 | + | EWX_LOGOFF | |
| 10 | + | Alle Prozesse des Benutzers werden beendet. | |
| 11 | + | Der Benutzer wird abgemeldet. | |
| 12 | + | ||
| 13 | + | EWX_POWEROFF | |
| 14 | + | Fährt Windows herunter und setzt den Computer in den StandBy-Modus. | |
| 15 | + | (Die Hardware muss dies unterstützen) | |
| 16 | + | ||
| 17 | + | EWX_REBOOT | |
| 18 | + | Fährt Windows herunter und startet es neu | |
| 19 | + | ||
| 20 | + | EWX_SHUTDOWN | |
| 21 | + | Fährt Windows herunter | |
| 22 | + | ||
| 23 | + | EWX_FORCE | |
| 24 | + | Beendet die Prozesse ohne Rückfrage | |
| 25 | + | ||
| 26 | + | EWX_FORCEIFHUNG | |
| 27 | + | Beendet Prozesse mit vorheriger Nachfrage | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | ... | |
| 31 | + | ||
| 32 | + | uses | |
| 33 | + | SysUtils, Windows, Dialogs, ...; | |
| 34 | + | ||
| 35 | + | ... | |
| 36 | + | ||
| 37 | + | const | |
| 38 | + | //Soft-Variante | |
| 39 | + | Logoff = EWX_LOGOFF or EWX_FORCEIFHUNG; | |
| 40 | + | StandBy = EWX_POWEROFF or EWX_FORCEIFHUNG; | |
| 41 | + | Reboot = EWX_REBOOT or EWX_FORCEIFHUNG; | |
| 42 | + | Shutdown = EWX_SHUTDOWN or EWX_FORCEIFHUNG; | |
| 43 | + | ||
| 44 | + | //Harte-Variante | |
| 45 | + | Logoff_F = EWX_LOGOFF or EWX_FORCE; | |
| 46 | + | StandBy_F = EWX_POWEROFF or EWX_FORCE; | |
| 47 | + | Reboot_F = EWX_REBOOT or EWX_FORCE; | |
| 48 | + | Shutdown_F = EWX_SHUTDOWN or EWX_FORCE; | |
| 49 | + | ||
| 50 | + | ... | |
| 51 | + | ||
| 52 | + | implementation | |
| 53 | + | ||
| 54 | + | ... | |
| 55 | + | ||
| 56 | + | function funExitWindows(lwdRebootParam: longword): boolean; | |
| 57 | + | var | |
| 58 | + | hToken: THandle; | |
| 59 | + | TokenPvg1: TTokenPrivileges; | |
| 60 | + | TokenPvg2: TTokenPrivileges; | |
| 61 | + | wrdGroesseTokenPvg2: DWORD; | |
| 62 | + | wrdPcbtpPreviousRequired: DWORD = 0; | |
| 63 | + | blnRueckgabe: boolean; | |
| 64 | + | ||
| 65 | + | begin | |
| 66 | + | ||
| 67 | + | Result := False; | |
| 68 | + | ||
| 69 | + | try | |
| 70 | + | ||
| 71 | + | blnRueckgabe := OpenProcessToken(GetCurrentProcess(), | |
| 72 | + | TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken); | |
| 73 | + | ||
| 74 | + | if blnRueckgabe = True then | |
| 75 | + | begin | |
| 76 | + | blnRueckgabe := LookupPrivilegeValue(nil, 'SeShutdownPrivilege', | |
| 77 | + | TokenPvg1.Privileges[0].Luid); | |
| 78 | + | ||
| 79 | + | TokenPvg1.PrivilegeCount := 1; | |
| 80 | + | TokenPvg1.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; | |
| 81 | + | wrdGroesseTokenPvg2 := SizeOf(TokenPvg2); | |
| 82 | + | ||
| 83 | + | if blnRueckgabe = True then | |
| 84 | + | Windows.AdjustTokenPrivileges(hToken, False, TokenPvg1, | |
| 85 | + | wrdGroesseTokenPvg2, TokenPvg2, wrdPcbtpPreviousRequired); | |
| 86 | + | ||
| 87 | + | end; | |
| 88 | + | ||
| 89 | + | Result := ExitWindowsEx(RebootParam, 0); | |
| 90 | + | ||
| 91 | + | except | |
| 92 | + | ShowMessage('Beim Herunterfahren von Windows ist ein Fehler aufgetreten'); | |
| 93 | + | end; | |
| 94 | + | ||
| 95 | + | end; | |
| 96 | + | ||
| 97 | + | ... | |
| 98 | + | ||
| 99 | + | ``` | |
| 100 | + | ||
| 101 | + | Beispiel für einen Aufruf der Prozedur:\ | |
| 102 | + | ||
| 103 | + | ``` pascal | |
| 104 | + | ... | |
| 105 | + | subExitWindows(Shutdown); | |
| 106 | + | ... | |
| 107 | + | ``` | |
| 108 | + | ||
| 109 | + | --- | |
| 110 | + | *From the Free Pascal wiki, page "Windows reboot/de", as it stood on 2020-03-04 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
