was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

32 Visitors Online


 
...einen Windows Shutdown zeitverzögert durchführen?
Autor: Uri Fridman
Homepage: http://www.geocities.com/urifrid
[ Tip ausdrucken ]  

Tip Bewertung (21):  
     


{
Diese Methode funktioniert nur auf Windows NT/2000/XP
}

{
Works only on Windows NT/2000/XP systems
}

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;

//Start shut down
procedure TForm1.Button1Click(Sender: TObject);
begin
  if not 
TimedShutDown('\\computername', 'you have to shutdown', 30, true, true) then
    
ShowMessage('function failed...');
end;

//Abort shut down
procedure TForm1.Button2Click(Sender: TObject);
begin
  
AbortSystemShutdown('\\computername');
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners