unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs, jclsecurity,
ExtCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer, IdSocketHandle;
type
TAutoShutDown =
class(TService)
Timer1: TTimer;
IdUDPServer1: TIdUDPServer;
Timer2: TTimer;
Timer3: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ServiceCreate(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
function GetServiceController: TServiceController;
override;
{ Public-Deklarationen }
end;
var
AutoShutDown: TAutoShutDown;
implementation
{$R *.DFM}
function ExitWin(flag:word): Boolean;
var vi : TOSVersionInfo;
hToken : THandle;
tp : TTokenPrivileges;
h : DWord;
begin
//result := false;
vi.dwOSVersionInfoSize:=SizeOf(vi);
GetVersionEx(vi);
if vi.dwPlatformId = VER_PLATFORM_WIN32_NT
then // Windows NT
begin
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,hToken);
LookupPrivilegeValue(
nil,'
SeShutdownPrivilege',
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);
result := ExitWindowsEx(flag,0);
end
else // Windows 95
begin
Result := ExitWindowsEx(flag,0);
end;
end;
procedure ServiceController(CtrlCode: DWord);
stdcall;
begin
AutoShutDown.Controller(CtrlCode);
end;
function TAutoShutDown.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TAutoShutDown.Timer1Timer(Sender: TObject);
begin
SendMessage(FindWindow(
nil, '
Windows Task-Manager'), WM_CLOSE, 0, 0);
end;
procedure TAutoShutDown.ServiceCreate(Sender: TObject);
begin
if IsAdministrator=false
then
begin
Timer1.Enabled:=true;
end;
end;
procedure TAutoShutDown.IdUDPServer1UDPRead(Sender: TObject;
AData: TStream; ABinding: TIdSocketHandle);
var
x:
string;
t:integer;
begin
AData.Position:=0;
SetLength(x,AData.Size);
AData.ReadBuffer(x[1],AData.Size);
if copy(x,1,2)='
AA'
then
begin
ExitWin(EWX_SHUTDOWN);
Timer2.Enabled:=true;
end;
if copy(x,1,2)='
AB'
then
begin
ExitWin(EWX_LOGOFF);
end;
end;