请教:如何用dos命令禁用网络连接?

eastnofail 2006-03-09 06:32:37
请教:如何用dos命令禁用网络连接?
...全文
938 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
myqiao 2006-03-16
  • 打赏
  • 举报
回复
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脚本,运行一次就禁用"本地连接",再运行一次就启用,
如果其他名字,可以自己改,只要将第二行的本地连接,改为你在右键网上领居->属性里看到的名称就行了...

在2000环境下测试成功,
祝你好运...
scz123 2006-03-16
  • 打赏
  • 举报
回复
论坛上以前有过同样的话题。
参考:http://topic.csdn.net/t/20040720/19/3193591.html
Snakesnoop 2006-03-10
  • 打赏
  • 举报
回复
net stop service
sandwich1981 2006-03-10
  • 打赏
  • 举报
回复
net stop

6,850

社区成员

发帖
与我相关
我的任务
社区描述
Windows 2016/2012/2008/2003/2000/NT
社区管理员
  • Windows Server社区
  • qishine
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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