Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
AutoRestart
|
Kategori: System
Inlagt: 2007-12-26
Läst: 1882
Inlagt av: Mange
|
Beskrivning |
Ett tips om AutoRestart.
|
Kod |
unit Unit_con7; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TAutoRestart = class(TForm) GroupBox1: TGroupBox; Aktifkan: TRadioButton; Panel1: TPanel; ApplyBtn: TButton; procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure ApplyBtnClick(Sender: TObject); private function SetPrivilage(sPrivilageName: String; bEnabled: Boolean): Boolean; function WinExit(iFlags: integer): Boolean; procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QUERYENDSESSION; procedure WMEndSession(var Msg: TWMEndSession); message WM_ENDSESSION; procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; public { Public declarations } end; var AutoRestart: TAutoRestart; MsgResult: integer; implementation {$R *.dfm} function TAutoRestart.SetPrivilage(sPrivilageName: String; bEnabled: Boolean): Boolean; var TPPrev, TP: TTokenPrivileges; Token : THandle; dwRetLen: DWORD; begin Result:= False; OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, Token); TP.PrivilegeCount:= 1; if (LookupPrivilegeValue(nil, PChar(sPrivilageName), TP.Privileges[0].LUID)) then begin if bEnabled then begin TP.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED; end else begin TP.Privileges[0].Attributes:= 0; end; dwRetLen:= 0; Result:= AdjustTokenPrivileges(Token, False, TP, SizeOf(TPPrev), TPPrev, dwRetLen); end; CloseHandle(Token); end; function TAutoRestart.WinExit(iFlags: integer): Boolean; begin Result:= True; if SetPrivilage('SeShutdownPrivilege', True) then begin if not (ExitWindowsEx(iFlags, 0)) then Result:= False; SetPrivilage('SeShutdownPrivilege', False); end else Result:= False; end; procedure TAutoRestart.WMNCHitTest(var Message: TWMNCHitTest); begin inherited; with Message do if Result = HTCAPTION then Result := HTNOWHERE; end; procedure TAutoRestart.WMQueryEndSession(var Msg: TWMQueryEndSession); begin if(Aktifkan.Checked) then Msg.Result:= 0 else Msg.Result:= 1; MsgResult:= Msg.Result; end; procedure TAutoRestart.WMEndSession(var Msg: TWMEndSession); begin if (MsgResult=0) then begin if not(Msg.EndSession) then begin PostMessage(Handle, WM_QUERYENDSESSION, 0, 0); WinExit(EWX_REBOOT); Refresh; Application.Terminate; end else ShowMessage('What Are u Doing..; inherited; end else ShowMessage('Do Nothing'); end; procedure TAutoRestart.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose:= False; end; procedure TAutoRestart.ApplyBtnClick(Sender: TObject); begin AutoRestart.Hide; end; end.
|
|
|