远程开机/关机(不需要客户端)用网卡(50分)

  • 主题发起人 主题发起人 delphi5988
  • 开始时间 开始时间
D

delphi5988

Unregistered / Unconfirmed
GUEST, unregistred user!
就是想:
在局域网中不需要客户端,远程关机!

如下,这是远程开机的东东,但没有关机的!我想得到关机的,不知怎么办!大家多多讨论呀!

关于远程开机再配合远程控制

procedure TForm1.Button2Click(Sender: TObject);
var
vBuf:array[0..101] of char;
i,j:integer;
begin
//包的格式很简单,在以太网包的任何位置上,
//以6个FF为先导,后面跟相应MAC地址重复16次即可:
for i:=0 to 5 do vBuf:=char($FF);
for i:=0 to 15 do
begin
j:=6+i*6;
vBuf[j] :=Char($00);
vBuf[j+1]:=Char($13);
vBuf[j+2]:=Char($D4);
vBuf[j+3]:=Char($04);
vBuf[j+4]:=Char($55);
vBuf[j+5]:=Char($80);
end;
NMUDP1.RemoteHost:='192.168.1.255';
NMUDP1.SendBuffer(vBuf,Length(vBuf));
end;

以下为NetWaker的要求,也是远程开机的要求,一般现在的机子都有支持。

1.硬件需求

  实现网络开机,需要主板、网卡、电源3个设备支持。首先需要查看主板使用说明书,查看主板是否支持Wake-Up On Internal Modem(WOM)或者Wake-up On LAN(WOL)技术,如果支持就说明主板支持远程开机。能否实现远程唤醒,其中最主要的一个部件就是支持WOL的网卡,远端被唤醒计算机的网卡必须支持WOL,而用于唤醒其他计算机的网卡则不必支持WOL。另外,当一台计算机中安装有多块网卡时,只须将其中的一块设置为可远程唤醒即可。

  除此以外,电脑必须安装有符合ATX 2.03标准的ATX电源,+5VStandby电流至少应在720mA以上。有的早期电源可能只设计到500mA,在进行网络开机时,某些耗电较大的网卡可能会无法启动。

  2.CMOS设置

  首先需要进行CMOS和网卡设置,启动计算机,进入CMOS参数设置。选择电源管理设置“Power Management Setup”菜单,将“Wake up on LAN”项和“Wake on PCI Card”项均设置为“Enable”,启用该计算机的远程唤醒功能。有些网卡需要通过跳线将“Wake-on-LAN”功能设置为“Enable”。

  将WOL电缆的两端分别插入网卡和主板的3芯插座中,将网卡与计算机主板连接起来。如果主板支持PCI 2.2标准,只要开启“Wake on PCI Card”功能就可以了,无须使用WOL电缆连接。然后启动计算机,安装网卡驱动程序并完成网卡的网络连接设置
 
http://torry.net/authorsmore.php?id=1753&SID=5a6ee3f366fdf7faa4e8559e6d8d5440
Delphi盒子上也有
 
楼上的兄弟,我没找到你的说的东东呀,能不能直接写到论谈上!
 
procedure TForm1.Button1Click(Sender: TObject);
var
RemoteShutDown : Bool;
ComputerName : PChar;
begin
if Edit1.Text <> '' then
begin
ComputerName := PChar(Edit1.Text);
EnablePrivilege(ComputerName,'SeRemoteShutdownPrivilege');
RemoteShutDown :=InitiateSystemShutdown(ComputerName ,nil,0,TRUE,FALSE);
if RemoteShutDown then
ShowMessage('(远程)关机'+ComputerName+'成功!')
else
ShowMessage('(远程)关机'+ComputerName+'失败!');
end;
end;

function TForm1.EnablePrivilege(lpSystemName, lpName: PChar): Bool;
var
hToken : THANDLE;
fOk : Bool;
fTest : Bool;
tp, tpNew : TOKEN_PRIVILEGES;
ReturnLength : Cardinal;
begin
fOk := FALSE;
if IPCConnect(Edit1.Text ,Edit2.Text,Edit3.Text)=0 then
begin
if OpenProcessToken(GetCurrentProcess,(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),hToken) then
begin
tp.PrivilegeCount := 1;
if not (LookupPrivilegeValue(lpSystemName,lpName,tp.Privileges[0].Luid)) then
ShowMessage('Can not lookup privilege value!!');
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
if not (AdjustTokenPrivileges(hToken,FALSE,tp,sizeof(tp),tpNew,ReturnLength)) then
ShowMessage('Can not adjust privilege value!!');
if GetLastError = ERROR_SUCCESS then
fOk := TRUE
else
fOK := FALSE;
CloseHandle(hToken);
end;
end;
Result := fOk;
end;

Function TForm1.IPCConnect(Server , username , Password : String ) : Integer;
var
NR : TNetResource;
begin
FillChar(NR, SizeOf(NR), 0);
NR.dwType := RESOURCETYPE_ANY;
NR.lpLocalName := '';
NR.lpProvider := '';
NR.lpRemoteName := pchar('//'+Server);
Result := WNetAddConnection2(NR, pchar(Password), pchar(UserName), 0);
end;

Function TForm1.DisIPCConnect(Server : String) : integer;
begin
Result := WNetCancelConnection2(pchar(Server),0,True);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if IPCConnect(Edit1.Text ,Edit2.Text,Edit3.Text) <>0 then
begin
showmessage('连接失败');
end
else
begin
showmessage('连接成功');
end;
end;
 
EnablePrivilege(ComputerName,'SeRemoteShutdownPrivilege');
RemoteShutDown :=InitiateSystemShutdown(ComputerName ,nil,0,TRUE,FALSE);

怎么不能通过,要在USER中加入什么单元文件呀!
 
Delphi 盒子上的, 你自己研究吧

代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    function EnablePrivilege(lpSystemName, lpName: PChar): Bool;
    Function IPCConnect(Server , username , Password : String ) : Integer;
    Function DisIPCConnect(Server : String) : integer;
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  RemoteShutDown : Bool;
  ComputerName : PChar;
begin
  if Edit1.Text <> '' then
  begin
    ComputerName := PChar(Edit1.Text);
    EnablePrivilege(ComputerName,'SeRemoteShutdownPrivilege');
    RemoteShutDown :=InitiateSystemShutdown(ComputerName ,nil,0,TRUE,FALSE);
    if RemoteShutDown then
    ShowMessage('(远程)关机'+ComputerName+'成功!')
    else
    ShowMessage('(远程)关机'+ComputerName+'失败!');
  end;
end;

function TForm1.EnablePrivilege(lpSystemName, lpName: PChar): Bool;
var
  hToken : THANDLE;
  fOk : Bool;
  fTest : Bool;
  tp, tpNew : TOKEN_PRIVILEGES;
  ReturnLength : Cardinal;
begin
  fOk := FALSE;
  if IPCConnect(Edit1.Text ,Edit2.Text,Edit3.Text)=0 then
    begin
    if OpenProcessToken(GetCurrentProcess,(TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY),hToken) then
      begin
      tp.PrivilegeCount := 1;
      if not (LookupPrivilegeValue(lpSystemName,lpName,tp.Privileges[0].Luid)) then
      ShowMessage('Can not lookup privilege value!!');
      tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      if not (AdjustTokenPrivileges(hToken,FALSE,tp,sizeof(tp),tpNew,ReturnLength)) then
      ShowMessage('Can not adjust privilege value!!');
      if GetLastError = ERROR_SUCCESS then
      fOk := TRUE
      else
      fOK := FALSE;
      CloseHandle(hToken);
    end;
  end;
  Result := fOk;
end;

Function TForm1.IPCConnect(Server , username , Password : String ) : Integer;
var
  NR : TNetResource;
begin
  FillChar(NR, SizeOf(NR), 0);
  NR.dwType := RESOURCETYPE_ANY;
  NR.lpLocalName := '';
  NR.lpProvider := '';
  NR.lpRemoteName := pchar('//'+Server);
  Result := WNetAddConnection2(NR, pchar(Password), pchar(UserName), 0);
end;

Function TForm1.DisIPCConnect(Server : String) : integer;
begin
  Result := WNetCancelConnection2(pchar(Server),0,True);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if IPCConnect(Edit1.Text ,Edit2.Text,Edit3.Text) <>0 then
  begin
     showmessage('连接失败');
     exit;
  end
  else
  begin
     showmessage('连接成功');
     exit;
  end;
end;

end.

-------------------------------------

object Form1: TForm1
  Left = 383
  Top = 178
  Width = 291
  Height = 167
  Caption = '远程关机'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 33
    Top = 16
    Width = 52
    Height = 13
    Caption = '计算机名'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
  end
  object Label2: TLabel
    Left = 33
    Top = 47
    Width = 39
    Height = 13
    Caption = '用户名'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
  end
  object Label3: TLabel
    Left = 33
    Top = 76
    Width = 26
    Height = 13
    Caption = '密码'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 87
    Top = 11
    Width = 121
    Height = 21
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
    TabOrder = 0
  end
  object Button1: TButton
    Left = 184
    Top = 103
    Width = 75
    Height = 25
    Caption = '关机'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
    TabOrder = 1
    OnClick = Button1Click
  end
  object Edit2: TEdit
    Left = 87
    Top = 42
    Width = 121
    Height = 21
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
    TabOrder = 2
    Text = 'Administrator'
  end
  object Edit3: TEdit
    Left = 87
    Top = 72
    Width = 121
    Height = 21
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
    PasswordChar = '*'
    TabOrder = 3
  end
  object Button2: TButton
    Left = 32
    Top = 104
    Width = 75
    Height = 25
    Caption = '测试连接'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = '宋体'
    Font.Style = []
    ParentFont = False
    TabOrder = 4
    OnClick = Button2Click
  end
end
 
帮顶!

╭=========================================╮

80G海量源代码,控件,书籍全免费狂下不停!

http://www.source520.com

个人网站站长开发推广同盟,让所有人知道你的世界!

http://www.source520.com/search/search.asp

╰=========================================╯
 
上面的代码,写得很好,但是不是多线程的,关机很慢呀!
大家能不能帮我一下,写一个多线程的!
最好有,开机原理!
万分感谢!
 
后退
顶部