1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Windows 98/2000/XP Power Off or Reboot

Discussion in 'Delphi Programming' started by AdminDF, Feb 14, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Code:
    function MyExitWindows(RebootParam: Longword): Boolean;
    var
    TTokenHd: THandle;
    TTokenPvg: TTokenPrivileges;
    cbtpPrevious: DWORD;
    rTTokenPvg: TTokenPrivileges;
    pcbtpPreviousRequired: DWORD;
    tpResult: Boolean;
    const
    SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
    begin
    if Win32Platform = VER_PLATFORM_WIN32_NT then
    begin
    tpResult := OpenProcessToken(GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
    TTokenHd);
    if tpResult then
    begin
    tpResult := LookupPrivilegeValue(nil,
    SE_SHUTDOWN_NAME,
    TTokenPvg.Privileges[0].Luid);
    TTokenPvg.PrivilegeCount := 1;
    TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    cbtpPrevious := SizeOf(rTTokenPvg);
    pcbtpPreviousRequired := 0;
    if tpResult then
    Windows.AdjustTokenPrivileges(TTokenHd,
    False,
    TTokenPvg,
    cbtpPrevious,
    rTTokenPvg,
    pcbtpPreviousRequired);
    end;
    end;
    Result := ExitWindowsEx(RebootParam, 0);
    end;
    
    // Example to shutdown Windows:
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    MyExitWindows(EWX_POWEROFF or EWX_FORCE);
    end;
    
    // Example to reboot Windows:
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    MyExitWindows(EWX_REBOOT or EWX_FORCE);
    end;
     

Share This Page