How to implement batch scripts that are disabled / enabled for local connections
This article mainly shows you "how to achieve local connection disabled / enabled batch script", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to implement local connection disabled / enabled batch script" this article.
The 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
The above is all the contents of the article "how to implement local connection disabled / enabled batch scripts". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!