如何通过程序实现网卡的启用和禁止功能?

如何通过程序实现网卡的启用和禁止功能?在Delphi中选ProjectImportTypeLibrary命令,在对话框中选ImportMicrosoftShellControlsAndAutomation类型库,点Install后,在Delphi的ActiveX控件板上就多了TShellFolderItem,TShellLinkObject,TShellFolderView,TShell,TSearchCommand等

大家好,欢迎来到IT知识分享网。如何通过程序实现网卡的启用和禁止功能?

在Delphi中选Project Import Type Library命令,在对话框中选Import Microsoft Shell Controls And Automation类型库,点Install后,在Delphi的ActiveX控件板上就多了TShellFolderItem,TShellLinkObject,TShellFolderView,TShell,TSearchCommand等几个组件

const
   discVerb = ‘禁用(&B)’;
   connVerb = ‘启用(&A)’;

function TForm1.DisableEthernet(const EthName,State: String): Boolean;
var
  cpFolder: Folder;
  nwFolder: Folder;
  nVerbs: FolderItemVerbs;
  i,j,k: integer;
  aItem: TListItem;
begin
  result := false;
  cpFolder := Form1.shell1.NameSpace(3);
  if cpFolder <> nil then
  begin
    for i := 0 to cpFolder.items.Count-1 do
    begin
      if cpFolder.Items.Item(i).Name = ‘网络和拨号连接’ then
      begin
        nwFolder := cpFolder.items.item(i).GetFolder as Folder;
        if nwFolder <> nil then
        begin
          for j :=0 to nwFolder.items.Count-1 do
          begin
            if nwFolder.Items.Item(j).Name = EthName then
            begin
              nVerbs := nwFolder.Items.Item(j).Verbs;
              for k := 0 to  nVerbs.Count-1 do
             begin
                if nVerbs.Item(k).Name = State then
                begin
                  nVerbs.Item(k).DoIt;
                  aItem := Form1.lvLog.Items.Add;
                  aItem.Caption := FormatDateTime(‘yyyy-mm-dd hh:mm:ss’,now);
                  aItem.SubItems.Add(EthName);
                  aItem.SubItems.Add(State);
                  Result := True;
                end;
              end;
            end;
          end;
        end;
      end;
    end;
    if nwFolder = nil then
       showmessage(‘Network and Dial-up Connections not found’);
  end
  else
    showmessage(‘control panel not found’);

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DisableEthernet(‘本地连接’,discVerb);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  DisableEthernet(‘本地连接’,connVerb);
end;

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/22621.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信