5
5
5napdragon2020-12-18 21:21:13
Computer networks
5napdragon, 2020-12-18 21:21:13

How to connect to the specified network through a bat file?

In a third-party program (written in ancient Roman), I get a list of available networks, through a third-party bat file.

What I need is for me to select the network to which I want to connect in my program and bat read it, for example, from the file connectnow.txt
Text: Ethernet
Then I connected to it,
and the same thing when disconnecting from the network.
disconnectnow.txt
Text:Ethernet

Help me out

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Johnny Gat, 2020-12-19
@5napdragon

Using the contents of a file in a command:

set /p ARGS= <connectnow.txt && netsh interface set interface "%ARGS%" enable
set /p ARGS= <disconnectnow.txt && netsh interface set interface "%ARGS%" disable

Option 1 (requires admin rights):
подключиться к сети 
netsh interface set interface "Ethernet" enable
отключиться от сети
netsh interface set interface "Ethernet" disable

Option 2 (requires admin rights):
подключиться к сети
netsh interface set interface name="Ethernet" admin=ENABLED
отключиться от сети
netsh interface set interface name="Ethernet" admin=DISABLED

Option 3:
подключиться к сети
Enable-NetAdapter -InterfaceAlias "Ethernet"
отключиться от сети
Disable-NetAdapter -InterfaceAlias "Ethernet"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question