1

I have a batch file (run.bat) which is to change my IP address setting:

netsh
interface
ip
set address "lan" static 192.168.30.77 255.255.255.0 192.168.30.2

The command worked as I expected when I type it directly in a cmd shell, but not when I put it in run.bat (which I ran with administrator access).

How do I fix this?

1

When you type netsh at the Command Prompt (cmd) prompt, you start running the netsh.exe program.  The next three lines are input to that program, and are read and processed by that program.

cmd isn't set up to allow that sort of thing in a .BAT file.  But you can do the following workaround to make the netsh-related commands be input to netsh:

(echo interface & echo ip & echo set address "lan" static 192.168.30.77 255.255.255.0 192.168.30.2) | netsh

To make your script more readable, break the long line with a ^:

(echo interface & echo ip & echo set address "lan" ^
  static 192.168.30.77 255.255.255.0 192.168.30.2) | netsh
1

You need to put the entire command on one line so that it gets passed to the netsh executable.

netsh interface ip set address "lan" static 192.168.30.77 255.255.255.0 192.168.30.2

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.