2

i have a batch file for assigning the static ip by only to click the batch file . but its showing error (the filename, directory name, or volume label syntax is incorrect.” ) on some systems. what would be the solutoin.

my batch file is

 netsh interface ip set address "Wireless Network Connection" static 192.168.1.26 255.255.255.0 192.168.1.1 
netsh interface ip set dns "Wireless Network Connection" static 8.8.8.8
netsh interface ip add dns "Wireless Network Connection" 4.2.2.2
npocmaka
  • 55,367
  • 18
  • 148
  • 187
sahil
  • 23
  • 1
  • 3
  • `netsh interface ip add /?` does not show `add dns` but `add dnsservers` – JosefZ Mar 27 '17 at 08:51
  • I get the very same error msg with the first command on a system without a wlan adapter. –  Mar 27 '17 at 08:53

2 Answers2

0

The problem seems to be with the connection name. If you run

netsh interface ip set address "Wireless Network Connection" static 192.168.1.26 255.255.255.0 192.168.1.1

"Wireless Network Connection" should exist exactly like that given name as an interface. It is like an Alias name you are referencing.

If you look at your interfaces by netsh interface ip show config does "Wireless Network Connection" actually exist? Might be something else like "Wireless Network Connection 2" and then you will then get the exact error as you have posted.

EDIT

As per your comment.

Remember to add the correct interface name for each of the lines, but your latest problem is really with adding the DNS server in the last line

netsh interface ip set address "Connection name goes here" static 192.168.1.26 255.255.255.0 192.168.1.1 
netsh interface ip set dns "Connection name goes here" static 8.8.8.8
netsh interface ip add dnsserver "Connection name goes here" address=4.2.2.2 index=1

note you can also use

 netsh interface ipv4 add dnsserver "Connection name goes here" address=4.2.2.2 index=1

As far as index=1 is concerned, remember to set it according to which DNS server you want to index first.

  • can anyone send the batch file to connect my automatic network interface and automatic assign the static ip address by one click of that file – sahil Mar 27 '17 at 11:46
  • @sahil, please post a new question with detailed requirements and I will answer. –  Mar 27 '17 at 12:00
  • i need the complete batch file which automatic set my wireless network interface(it means name that is connected) and automatic set the complete static ip configuration by just click to that batch file , please send me the batch file , as i have sent you in my previous question but its fine for onw line but for dns its showing incorrect, on some system it works fine , so please send me that correct file code. – sahil Mar 27 '17 at 12:24
0

Looks like you try to change a nonexistent connection.
I'd enumerate the current connections first:

for /f tokens^=2delims^=^" %%A in (
  'netsh interface ip show config'
) Do Echo %%A

Sample output:

> List-Conn.cmd
LAN-Verbindung
Ethernet 2
Loopback Pseudo-Interface 1