-1

I am unable to find a way to create a dynamic batch file for NETSH commands.

I have created static files to give IP and DNS address(es).

I want to know how do I enable user input and put those values in the succeeding command?

For example:

netsh interface set interface name=Ethernet admin=disabled

How do I create a variable which user will assign a value to and enforce that variable at place of ethernet?

Example 2:

netsh interface ipv4 set address name="Wi-Fi" static 10.0.0.159 255.255.255.0 10.0.0.1

How do I do same for multiple values such as those highlighted?

Mofi
  • 46,139
  • 17
  • 80
  • 143
Parth Maniar
  • 147
  • 5
  • Take a look at `SET /P`. – Compo Apr 22 '17 at 11:29
  • 3
    Open a command prompt window and run `set /?` to get output the help of this command explaining `set /P` syntax (P for Prompt) like `set /P "InternfaceName=Enter interface name: "` used with `netsh interface set interface "name=%InterfaceName%" admin=disabled`. – Mofi Apr 22 '17 at 11:29
  • Thank you very much. I should have thought of set as an independent command. I did not realize that when I was searching for a solution. :) – Parth Maniar Apr 22 '17 at 13:43

1 Answers1

0

To ask the user for input use this:

set /p "UserInput1=Please input parameters for the program​: "

To refer to their input use this:

%UserInput1%

The %UserInput1% will get replaced with whatever the user typed in. Please note if they type in any "&" or "|" symbols the command prompt will think that anything after that symbol is a command and will mess up. This usually won't matter though as these symbols most likely wouldn't be typed in anyway.

Mofi
  • 46,139
  • 17
  • 80
  • 143
J03L
  • 314
  • 3
  • 17