Using Command Prompt: Network Commands in Batch Files

FOR~GO
(For Geeks Only)
By Joe Callison
10 October 2020

Probably the most common use for the command prompt is to run ipconfig to view the network properties. It only takes a few steps- opening the command prompt app (at least two steps) and typing ipconfig and then enter (two more steps). A batch file can be created to reduce these tasks to just opening the batch file which then runs the tasks for you. A batch file is created using a plain text editor such as the Windows Notepad app.  

For the example above, the file could be:

@echo off (This turns off displaying the commands when the batch file runs)
ipconfig /all (This command will display the network properties of all network adapters)
pause (This keeps the command prompt app from automatically closing after running)

To convert the text file (txt) to a batch file (bat) just requires saving or renaming the file with a bat file extension in place of the txt file extension. Opening the batch file will automatically associate it with the command prompt app for running unless the default file association for bat has been changed to some other app.

If you want a more useful display of network adapter properties, try the following batch files:

For a wired Ethernet connection:
@echo off
netsh lan show interface
pause

For a wireless Ethernet connection:
@echo off
netsh wlan show interface
pause

If you should happen to use a command in a batch file that requires running with elevated privileges (run as administrator), this can be accommodated by first creating a shortcut to the batch file (right-click on the batch file, choose Create shortcut) and then changing the shortcut properties under the Advanced tab to check the Run as administrator (right-click on the shortcut, choose Properties, click on Advanced, check the Run as administrator). Then you can use the shortcut to run the batch file.

Posted by Joe Callison

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.