如何在程序里禁用网卡

alphadyz 2004-07-25 01:35:04
如何用程序来禁用网卡,主机可能有多个网卡。
...全文
200 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ly_liuyang 2004-07-25
  • 打赏
  • 举报
回复
上面的没有兼容性的
不同的系统不一样的
NT下方法
最简单的方法:WinExec调用NetSH用参数搞定
代码方法:使用SetupAPI的API操作,比较复杂,不建议你用了
constantine 2004-07-25
  • 打赏
  • 举报
回复
up
anbeel 2004-07-25
  • 打赏
  • 举报
回复
zt:

按照上面的网址 安装Shell Controls and Automation 对象:
然后完整的代码如下:

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
StdCtrls,QComCtrls, OleServer, Shell32_TLB, ComCtrls,Dialogs;
const
discVerb = '禁用(&B)';
connVerb = '启用(&A)';
type
TForm1 = class(TForm)
Button1: TButton;
Shell1: TShell;
lvLog: TListView;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function DisableEthernet(const EthName: String): Boolean;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.DisableEthernet(const EthName: 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 = discVerb then
begin
nVerbs.Item(k).DoIt;
aItem := lvLog.Items.Add;
aItem.Caption := FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
aItem.SubItems.Add(EthName);
aItem.SubItems.Add(discVerb);
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('本地连接');
end;

end.
anbeel 2004-07-25
  • 打赏
  • 举报
回复
http://hubdog.csdn.net/UpdateList/ul20020411.htm

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧