How to Disable a Network in VB Script

How to Disable a Network in VB Script thumbnail
Disable a Network in VB Script

VBScript is a type of script language developed by Microsoft. You can use it in various environments such as web client scripting via web browsers and web server scripting in Microsoft Internet Information Service. It is simple to use if you already know Visual Basic. You can disable or enable a network connection in VBScript using NAMESPACE method. NAMESPACE method creates and returns a folder object for the specific folder.

Things You'll Need

  • Cscript.exe
  • Notepad
Show More

Instructions

    • 1

      Download Cscript.exe from Microsoft website (see resources). Double-click it to run. Cscript.exe is a command-line version of the Windows Script Host which offers command-line options for setting script properties.

    • 2

      Open your notepad and enter the following code with comments:

      'Define Variables;

      Const Connection_CONTROLS = 3

      Connection_Name = "Local Area Connection"

      Enable_Verb = "Enable"

      Disable_Verb = "Disable"

      'Define shell application

      set shellApp = createobject("shell.application")

      'define the folder object

      set Control_Panel = shellApp.Namespace(Connection_CONTROLS)

      set Net_Connections = nothing

      'Check all the network connections

      for each folderitem in Control_Panel.items

      if folderitem.name = "Network Connections" then

      'Disable the network connection

      set Net_Connections = folderitem.getfolder: exit for

      end if

      next

      Save the file as networkconnection.vbs.

    • 3

      Disable the network connection using the following code:

      bEnabled = true

      set Enable_Verb = nothing

      s = "Verbs: " & vbcrlf

      for each verb in Net_Connections.verbs

      s = s & vbcrlf & verb.name

      if verb.name = Enable_Verb then

      set Enable_Verb = verb

      bEnabled = false

      end if

      next

      Save the file.

    • 4

      Type networkconnection.vbs in the command-line of Cscript. Press "Enter" to run the VBScript file.

Related Searches:

References

Resources

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images

Comments

Related Ads

Featured