CBC Computer Services

Write Batch Files to Enable & Disable Internet Connection

Here’s how you can create a batch file to control your internet connection (turn it on and off) using the netsh command to manage network interfaces.

Steps to Create the Batch Files

1. Create a Batch File to Turn Off the Internet:

  1. Open Notepad.
  2. Paste the following code to disable both Wi-Fi and Ethernet connections:
   @echo off
   netsh interface set interface "Wi-Fi" admin=disable
   netsh interface set interface "Ethernet" admin=disable
   echo Internet has been turned OFF.
   pause
  1. Save this file as Turn_Off_Internet.bat (make sure to select All Files under the “Save as type” dropdown).

2. Create a Batch File to Turn On the Internet:

  1. Open Notepad again.
  2. Paste the following code to enable both Wi-Fi and Ethernet connections:
   @echo off
   netsh interface set interface "Wi-Fi" admin=enable
   netsh interface set interface "Ethernet" admin=enable
   echo Internet has been turned ON.
   pause
  1. Save this file as Turn_On_Internet.bat.

Important Notes:

  • Wi-Fi and Ethernet are the default names for network interfaces. If your network interfaces are named differently, replace "Wi-Fi" and "Ethernet" with the correct names. You can check the exact names by typing netsh interface show interface in a command prompt.
  • To ensure the batch files work properly, run them as Administrator. Right-click on the batch file and select Run as administrator.

Now you have two batch files: one to turn off the internet and another to turn it back on, making it easy to control your connection when needed.