Автор Жека задал вопрос в разделе Другие языки и технологии
Wake-on-LAN +Delphi и получил лучший ответ
Ответ от Pract pract[новичек]
program WOL;
{$APPTYPE CONSOLE}
uses
Windows,
SysUtils,
IdBaseComponent,
IdComponent,
IdUDPBase,
IdUDPClient,
IdGlobal;
{$R *.res}
function HexToInt(const s: string): Integer;
begin
Result := 0;
if Length(s) <= (SizeOf(LongWord) * 2) then
Result := StrToInt('$' + s);
end;
procedure ErrMsg(Msg:String);
begin
MessageBox(0,PChar(Msg),'Wake On LAN',MB_OK or MB_ICONERROR);
end;
procedure WakeUPComputer(aMacAddress: string);
var i,j,k:Byte;
lBuffer: TBytes; // исправлено здесь (для BDS2006)
lUDPClient:TIdUDPClient;
begin
try
SetLength(lBuffer,102);
for i := 0 to 5 do begin
lBuffer := $FF;
end;
for i:=1 to 16 do begin
k:=i*6;
for j := 0 to 5 do begin
lBuffer[k+j] := HexToInt(aMacAddress[j*2+1] + aMacAddress[j*2+2]);
end;
end;
lUDPClient:=TIdUDPClient.Create(nil);
try
lUDPClient.BroadcastEnabled:=true;
lUDPClient.Host:='255.255.255.255';
lUDPClient.Port:=2050;
lUDPClient.SendBuffer(lBuffer); //исправлено здесь (для BDS2006)
except
on E:Exception do ErrMsg(E.Message);
end;
lUDPClient.Free;
SetLength(lBuffer,0); // не забываем чистить память
except
on E:Exception do ErrMsg(E.Message);
end;
end;
procedure ShowHelp;
begin
MessageBox(0,'Usage: WOL.exe <mac-address>'#13#10'Example: WOL 000D619AFB55',
'Wake On LAN',0);
end;
begin
if ParamCount>0 then WakeUpComputer(ParamStr(1)) else ShowHelp;
end.