ExitWindowsEx
The ExitWindowsEx function either logs off the current user, shuts down the system, or shuts down and restarts the system. It sends the WM_QUERYENDSESSION message to all applications to determine if they can be terminated.
Parameters
uFlags
Specifies the type of shutdown. This parameter must include one of the following values: Value Meaning
EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
EWX_REBOOT Shuts down the system and then restarts the system.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.
Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
This parameter can optionally include the following values: Value Meaning
EWX_FORCE Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_FORCEIFHUNG Windows NT 5.0 and later: Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used.
要有网卡,BIOS要支持网络唤醒,好像只能一台一台的启~~
而且受控方要正常关机才行~~郁闷极了
//取得广播的ip地址,比如本机是192.168.0.1,这个函数得到192.168.0.255
function TFunc.GetRadiateIP:String;
var i,j,iHead:Integer;
sHead,s:String;
ai:array [1..3] of integer;
LocalIPAdd:string;
begin
Result:='192.168.255.255';
LocalIPAdd:=GetLocalIP; //GetLocalIP为本机IP,这样Powersock1.LocalIP
j:=1;
//取出.的位置
for i:=0 to Length(LocalIPAdd) do
begin
if LocalIPAdd[i]='.' then
begin ai[j]:=i; Inc(j); end;
if j>3 then break;
end;
//shead为ip第一段
sHead:=Copy(LocalIpAdd,1,ai[1]-1);
iHead:=StrToInt(sHead);
if iHead<128 then //A类网
Result:=sHead+'.255.255.255'//a类网的广播ip
else
begin
if iHead<192 then //B类网
begin
s:=Copy(LocalIPAdd,1,ai[2]-1);
Result:=s+'.255.255';//b类网的广播ip
end
else //C类网
begin
s:=Copy(LocalIPAdd,1,ai[3]-1);
Result:=s+'.255';//c类网的广播ip
end;
end;
end;
[灌水]远程启动函数
procedure TFunc.PowerMachine(aMac: String;NMUDP1:TNMUDP);
//aMac为受控方网卡地址
var Str:Array[1..102] of char;
i:Integer;
function StrtoHex(S:String):Byte;
begin
Result := 0;
Case S[2] of
'0': Result := 0;
'1': Result := 1;
'2': Result := 2;
'3': Result := 3;
'4': Result := 4;
'5': Result := 5;
'6': Result := 6;
'7': Result := 7;
'8': Result := 8;
'9': Result := 9;
'A': Result := 10;
'B': Result := 11;
'C': Result := 12;
'D': Result := 13;
'E': Result := 14;
'F': Result := 15;
end;
Case S[1] of
'0': Result := Result;
'1': Result := Result + 16*1;
'2': Result := Result + 16*2;
'3': Result := Result + 16*3;
'4': Result := Result + 16*4;
'5': Result := Result + 16*5;
'6': Result := Result + 16*6;
'7': Result := Result + 16*7;
'8': Result := Result + 16*8;
'9': Result := Result + 16*9;
'A': Result := Result + 16*10;
'B': Result := Result + 16*11;
'C': Result := Result + 16*12;
'D': Result := Result + 16*13;
'E': Result := Result + 16*14;
'F': Result := Result + 16*15;
end;
end;
begin
for i := 1 to 6 do Str[i] := #255;
i := 7;
while i < 103 do
begin
Str[i] := chr(StrToHex(Copy(aMac,1,2)));
Str[i+1] := chr(StrToHex(Copy(aMac,3,2)));
Str[i+2] := chr(StrToHex(Copy(aMac,5,2)));
Str[i+3] := chr(StrToHex(Copy(aMac,7,2)));
Str[i+4] := chr(StrToHex(Copy(aMac,9,2)));
Str[i+5] := chr(StrToHex(Copy(aMac,11,2)));
inc(i,6);
end;
NMUDP1.LocalPort := 6666;
NMUDP1.RemotePort := 6666;
NMUDP1.RemoteHost:=GetRadiateIP;//广播地址,GetRadiateIP函数见下
NMUDP1.ReportLevel := 1;
NMUDP1.SendBuffer(Str,102);
end;