How do I toggle internet connection on/off

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way for me to create a two key combination that will toggle my
internet connection on/off? I am right clicking a shortcut to my connection
and choosing "disable". I'd like a less cumbersome method.
Thanks much.
 
Rat said:
Is there a way for me to create a two key combination that will toggle
my internet connection on/off? I am right clicking a shortcut to my
connection and choosing "disable". I'd like a less cumbersome method.
Hi

You can do it by creating a shortcut that have a keyboard shortcut key,
and let the shortcut point to a VBScript that does the job.


With Shell.Application/VBScript (Win2k and WinXP):

From: Michael Harris
Subject: Re: How to disable-Enable Local area Connection via script
Newsgroups: microsoft.public.scripting.vbscript
Date: 2002-03-25 11:36:10 PST
http://groups.google.co.uk/groups?selm=OcFYOQD1BHA.2848@tkmsftngp05
 
Torgeir Bakken (MVP) said:
Hi

You can do it by creating a shortcut that have a keyboard shortcut key,
and let the shortcut point to a VBScript that does the job.


With Shell.Application/VBScript (Win2k and WinXP):

From: Michael Harris
Subject: Re: How to disable-Enable Local area Connection via script
Newsgroups: microsoft.public.scripting.vbscript
Date: 2002-03-25 11:36:10 PST
http://groups.google.co.uk/groups?selm=OcFYOQD1BHA.2848@tkmsftngp05


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Thank you for the response. I have never worked with a VB script. Can you
give me instructions on how to accomplish this task?
 
Rat said:
Thank you for the response. I have never worked with a VB script. Can you
give me instructions on how to accomplish this task?
Hi

1.
Open Notepad.

2.
Paste the script in the link I gave you into the Notepad document.

3.
At the line

sConnectionName = "Local Area Connection"

change "Local Area Connection" to the name you have on
your connection (unless it is "Local Area Connection").

4.
Save the file with a .vbs file extension (e.g. call it
ToggleConnection.vbs)

5.
Run the file by double clicking on it.
 
Torgeir Bakken (MVP) said:
Hi

1.
Open Notepad.

2.
Paste the script in the link I gave you into the Notepad document.

3.
At the line

sConnectionName = "Local Area Connection"

change "Local Area Connection" to the name you have on
your connection (unless it is "Local Area Connection").

4.
Save the file with a .vbs file extension (e.g. call it
ToggleConnection.vbs)

5.
Run the file by double clicking on it.


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Thank you. Sorry for my lack of knowledge but i have followed the
instructions and get the following error......"Couldn't find 'Network and
Dial-up Connections' folder"
 
Rat said:
Thank you. Sorry for my lack of knowledge but i have followed
the instructions and get the following error......"Couldn't find
'Network and Dial-up Connections' folder"
Hi

In the script, change

Network and Dial-up Connections

to

Network Connections

(two places in the script)
 
Torgeir Bakken (MVP) said:
Hi

In the script, change

Network and Dial-up Connections

to

Network Connections

(two places in the script)


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Sorry,still having trouble,
Now I get a"couldn't find 'Network Connections' folder". I tried re-naming
the sConnectionName = "Local Area Connection" to no avail. Here is what I
have......


Const ssfCONTROLS = 3

sConnectionName = "Local Area Connection"

sEnableVerb = "En&able"
sDisableVerb = "Disa&ble"

set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

set oNetConnections = nothing
for each folderitem in oControlPanel.items
if folderitem.name = "Network Connections" then
set oNetConnections = folderitem.getfolder: exit for
end if
next

if oNetConnections is nothing then
msgbox "Couldn't find 'Network Connections' folder"
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 "Couldn't find '" & 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 1000
 
Torgeir Bakken (MVP) said:
Hi

In the script, change

Network and Dial-up Connections

to

Network Connections

(two places in the script)


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx



Hi,
Sorry but I am still having trouble. After the changes above I get...
"Couldn't find 'Network Connections' folder"

I also tried re-naming the sConnectionName to no avail.
This is what I have so far....

Const ssfCONTROLS = 3

sConnectionName = "Local Area Connection"

sEnableVerb = "En&able"
sDisableVerb = "Disa&ble"

set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

set oNetConnections = nothing
for each folderitem in oControlPanel.items
if folderitem.name = "Network Connections" then
set oNetConnections = folderitem.getfolder: exit for
end if
next

if oNetConnections is nothing then
msgbox "Couldn't find 'Network Connections' folder"
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 "Couldn't find '" & 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 1000

Thank you so much for your help.
 
Rat said:
Hi,
Sorry but I am still having trouble. After the changes above I get...
"Couldn't find 'Network Connections' folder"

I also tried re-naming the sConnectionName to no avail.
This is what I have so far....

Const ssfCONTROLS = 3

sConnectionName = "Local Area Connection"

sEnableVerb = "En&able"
sDisableVerb = "Disa&ble"

set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

set oNetConnections = nothing
for each folderitem in oControlPanel.items
if folderitem.name = "Network Connections" then


You have two spaces in "Network Connections", you must only
have one...
 
Torgeir Bakken (MVP) said:
You have two spaces in "Network Connections", you must only
have one...




--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Done. I still get "Couldn't find 'Network Connections' folder"
here's what i have....

Const ssfCONTROLS = 3

sConnectionName = "Local Area Connection"

sEnableVerb = "En&able"
sDisableVerb = "Disa&ble"

set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

set oNetConnections = nothing
for each folderitem in oControlPanel.items
if folderitem.name = "Network Connections" then
set oNetConnections = folderitem.getfolder: exit for
end if
next

if oNetConnections is nothing then
msgbox "Couldn't find 'Network Connections' folder"
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 "Couldn't find '" & 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 1000
 
Rat said:
Done. I still get "Couldn't find 'Network Connections' folder"
here's what i have....

Const ssfCONTROLS = 3

sConnectionName = "Local Area Connection"

sEnableVerb = "En&able"
sDisableVerb = "Disa&ble"

set shellApp = createobject("shell.application")
set oControlPanel = shellApp.Namespace(ssfCONTROLS)

set oNetConnections = nothing
for each folderitem in oControlPanel.items
if folderitem.name = "Network Connections" then
Hi

You still have two spaces in the "Network Connections" part
(you only updated the MsgBox text).
 
Torgeir Bakken (MVP) said:
Hi

You still have two spaces in the "Network Connections" part
(you only updated the MsgBox text).



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

I missed that...thought that i did that one.
That did it.
Thank you very much for your help....and your patience.
 
Back
Top