Get the App
SLTechnology News&Howtos  ›  Development  › 

How to disable or enable local connections with vbs

Shulou Source: shulou.com Published: 2022-06-03 19:39:04 09月29日 Update

This article mainly introduces "how to use vbs to disable or enable local connections". In daily operation, I believe many people have doubts about how to use vbs to disable or enable local connections. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to use vbs to disable or enable local connections." Next, please follow the editor to study!

The copy code is as follows:

Const ssfCONTROLS = 3

SConnectionName = "local connection" can be changed to the name of the connection to be controlled, such as "wireless network connection", etc.

SEnableVerb = "enable (A)"

SDisableVerb = "disable (& B)" in XP system should be "disable (& B)"

Set shellApp = createobject ("shell.application")

Set oControlPanel = shellApp.Namespace (ssfCONTROLS)

Set oNetConnections = nothing

For each folderitem in oControlPanel.items

If folderitem.name = "Network connection" then

Set oNetConnections = folderitem.getfolder: exit for

End if

Next

If oNetConnections is nothing then

Msgbox "Network connection folder not found"

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 "not found" & 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

At this point, the study on "how to use vbs to disable or enable local connections" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Learning networking code more help practical next names files folders articles methods wireless wireless networks theory knowledge articles systems websites materials Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia MariaDB Shulou Technology Shulou Information