Double click on Button1, fill in the following code in the code form ::
void __fastcall TForm1 :: Button1Click (TObject * Sender) {HANDLE hToken; TOKEN_PRIVILEGES tkp; OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, & hToken); LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME, & tkp.Privileges [0] .Luid); tkp.PrivilegeCount = 1; Tkp.Privileges [0] .attributes = se_privilege_enabled; AdjustTokenPrivileges (HToken, False, & Tkp, 0, (ptoken_privileges) null, 0);
// Option thereof in several actions.
// EXITWINDOWSEX (EWX_LOGOFF, 0); // Logouts the current user // exitwindowsex (ewx_reboot, 0); // Restart system EXITWINDOWSEX (EWX_SHUTDOWN, 0); // Normal shutdown system // EXITWINDOWSEX (EWX_Poweroff, 0); / / Exit the Windows system and turn off the machine power (ATX specification only) // exitWindowSex (force, 0); // Force turn off system // exitWindowSex (forceifhung, 0); // windows2000 and its later version support for a forcibly shut down system
}