I'm trying to set DNS (both primary and secondary) for a network adapter using command prompt. So I created a windows shortcut with the following command:

C:\Windows\System32\netsh.exe interface ipv4 add dnsservers "Ethernet" address= index=1 & C:\Windows\System32\netsh.exe interface ipv4 add dnsservers "Ethernet" address= index=2

but for some reason it's not working (neither giving any error). If I execute this command directly in command prompt, it works! Needless to say, I'm running the shortcut as admin, so it isn't any permission issue. However, I can't figure out what it is. Am I missing something?

Any help will be really appriciated. Thanks!


The & command separator is a feature of the Cmd.exe interpreter – it is not universal to launching programs in Windows. Other means of starting programs (ShellExecute in this case) do not understand any Cmd-specific syntax and simply run everything as one command with the & as an ordinary parameter.

(This is very similar to how things work in Linux, with many such things being interpreted by the shell.)

To run two commands, either

a) put them both in a script file (.bat/.cmd) and make a shortcut to that script, or

b) invoke Cmd and ask it to interpret the command line:

cmd /c "netsh this & netsh that"
  • Thank you so much for your help! Much appreciated :) – baburao May 4 '19 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.