分类: WINDOWS
2006-12-22 09:19:40
如何在XP的命令行模式下禁用或启用网卡
先看show interface 的结果, 然后选择你要disable的interface. 注意带空格的名称需要用引号.
netsh interface show interface
-------------------------------------------------------------------------
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文件,运行一次,就禁用"本地连接",再运行一次,就启用"本地连接".
如果名字不一样,可以更改第二行引号内名字.
祝好运..