Return to Snippet

Revision: 29647
at August 2, 2010 18:05 by icebob


Initial Code
function TimedShutDown(Computer: string; Msg: string; Time: Word; Force: Boolean; Reboot: Boolean): Boolean;
var
  rl: Cardinal;
  hToken: Cardinal;
  tkp: TOKEN_PRIVILEGES;
begin
  //get user privileges to shutdown the machine, we are talking about win nt and 2k here
  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;

Initial URL


Initial Description


Initial Title
Shutdown the (local or remote) computer (with delay)

Initial Tags


Initial Language
Delphi