unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TimedShutDown(Computer: string; Msg: string; Time: Word; Force: Boolean; Reboot: Boolean): Boolean;
var
rl: Cardinal;
hToken: Cardinal;
tkp: TOKEN_PRIVILEGES;
begin
if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then ShowMessage('Cannot open process token.')
else
begin
if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then
begin
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
if GetLastError <> ERROR_SUCCESS then
ShowMessage('Error adjusting process privileges.');
end
else
ShowMessage('Cannot find privilege value.');
end;
Result := InitiateSystemShutdown(PChar(Computer), PChar(Msg), Time, Force, Reboot)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not TimedShutDown('\\blue', '30ÃÊÈÄ¿¡ ½Ã½ºÅÛÀ» Á¾·áÇÕ´Ï´Ù', 30, true, true) then ShowMessage('Chyba, funkci se nepodarilo spustit...');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
// Á¾·á ÇØÁ¦
AbortSystemShutdown('\\blue');
end;
end. |
|