用户登录
用户注册

分享至

本地连接禁用/启用批处理脚本

  • 作者: 率德布耀布耀德ljw
  • 来源: 51数据库
  • 2021-09-27

复制代码 代码如下:

const ssfcontrols = 3 

sconnectionname = "本地连接"  '可改成需要控制的连接名称,如"无线网络连接"等 

senableverb = "启用(&a)" 
sdisableverb = "禁用(&b)"   'xp系统中应为 "停用(&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 

软件
前端设计
程序设计
Java相关