一段启用和禁用网卡的delphi代码。。
谁能帮我解释一下。引用shell32.dll
unit Unit1;interfaceuses
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;
beginResult:= 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;
beginResult:= 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.
谁能帮我解释一下。引用shell32.dll
unit Unit1;interfaceuses
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;
beginResult:= 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;
beginResult:= 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.
解决方案 »
- [急]TreeView高手进
- 小声的问一下:Windows api函数那里有说明文档?
- 压抑,这些简单的东西我都看不懂....只好请教你们了.在线等....
- 如何找到并取得当前操作系统的system或者systemp32目录
- 证券之星上面的工具栏的效果怎么实现?
- 在DELPHI的TQUERY中,或者在INTERBASE中如果有两条SQL语句, 中间用什么分开?
- 有没有这样的控件阿??
- 求S:='ABCD$EF/1G3H4/I323J/K43L/M4N%7O8P$9QR$STUV'中各字符所对应ASC值的和,但不包括$和/
- 高分等待:哪位高手能指点一下有关 Delphi 读写并口的方法!资料 等待中...
- 请教delphi7+win7环境,使用Doscommand控件+plink,ssh登录服务器问题
- writeBuffer,writeStream,writeLn这3种怎么区别?怎么用?
- 引用dll?
至少你要说出那里不懂吧?如果都不懂,建议你应该先学习delphi的基础知识先
上面的代码,都有英文注释的阿3 个 procedure TForm1.ButtonXClick(Sender: TObject);
代表三个按钮操作,不同的功能,后面两个,看中文就知道意义了第一个是调用前面的函数,取得列表,
就是希望 能一句句解释一下。。
我只会vb,我想把上面做成vb..很郁闷。。做网卡启动和禁止烦了两三天了。
急又急。。唉
加什么控件?还在哪里引用库,和声明变量?
shell32.dll在delphi中是怎么引用的???