whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

77 Visitors Online


 
...shutdown a computer through a network connection?
Autor: Manfred Ruzicka
[ Print tip ]  

Tip Rating (26):  
     


{-----------------------------------------------------------------------------
 Unit Name: shutdown
 Author:    Manfred Ruzicka
 Description: Mit diese Unit ist es möglich Betriebssysteme die auf Windows NT
              basieren herunterzufahren.
-----------------------------------------------------------------------------}


unit shutdown;

interface

uses
  
Windows,
  StdCtrls;

procedure shut(system, nachricht: string; force, reboot: Boolean; countdown: Integer);
procedure abortshut(system: string);

implementation

const
  
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
var
  
hdlg: DWORD = 0;

procedure shut(system, nachricht: string; force, reboot: Boolean; countdown: Integer);
var
  
otoken, hToken: THandle;
  tp: TTokenPrivileges;
  h: DWORD;
begin
  
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken);
  otoken := htoken;
  LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, tp.Privileges[0].luid);
  tp.privilegecount := 1;
  tp.privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
  h := 0;
  AdjustTokenPrivileges(hToken, False, tp, 0, PTokenPrivileges(nil)^, h);
  InitiateSystemShutdown(PChar(system), PChar(nachricht), countdown, force, reboot);
  tp.privilegecount := 1;
  tp.privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
  h := 0;
  AdjustTokenPrivileges(oToken, False, tp, 0, PTokenPrivileges(nil)^, h);
  CloseHandle(hToken);
end;

procedure abortshut(system: string);
var
  
hToken: THandle;
  tp: TTokenPrivileges;
  h: DWORD;
begin
  
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken);
  LookupPrivilegeValue(PChar(system), SE_SHUTDOWN_NAME, tp.Privileges[0].luid);
  tp.privilegecount := 1;
  tp.privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
  h := 0;
  AdjustTokenPrivileges(hToken, False, tp, 0, PTokenPrivileges(nil)^, h);
  CloseHandle(hToken);
  abortSystemShutdown(PChar(system));
end;

end.


 

Rate this tip:

poor
very good


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