1

I have the following .bat file (called ip-set):

netsh interface ip set address name="Local Area Connection" static %ip %sub %def
pause
exit

And the following C# (which passes arguments to the .bat and executes it):

proc = new Process();
proc.StartInfo.WorkingDirectory = String.Format(@"C:\test\WindowsFormsApplication1\setup");
proc.StartInfo.FileName = "ip-set";
proc.StartInfo.Arguments = String.Format("{0} {1} {2}", textBox1.Text, textBox2.Text, textBox3.Text);
proc.Start();

I keep getting the error: "Invalid address parameter (sub). It should be a valid IPv4 address."

I don't know what's wrong / missing.

HGOC97
  • 5
  • 1
  • 4
    Where are you setting `%ip` and the rest? The parameters should be `%1`, `%2`, and `%3` – Anon Coward Nov 17 '20 at 19:28
  • 1
    Print the formatted arguments to ensure it is correct. BTW I would rather do a system call. – Tarik Nov 17 '20 at 19:29
  • Variables in batch are called with `%variable%`, not `%variable` (note the percent signs on both sides of the variable name). – SomethingDark Nov 17 '20 at 20:14
  • Batch files do not have named arguments like other scripting languages if that is what you are trying to do. – Squashman Nov 17 '20 at 21:24
  • [How can you change Network settings (IP Address, DNS, WINS, Host Name)](https://stackoverflow.com/q/209779/7444103) – Jimi Nov 18 '20 at 04:37

0 Answers0