正 文

用脚本实现禁用和启用某网络连接


www.7dspace.com  更新日期:2006-1-10 3:19:23  七度空间


  1.一个方法是用Devcon

  这是Windows DDK里面的一个工具, 参见:http://support.microsoft.com/default.aspx?scid=KB;EN-US;q311272

  可以下载Devcon的package.

  2. 还有方法就是写vbscript的脚本......

'
' Toggle the Local Area Connection inside Network Connections
'

'Virtual folder containing icons for the Control Panel applications. (value = 3)
Const ssfCONTROLS = 3

sConnectionName = "Local Area Connection 2"  ' <-- change here

sEnableVerb = "En&able"  '<-- change here
sDisableVerb = "Disa&ble"  '<-- change here

set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

set oNetConnections = nothing
for each folderitem in oControlPanel.items
  if folderitem.name  = "Network Connections" Then  '<--- change here
    set oNetConnections = folderitem.getfolder: exit for
  end if
next

if oNetConnections is nothing then
  msgbox "Couldn't find 'Network Connections' folder"
  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 "Couldn't find '" & 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

if bEnabled then
  oDisableVerb.DoIt
else
  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 1000

  请根据OS及语言版本, 自行调节加注了"change here"的地方. 这个程序, 只是在enable/disable之间切换. 可以更加需要添加脚本的命令行参数.


上一篇:八种常见的ADSL断流现象
下一篇:合成与后期光影-超级战士
作者:asap  来源:DRL ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐