假设我的电脑有两个本地连接(系统栏右下角两个小电脑图标),分别是“本地连接1”和“本地连接2”,我要用程序禁用其中的“本地连接2”,该如何实现,谢谢大家。

解决方案 »

  1.   

    up,好像在window版看过此问,顶
      

  2.   

    const
       discVerb = '禁用(&B)';
       connVerb = '启用(&A)';function DisableEthernet(const EthName: String): Boolean;
    var
      cpFolder: Folder;
      nwFolder: Folder;
      nVerbs: FolderItemVerbs; 
      i,j,k: integer;
    begin
      result := false;
      cpFolder := 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 = discVerb then
                    begin
                      nVerbs.Item(k).DoIt;  
                      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;
    function EnableEthernet(const EthName: String): Boolean;
    var
      cpFolder: Folder;
      nwFolder: Folder;
      nVerbs: FolderItemVerbs; 
      i,j,k: integer;
    begin
      result := false;
      cpFolder := 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 = connVerb then
                    begin
                      nVerbs.Item(k).DoIt;  
                      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;
      

  3.   

    多看看win2k/xp命令行的工具介绍吧
      

  4.   

    还可以是使用Setup API来实现的FAQ中和以前的帖有的,与使用代码移除U盘方法是一样的http://lysoft.7u7.net
      

  5.   

    if cpFolder.Items.Item(i).Name = '网络和拨号连接' then如果是E文版Windows或者越南语、阿拉伯语等等的怎么办啊。
    呵呵。