How to connect to a network using VBScript

Using VBScript, we can easily work with automating network connections such as: Connect to wifi , Disable a firewall etc.

VBScript comes with inbuilt capability to handle network connections and so many other options in windows extremely well that you will be amazed..

In this page we will have a complete solution of disable network, connect network, disconnect a network, close a firewall using vbscript. 

How to connect to a network using VBScript – Example code
'The following code can be used to connect disable and enable network (name may need to be modified according to the actual conduct):

Const ssfCONTROLS = 3
sConnectionName = "The wireless network connection"

sEnableVerb = "Enable(&A)"
sDisableVerb = "Disable(&B)"

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

set oNetConnections = nothing
for each folderitem in oControlPanel.items
 if = "The network connection" then
  set oNetConnections = folderitem.getfolder: exit for
 end if

if oNetConnections is nothing then
 msgbox "Network and dial up Connections folder was not found"
end if

set oLanConnection = nothing
for each folderitem in oNetConnections.items
 if lcase( = lcase(sConnectionName) then
  set oLanConnection = folderitem: exit for
 end if

if oLanConnection is nothing then
 msgbox "Not found '" & sConnectionName & "' item"
end if

bEnabled = true
set oEnableVerb = nothing
set oDisableVerb = nothing
s = "Verbs: " & vbcrlf
for each verb in oLanConnection.verbs
 s = s & vbcrlf &
 if = sEnableVerb then
  set oEnableVerb = verb
  bEnabled = false
 end if
 if = sDisableVerb then
  set oDisableVerb = verb
 end if

if bEnabled then
' oLanConnection.invokeverb sDisableVerb
' oLanConnection.invokeverb sEnableVerb
end if

wscript.sleep 400

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.