程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi重啟,關閉注銷計算機的實現

Delphi重啟,關閉注銷計算機的實現

編輯:Delphi

Delphi重啟電腦、關閉計算機、注銷(退出當前用戶用其它用戶重新登錄系統)功能的實現代碼,在Delphi中算是比較基礎的例子了,程序運行後,窗體上有對應的控制按鈕,測試時候要注意哦,如果點擊關閉或重啟,電腦就會執行該項命令,要保存好你需要保存的內容。

vIEw source print? 01 unit MainUnit; 02 interface 03 uses 04   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 05   StdCtrls; 06 type 07   TMainForm = class(TForm) 08     Button1: TButton; 09     Button2: TButton; 10     Button3: TButton; 11     procedure Button1Click(Sender: TObject); 12     procedure Button2Click(Sender: TObject); 13     procedure Button3Click(Sender: TObject); 14   private 15     procedure GetPrivilege; 16     { Private declarations } 17   public 18     { Public declarations } 19   end; 20 var 21   MainForm: TMainForm; 22 implementation 23 {$R *.DFM} 24 procedure TMainForm.GetPrivilege; 25 var 26   NewState:       TTokenPrivileges; 27   lpLuid:         Int64; 28   ReturnLength:   DWord; 29   ToKenHandle:    Cardinal; 30 begin 31   OpenProcessToken(GetCurrentProcess, 32                    TOKEN_ADJUST_PRIVILEGES 33                    OR TOKEN_ALL_Access 34                    OR STANDARD_RIGHTS_REQUIRED 35                    OR TOKEN_QUERY,ToKenHandle); 36   LookupPrivilegeValue(nil,'SeShutdownPrivilege',lpLuid); 37   NewState.PrivilegeCount:=1; 38   NewState.Privileges[0].Luid:=lpLuid; 39   NewState.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED; 40   ReturnLength:=0; 41   AdjustTokenPrivileges(ToKenHandle,False,NewState,0,nil,ReturnLength); 42 end; 43 procedure TMainForm.Button1Click(Sender: TObject); 44 begin 45   GetPrivilege; 46   ExitWindowsEx(EWX_REBOOT OR EWX_POWEROFF, 0); 47 end; 48 procedure TMainForm.Button2Click(Sender: TObject); 49 begin 50   GetPrivilege; 51   ExitWindowsEx(EWX_SHUTDOWN OR EWX_POWEROFF, 0); 52 end; 53 procedure TMainForm.Button3Click(Sender: TObject); 54 begin 55   ExitWindowsEx(EWX_LOGOFF, 0); 56 end; 57 end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved