问题
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
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/43041435/assign-the-ip-address-by-the-using-the-batch-file