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 folderitem.name = "The network connection" then set oNetConnections = folderitem.getfolder: exit for end if next if oNetConnections is nothing then msgbox "Network and dial up Connections folder was 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 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 if bEnabled then ' oLanConnection.invokeverb sDisableVerb oDisableVerb.DoIt else ' oLanConnection.invokeverb sEnableVerb oEnableVerb.DoIt 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