How to use netsh with Unicode network adapter names

0

I run my Windows 7 laptop in Spanish as it helps me learn that language. Recently I wanted to set up a DOS batch file to disable a number of network adapters - however in Spanish, the network adapter names use special (non-ANSI) characters. For example the accented characters in this name:

Conexión de área local 4

I copy/pasted the names from the Network Connections window into my .bat file, but on execution got the error "No existe una interfaz con este nombre registrada con el enrutador", i.e. it couldn't find an adapter with that exact name.

Using Notepad++, I changed the encoding of my .bat file from ANSI to UTF-8 (both with and without BOM), but continued to get the same error. (I pasted in the adapter name each time after changing encoding).

So the question is, what is the best way to get the exact adapter name into my batch file, so that it will be recognised by Windows when I execute it?

Mike

Posted 2016-01-28T07:40:15.363

Reputation: 193

You're not telling us which character set your Spanish Windows actually uses. It looks like it's not ANSI (and that would in fact be very unusual). So presumably, it's using an ISO Latin character set whichshould be able to represent Spanish characters. Opposed to that, if you use a different encoding in your editor for a BAT file, you'd have to tell the command interpreter that the BAT file is not encoded in the system's default character set. – Run CMD – 2016-01-28T08:04:41.267

The cmd.exe interpreter doesn't support UTF-8, but it should work with UTF-16... – user1686 – 2016-01-28T08:07:59.337

@ClassStacker - when I run chcp in a command window, I get the active code page is 850. Is that what you were asking? – Mike – 2016-01-28T08:28:24.963

@ClassStacker - that led me to change my .BAT file to use Character Set OEM 850 in Notepad++, and now it works perfectly. Can you add this as an answer so I can accept it? (Strangely the Bluetooth adapter is still an exception tho'). – Mike – 2016-01-28T08:30:49.373

You could try UTF-16 in line with @grawity's suggestion that cmd.exe should be able to auto detect that. -- What about the blutooth isn't working? What's even in your BAT file? – Run CMD – 2016-01-28T08:40:24.823

@ClassStacker The command that is failing is this: netsh interface set interface name="Conexión de red Bluetooth" admin=disabled The others all work, but for this one, the adapter name is not recognised for some reason. It was the same for my original solution that I posted an answer for. – Mike – 2016-01-28T08:47:35.340

Answers

0

After trying various methods, I eventually found the following worked:

  • Change my .BAT file back to ANSI
  • Run the following DOS command to generate a text file listing the adapters

    netsh interface ip show interfaces > list.txt

  • Copy/paste the adapter name from the .TXT file to my .BAT file.

I should note that the adapter name does look odd with this method, but it works:

Conexi¢n de  rea local 4

However - for some reason it doesn't work with all of my adapters. For example, this one does not get recognised when I execute the .BAT:

Conexi¢n de red Bluetooth

Mike

Posted 2016-01-28T07:40:15.363

Reputation: 193

Apply CHCP 1252 prior to running > list.txt netsh interface ip show interfaces and keep your bat script in ANSI encoding. Not much more to say not knowing related problematic code snippet. – JosefZ – 2016-07-02T10:11:11.333