用Delphi实现关闭重启本地网络连接
2009-11-26 14:04
555 查看
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleServer, Shell32_TLB, StdCtrls; const connVerb = '启用'; discVerb = '停用'; type TForm1 = class(TForm) shl1: TShell; btn1: TButton; btn2: TButton; procedure btn1Click(Sender: TObject); procedure btn2Click(Sender: TObject); private { Private declarations } function ControlEthernet(const EthName, FolderItemVerbsName: string): Boolean; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { Component -> Import ActiveX Control -> Microsoft Shell Contolrs And Automation 然后创建单元文件,之后再新建一个安装包,添加该单元文件,最后是安装该控件,就可以用了(Tshell) } procedure TForm1.btn1Click(Sender: TObject); begin ControlEthernet('本地连接', discVerb); //启用本地连接 '停用&' end; procedure TForm1.btn2Click(Sender: TObject); begin ControlEthernet('本地连接', connVerb); //启用本地连接 '启用&' end; function TForm1.ControlEthernet(const EthName, FolderItemVerbsName: string): Boolean; var cpFolder, nwFolder: Folder; //一个外壳文件夹对象 nVerbs: FolderItemVerbs; //获得上下文相关的菜单信息 i, j, k: integer; Shell1: TShell; begin Result := false; Shell1 := TShell.Create(Application); cpFolder := Shell1.NameSpace(3); //选择控件面板 if cpFolder <> nil then begin for i := 0 to cpFolder.items.Count - 1 do //返回它所包含的外壳对象的集合(文件) 28 begin if cpFolder.Items.Item(i).Name = '网络连接' then //返回的集合的名称 begin nwFolder := cpFolder.items.item(i).GetFolder as Folder; //取得该cpFolder下面的外壳对象 if nwFolder <> nil then //内容不为空 begin for j := 0 to nwFolder.items.Count - 1 do //历遍cpFolder下面的外壳对象 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 Pos(FolderItemVerbsName, nVerbs.Item(k).Name) > 0 then //如果菜单名称为 '禁用&' 时, // 则执行该菜单命令 begin nVerbs.Item(k).DoIt; //执行该菜单命令 //nwFolder.Items.Item(j).InvokeVerb(nwFolder.Items.Item(j).Verbs.Item(k).Name); Result := true; //效果一致 end; end; end; end; end; end; end; end; end; end.
相关文章推荐
- 用Delphi实现关闭、重启本地网络连接
- C#实现启用或停用本地网络连接,转
- Android中监听系统网络连接打开或者关闭的实现代码
- 让命令提交后不受本地关闭终端窗口/网络断开连接的干扰
- muduo源码分析之实现TCP网络库(连接的接收和关闭)
- Delphi实现WINDOWS“本地连接”的启用和禁用
- 网络连接中断时关机实现方法(delphi)
- win7本地连接共享网络实现手机wifi访问
- bat实现监测计算机网络连接,断网自动重启网络连接
- C#实现启用或停用本地网络连接
- GTK 程序 检测 网线是否连接 本地网络状态 C语言实现
- 如何用Delphi实现WINDOWS XP中“本地连接”的启用和禁用 ?
- Android 监听 Android中监听系统网络连接打开或者关闭的实现代码
- 关闭+重启本地连接
- 用Delphi实现WINDOWS XP中“本地连接”的启用和禁用
- 无法使用VMware以NAT模式连接本地网络(实现虚拟机跟主机共享网络)
- 【转】VBS脚本 实现"无线网络连接"与"本地连接"的网卡禁用启用完美切换(优化版)
- Java语句轻松实现与数据库MYSQL【本地数据库】的连接,和对数据库的增删改查操作
- Android用代码实现GPS的开启/关闭功能+网络开关