解决办法已找到:
//调用循环(实现开多台)
procedure TMainForm.BtnWakeClick(Sender: TObject);
var
I,varEnd:integer;
varCommandStr:string;
begin
with ListView1.Items do
For I:=0 to Count-1 do
begin
if item.checked and (item.SubItems.Count>1) then
if pri_FunWakeUpComputer(pchar(item.caption),pchar(item.SubItems.Strings[1])) then
MemoState.Lines.Add(item.SubItems.Strings[1]+' 发送成功! -- '+ DateTimeToStr(Now()))
else
MemoState.Lines.Add(item.SubItems.Strings[1]+' 发送失败! -- '+ DateTimeToStr(Now()));
end;
MemoState.Lines.SaveToFile(ExtractFiledir(ParamStr(0))+'/'+'thinkingWakerSate.Txt');
if CkBoxDate.Checked then close;
end;
//开机代码---网上大虾提供,略做修改
//WSocket是ICS的控件
function TMainForm.pri_FunWakeUpComputer(AMacAddr, AIPAddr : PChar) : Boolean; stdcall;
var
MagicStr, BroadcastAddr : string;
i, Dot : Integer;
strMacAddr, strIPAddr : string;
WSocket : TWSocket;
begin
MagicStr := '';
strMacAddr := StrPas(AMacAddr);
strIPAddr := StrPas(AIPAddr);
for i := 1 to 16 do
begin
MagicStr := MagicStr + string(Char(StrToInt('0x' + Copy(strMacAddr, 1, 2))))
+ string(Char(StrToInt('0x' + Copy(strMacAddr, 3, 2))))
+ string(Char(StrToInt('0x' + Copy(strMacAddr, 5, 2))))
+ string(Char(StrToInt('0x' + Copy(strMacAddr, 7, 2))))
+ string(Char(StrToInt('0x' + Copy(strMacAddr, 9, 2))))
+ string(Char(StrToInt('0x' + Copy(strMacAddr, 11, 2))));
end;
MagicStr := StringOfChar(#255,6) + MagicStr;
BroadcastAddr := '';
for i := 0 to 2 do
begin
Dot := Pos('.', strIPAddr);
BroadcastAddr := BroadcastAddr + Copy(strIPAddr, 1, Dot);
Delete(strIPAddr, 1, Dot);
end;
BroadcastAddr := BroadcastAddr + '255';
//dmShare.UDPSendStr(BroadcastAddr, C_IsActivePort, MagicStr);
WSocket := TWSocket.Create(nil);
try
with WSocket do
begin
Close;
Proto := 'UDP';
Port := '7911';
Addr := BroadcastAddr;
Connect;
SendStr(MagicStr);
end;
finally
WSocket.Close;
WSocket.Free;
end;
Result := True;
end;
//前提:电脑主板支持LAN唤醒,并在BIOS设置生效.