There are two servers in the unit, and there is a timed function in a BIOS, while the other is not. So the first thing after going to the unit every morning is to press the power switch of this server to boot, not even annoying! Today, a Timer Network Wake-up Service (Service) program is written, installed on the first server, so when the first server is started, if it goes, it will automatically send WAKEOONLINE (WOL) broadcast box to wake up. Another server.
step:
Start Delphi, File-New-Other-Server Application, then define the properties of the service, as shown:
The save file name is Wakeonlinesrv.PAS, the code of the unit is as follows:
Unit wakeonlinesrv;
Interface
Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, SVCMGR, Dialogs, WakeOnlineexecutethread;
type TWakeOnLineServer = class (TService) procedure ServiceStart (Sender: TService; var Started: Boolean); procedure ServiceStop (Sender: TService; var Stopped: Boolean); procedure ServicePause (Sender: TService; var Paused: Boolean); procedure ServiceContinue (Sender : TService; var continued: boolean; private {private declarations}}}}; public function GetServiceController: tServiceController; override; {public declarations}
Var WakeOnlineServer: TwakeOnlineServer;
IMPLEMENTATION
{$ R * .dfm}
Procedure ServiceController (Ctrlcode: DWORD); stdcall; begin wakeonlineserver.controller (ctrlcode);
Function TwakeonLineServer.getServiceController: TServiceController; Begin Result: = ServiceController;
Procedure TwakeOnlineServer.ServiceStart (Sender: TService; Var Started: Boolean); Begin // Startup Service THDWakeOnline: = twakeonline.create (false); started: = true;
Procedure TwakeOnlineServer.ServiceStop (Sender: TService; VAR Stopped: Boolean); Begin // Stop Sergey; Stopped: = true;
procedure TWakeOnLineServer.ServicePause (Sender: TService; var Paused: Boolean); begin // suspended ThdWakeOnline.Suspend; Paused: = True; end; procedure TWakeOnLineServer.ServiceContinue (Sender: TService; var Continued: Boolean); begin // recovery Serving thdwakeonline.resume; continued: = true;
End.
From File-New-Other-Thread Object, create a new unit file, save the file name to wakeonlineexecutethread.pas, the code is as follows:
Unit wakeonlineexecutethread;
Interface
Uses classes, idudpclient, sysutils;
Const Wakeuptime = '07: 50 '; // Notice That Not 7:50! Stopsendtime = '07: 51'; targetComputermacaddress = '00025556e5c5';
Type Twakeonline = Class (TTHREAD) private {private declarations} protected procedure execute; override;
VAR SENT: BOOLEAN = FALSE;
IMPLEMENTATION
{Important: Methods and Properties Of Objects in Visual Components Called Using Synchronize, for Example,
Synchronize (UpdateCaption);
And UpdateCaption Could Look Like,
Procedure wakeonline.Updatecaption; begin form1.caption: = 'updated in a thread'; end;}
{Wakeonline}
procedure TWakeOnLine.Execute; var MacAddr: String; FUDP: TIdUDPClient; SendCode: string; I, J: Integer; Bin: String [6]; begin {Place thread code here} // automatically released when the thread terminates Self.FreeOnTerminate: = True; // Send flag SENT: = false; // If the thread is not terminated, run the following loop while not Terminated do begin // If there is no transmission, and has reached the time IF (Not Sent) and (Copy (FormatorTime) ('HH: MM: SS', NOW), 1, 5) = Wakeuptime) The begin // Start Send MacAddr: = TargetComputerMacaddress;
Fudp: = tidudpclient.create (nil); tryp.port: = 7; fudp.host:=10.10.10.2 '; fudp.active: = true; hextobin (pchar (macaddr), @ bin, 6); sendcode : = StringOfchar (# 255, 6);
// Filled buffer for i: = 0 to 15 do for j: = 0 to 5 do sendcode: = sendcode bin [j];
// Suspend 6 times, insurance. . . For i: = 0 to 5 do fudp.broadcast (sendcode, 7);
Finally fudp.free; end;
SENT: = true;
END ELSE
Begin // If it has been sent, and the next minute of the send time has been reset, reset the sending flag to provide IF Sent and (FormatorTime ('hh: mm: SS', NOW), 1, 5) = stopsendtime) THEN SENT: = FALSE;
// Rest 30 seconds to avoid waste of resources SLEEP (30000);
// If there is a termination signal, the IF Terminated Ten Break is terminated.
END;
END;
End.
Finally, the name of the project file is wakeonline.dpr, the content is as follows:
Program wakeonline;
Uses svcmgr, wakeonlinesrv in 'wakeonlinesrv.pas' {wakeonlineserver: tService}, WakeOnlineexecutethread in 'WakeOnlineexecutethread.Pas';
{$ R * .res}
Begin Application.INITIALIZE; Application.createform (TwakeOnlineServer); Application.Run; End.
Select a suitable icon for this service program, and finally compile a name to WakeOnline.exe executable.
To the CMD window to install the service: Execute: wakeonline -install, will prompt the service has been successfully installed:
Then the mouse right click on my computer - Manage - Services and Applications - Services, then find the service just installed: Wake on line Server,
You can see it yet. You haven't started, now double-click it, click Start:
My time specified in the program is to send broadcasts at 7:50 in the morning. Start a network package crawler, adjust the time to 7:49 in the morning, take a while, look at what caught:
The target machine is started. . .
(Description: Delphi 7 compile; Cisco 2950 switch; awakened IBM X205 server, pay attention to the Wake Online option enable in BIOS)
ilittle @ FAT
2004-6-2