2

I'm not familiar with creating .bat files, but I want to create a file to deactivate/disable a network device

enter image description here

This is in win7. I have googled some similar problems, but nothing to solve this. pls help.

suit
  • 194
Johnny
  • 21

2 Answers2

2

Perhaps you might be able use this in a batch file.
I'm unsure if your router will show up though.

Get NIC list and index number:

wmic nic get name, index

Enable NIC with index number: (eg: 7)

wmic path win32_networkadapter where index=7 call enable

Disable NIC with index number: (eg: 7)

wmic path win32_networkadapter where index=7 call disable

Here is a batch file provided on the above link (You may be able to change it to suit your application).

@echo off
cls
goto Choices

REM use this command to determine what the adapter index number is REM wmic nic get name, index

:Top choice /c:123456 If ERRORLEVEL == 6 goto Enable_Wireless_Disable_LAN If ERRORLEVEL == 5 goto Enable_LAN_Disable_Wireless If ERRORLEVEL == 4 goto Disable_Wireless If ERRORLEVEL == 3 goto Disable_LAN If ERRORLEVEL == 2 goto Enable_Wireless If ERRORLEVEL == 1 goto Enable_LAN goto EOF

:1 :Enable_LAN wmic path win32_networkadapter where index=9 call enable goto :EOF

:2 :Enable_Wireless wmic path win32_networkadapter where index=7 call enable goto :EOF

:3 :Disable_LAN wmic path win32_networkadapter where index=9 call disable goto :EOF

:4 :Disable_Wireless wmic path win32_networkadapter where index=7 call disable goto :EOF

:5 :Enable_LAN_Disable_Wireless wmic path win32_networkadapter where index=9 call enable goto :4

:6 :Enable_Wireless_Disable_LAN wmic path win32_networkadapter where index=7 call enable goto :3

:Choices echo 1 Enable LAN echo 2 Enable Wireless echo 3 Disable LAN echo 4 Disable Wireless echo 5 Enable LAN / Disable Wireless echo 6 Enable Wireless / Disable LAN goto Top

:EOF

suit
  • 194
0

Enabling or disabling a network device in the Network Devices list is identical to enabling or disabling it in the Device Manager. You can use the Microsoft tool devcon to do this from the command-line.

  1. Download the file, extract it, and put it somewhere (we’ll use c:\tools for the example below).

  2. Now you need to determine the device ID. You can do it in two ways:

    • With the Device Manager

      1. Open the Device Manager (devmgmt.msc)
      2. Expand the Network adapters branch
      3. Locate and select the device
      4. Open its Properties dialog (double-click or [Alt+]Enter or right-click→Properties or Action→​Properties)
      5. Switch to the Details tab
      6. Select the Matching Device Id field
      7. Copy the ID (e.g., PCI\VEN_1337&DEV_2600&SUBSYS_DEADCAFE)

    • With devcon

      1. Open a command-prompt
      2. Run this command:

        devcon findall * | find /i "speedtouch" > "%temp%\devcon.txt"
        
      3. Open the file %temp%\devcon.txt and find your device

        • If you don’t find your device, try leaving out the filter:

          devcon findall * > "%temp%\devcon.txt"`
          
      4. Copy the ID (you only need up until the end of the SUBSYS field)

  3. Test it (replace the path and ID with your own, and make sure to put the ID in quotes):

    devcon disable "PCI\VEN_1337&DEV_2600&SUBSYS_DEADCAFE"
    
  4. Copy it to a batch-file (make sure to include the path if you are storing the batch-file somewhere different than devcon.exe). For example:

    c:\tools\devcon disable "PCI\VEN_1337&DEV_2600&SUBSYS_DEADCAFE"
    

You can then create a shortcut to the batch-file and set it to run minimized. If you don’t need to run other commands (the batch-file only contains the single line), then you can make a shortcut to run the command directly and forgo the batch-file altogether.

You can also make a batch-file/shortcut to enable the device as well (writing one to toggle the device is a little more complicated). You can even use this to enable or disable other devices (years ago I wrote one to toggle my old gameport gamepad when running DOSBox to work around a bug).


Screenshot of NIC device ID from Device Manager

Synetech
  • 69,547