Disable/enable scripts for local connections

Source: Internet
Author: User

Reprinted to http://community.csdn.net/Expert/topic/4881/4881882.xml

Const ssfcontrols = 3

Sconnectionname = "Local Connection" can be changed to the name of the connection to be controlled, such as "wireless network connection ".

Senableverb = "enable (& )"
Sdisableverb = "disabled (& B)" 'xp system should be "disabled (& 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
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
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

'Destgging 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

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.