Implement local connection with VBS disable/enable scripting code _vbs

Source: Internet
Author: User
Reprinted to Http://community.csdn.net/Expert/topic/4881/4881882.xml

Copy Code code as follows:

Const Ssfcontrols = 3

Sconnectionname = "Local Area Connection" can be changed to the name of the connection you want to control, such as "Wireless network Connection"

Senableverb = "enabled (&a)"
Sdisableverb = "Disabled (&b)" XP system should be "inactive (&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 "No network connection folder 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 ...
'
' 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 have the olanconnection go out of scope
' And be destroyed too soon, the action of the verb
' may not take ...
'
Wscript.Sleep 400

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.