Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1027378
  • 博文数量: 179
  • 博客积分: 10080
  • 博客等级: 上将
  • 技术积分: 2580
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-10 09:26
文章分类

全部博文(179)

文章存档

2015年(1)

2014年(1)

2012年(1)

2011年(3)

2010年(14)

2009年(11)

2008年(10)

2007年(42)

2006年(96)

我的朋友

分类: WINDOWS

2006-12-22 09:19:40

如何在XP的命令行模式下禁用或启用网卡

 

先看show interface 的结果, 然后选择你要disableinterface. 注意带空格的名称需要用引号.

 

netsh interface show interface

 

Admin State State Type Interface Name

-------------------------------------------------------------------------

Enabled Unreachable Dedicated Local Area Connection 2

Enabled Unreachable Dedicated Local Area Connection

Enabled Unreachable Internal Internal

Enabled Unreachable Loopback Loopback

 

netsh interface set interface name="Local Area Connection" admin=DISABLED

----------------------------

or:

netsh interface set interface "本地连接" "disabled"

netsh interface set interface "本地连接" "enabled"

 

win2003 实现 , xp 不行

 

2000中文专业版,XP环境,测试不了,给你个在2000下能用的脚本,XP下面不知道能不能用.

-----------------

Const ssfCONTROLS = 3

 

sConnectionName = "本地连接"

 

sEnableVerb = "启用(&A)"

sDisableVerb = "禁用(&B)"

 

set shellApp = createobject("shell.application")

set oControlPanel = shellApp.Namespace(ssfCONTROLS)

 

set oNetConnections = nothing

for each folderitem in oControlPanel.items

 if folderitem.name  = "网络和拨号连接" then

   set oNetConnections = folderitem.getfolder: exit for

 end if

next

 

if oNetConnections is nothing then

 msgbox "未找到网络和拨号连接文件夹"

 wscript.quit

end if

 

set oLanConnection = nothing

for each folderitem in oNetConnections.items

 if lcase(folderitem.name)  = lcase(sConnectionName) then

   set oLanConnection = folderitem: exit for

 end if

next

 

if oLanConnection is nothing then

 msgbox "未找到 '" & sConnectionName & "' item"

 wscript.quit

end if

 

bEnabled = true

set oEnableVerb = nothing

set oDisableVerb = nothing

s = "Verbs: " & vbcrlf

for each verb in oLanConnection.verbs

 s = s & vbcrlf & verb.name

 if verb.name = sEnableVerb then

   set oEnableVerb = verb 

   bEnabled = false

 end if

 if verb.name = sDisableVerb then

   set oDisableVerb = verb 

 end if

next

 

'debugging displays left just in case...

'

'msgbox s ': wscript.quit

'msgbox "Enabled: " & bEnabled ': wscript.quit

 

'not sure why, but invokeverb always seemed to work

'for enable but not disable. 

'

'saving a reference to the appropriate verb object

'and calling the DoIt method always seems to work.

'

if bEnabled then

'  oLanConnection.invokeverb sDisableVerb

 oDisableVerb.DoIt

else

'  oLanConnection.invokeverb sEnableVerb

 oEnableVerb.DoIt

end if

 

'adjust the sleep duration below as needed...

'

'if you let the oLanConnection go out of scope

'and be destroyed too soon, the action of the verb

'may not take...

'

wscript.sleep 400

---------------------

将以上文件存为VBS文件,运行一次,就禁用"本地连接",再运行一次,就启用"本地连接".

如果名字不一样,可以更改第二行引号内名字.

 

祝好运..

阅读(4093) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~