手机
当前位置:查字典教程网 >脚本专栏 >vbs >用vbs实现本地连接禁用/启用脚本代码
用vbs实现本地连接禁用/启用脚本代码
摘要:转载至http://community.csdn.net/Expert/topic/4881/4881882.xml复制代码代码如下:Con...

转载至http://community.csdn.net/Expert/topic/4881/4881882.xml

复制代码 代码如下:

ConstssfCONTROLS=3

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

sEnableVerb="启用(&A)"

sDisableVerb="禁用(&B)"'XP系统中应为"停用(&B)"

setshellApp=createobject("shell.application")

setoControlPanel=shellApp.Namespace(ssfCONTROLS)

setoNetConnections=nothing

foreachfolderiteminoControlPanel.items

iffolderitem.name="网络连接"then

setoNetConnections=folderitem.getfolder:exitfor

endif

next

ifoNetConnectionsisnothingthen

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

wscript.quit

endif

setoLanConnection=nothing

foreachfolderiteminoNetConnections.items

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

setoLanConnection=folderitem:exitfor

endif

next

ifoLanConnectionisnothingthen

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

wscript.quit

endif

bEnabled=true

setoEnableVerb=nothing

setoDisableVerb=nothing

s="Verbs:"&vbcrlf

foreachverbinoLanConnection.verbs

s=s&vbcrlf&verb.name

ifverb.name=sEnableVerbthen

setoEnableVerb=verb

bEnabled=false

endif

ifverb.name=sDisableVerbthen

setoDisableVerb=verb

endif

next

'debuggingdisplaysleftjustincase...

'

'msgboxs':wscript.quit

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

'notsurewhy,butinvokeverbalwaysseemedtowork

'forenablebutnotdisable.

'

'savingareferencetotheappropriateverbobject

'andcallingtheDoItmethodalwaysseemstowork.

'

ifbEnabledthen

'oLanConnection.invokeverbsDisableVerb

oDisableVerb.DoIt

else

'oLanConnection.invokeverbsEnableVerb

oEnableVerb.DoIt

endif

'adjustthesleepdurationbelowasneeded...

'

'ifyoulettheoLanConnectiongooutofscope

'andbedestroyedtoosoon,theactionoftheverb

'maynottake...

'

wscript.sleep400

【用vbs实现本地连接禁用/启用脚本代码】相关文章:

VBS调用WMI实现搜索硬盘mp3文件

用VBS实现PHP的md5_file函数代码

用VBS模拟实现PHP的sha1_file函数效果代码

用vbs实现按创建日期的顺序列出一个文件夹中的所有文件

encrypt.vbs 内容加密vbs实现代码

用vbs实现定时运行web文件的方法

两个批量挂马vbs脚本代码

vbs正则表达式代码

CMD和vbs修改 IP地址及DNS的实现代码

多进程的实现投票的vbs脚本

精品推荐
分类导航