Delphi禁用,启用网卡


本文整理自网络,侵删。

  (******************************************************************************
* CopyRight (c) By 姚佩云 2004
* All Right Reserved
* Email : i_rock_1001@163.com http://www.jynx.com.cn/
* 这是一个禁用、启用网卡的例子,实际上通过shell可以控制整个界面,参考的网上资料
* 需要先引用 Microsoft Shell Controls And Automation(Shell32.dll)对应delphi声明 Shell32_TLB.pas
******************************************************************************)

 

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}

{++
Routine Description:
取本机所有网络链接列表
Arguments:
OUT list - 取得的网络链接列表
Return Value:
BOOLEAN - 执行是否成功
--}

function GetNetLinkList(var list:TStrings):BOOLEAN;
var
Shell:TShell;
ControlPanel:Folder;
Item:FolderItem;
i:integer;
begin
Result:= FALSE;
if list = nil then exit;

Shell:=TShell.Create(Application);
if Shell = nil then exit;

ControlPanel:=Shell.NameSpace(ssfCONTROLS);
for i:=0 to ControlPanel.items.Count -1 do
begin
Item:=ControlPanel.items.Item(i);
if (Item.Name = '网络和拨号连接') then //如果是英文的windows则Name也需是英文的
begin
ControlPanel:=Folder(Item.GetFolder);
break;
end;
end;

for i:=0 to ControlPanel.items.count-1 do
begin
Item:= ControlPanel.items.Item(i);
List.Add(Item.Name);
end;
FreeAndNil(shell);
Result:= TRUE;
end;

{++ Routine Description:
执行 本地网络链接 的菜单命令(包括禁用、启用)
Arguments:
IN AdapterName - 网络链接名称
IN MenuName - 菜单名称
Return Value:
BOOLEAN - 执行是否成功
--}

function ExcNetLinkMenu(const AdapterName,MenuName:String):BOOLEAN;
var
Shell:TShell;
ControlPanel:Folder;
Item:FolderItem;
i,j:integer;
Verb:FolderItemVerb;
begin
Result:= FALSE;
Shell:=TShell.Create(Application);
if Shell = nil then exit;

ControlPanel:=Shell.NameSpace(ssfCONTROLS);
for i:=0 to ControlPanel.items.Count -1 do
begin
Item:=ControlPanel.items.Item(i);
if (Item.Name = '网络和拨号连接') then //如果是英文的windows则Name也需是英文的
begin
ControlPanel:=Folder(Item.GetFolder);
break;
end;
end;

for i:=0 to ControlPanel.items.count-1 do
begin
Item:=ControlPanel.items.Item(i);
if (Item.Name = AdapterName) then //如果是英文的windows则Name也需是英文的
begin
for j:=0 to Item.Verbs.Count -1 do
begin
Verb:=Item.Verbs.Item(j);
if (Verb.Name = MenuName) then
begin
Verb.DoIt ;
Result:=TRUE;
break;
end;
end;
break;
end;
end;
FreeAndNil(shell);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
list:TStrings;
begin
List:=TStringList.Create ;
GetNetLinkList(List);
ComboBox1.Items:=List;
FreeAndNil(List);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ExcNetLinkMenu('本地连接 2','启用(&A)');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ExcNetLinkMenu('本地连接 2','禁用(&B)');
end;

end.

相关阅读 >>

Delphi 拷贝文件时有进度显示

Delphi sendtextmessage 等方便的消息发送函数

Delphi 刷新桌面函数

Delphi 逐个分解后字符串加载到stringgrid1

Delphi spcomm 接收数据不完整

Delphi获取注册表run下所有值

Delphi xe安装后配置android的sdk的方法

Delphi opendialog控件用法

Delphi中使用汇编(关于pos函数的问题)

Delphi d10.x 并行库ppl编程之ttask

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...