|
Answer» Hi all after some research for a command that can get NIC name for windows OS for EXAMPLE "Ethernet" or "Local Area Connection" etc I found that command and it works properly but how we can store the output value "I mean the name of NIC" inside a variable.
here is that command
Code: [Select]wmic nic get NetConnectionID Hi Refer to this : Pass netconnectionid to a netsh interface command in batch
Code: [Select]echo off :: tokens=2 indicates that of all the tokens that would normally be returned, we only want the second one :: delims== indicates that the string should be split up wherever there is an = symbol for /f "tokens=2 delims==" %%A in ('wmic nic where "netconnectionid like '%%'" get netconnectionid /value') do ( call :dhcp "%%A" ) pause exit /b
:dhcp echo %1 :: %~1 refers to the first parameter passed into the function, but without the quotation marks ::netsh interface set address %1 dhcp We can store and set all variables into an array like this code :
Code: [Select]echo off Title Find Network Adapter name and store this name inside a variable SetLocal EnableDelayedExpansion for /f "tokens=2 delims==" %%A in ('wmic nic where "netconnectionid like '%%'" get netconnectionid /value') do ( for /f "delims=" %%B in ("%%A") do ( Set /A Count+=1 Set "NET_CONN_ID[!Count!]=%%B" ) )
for /L %%i in (1,1,%Count%) do ( echo NetConnectionId%%i = "!NET_CONN_ID[%%i]!" ) pause As a result, you can GOT some thing like me :
Code: [Select]NetConnectionId1 = "Ethernet" NetConnectionId2 = "Wi-Fi" NetConnectionId3 = "CONNEXION réseau Bluetooth"Thanks, Hackoo for your usual help but can we enable these detected Network cards also for example by using the below command.
Code: [Select]netsh interface set interface name="Name of detected network" admin=ENABLED>nul
as I tried to use this command but it doesn't work for me, so could you help.All the examples I see on the web say this is proper syntax
Code: [Select]netsh interface set interface "Ethernet" disable netsh interface set interface "Wi-Fi" enable
Quote from: Squashman on April 21, 2021, 07:24:24 AM All the examples I see on the web say this is proper syntax
Code: [Select]netsh interface set interface "Ethernet" disable netsh interface set interface "Wi-Fi" enable
Thanks, Squashman Your opinion is correct but also I saw the previous code on the web, kindly look into this link As PROOF https://stackoverflow.com/questions/19831023/enable-disable-network-connection-from-command-line. , so I'm trying to merge between two this command and Hackoo array
|