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. 

Function to connect a network using vbscript

'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
' Disable the Firewall

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
objPolicy.FirewallEnabled = FALSE

Set objPolicy = Nothing
Set objFirewall = Nothing

Subscribe for updates