Solved

write Ipconfig commands with a batch file

Posted on 2009-07-13
13
1,718 Views
Last Modified: 2013-11-09

write Ipconfig command with a batch file

I need to write a batch file that runs the following commands and puts the results in C:\Result.txt file

Ipcongig /Flushdns
Ipconfig /release
Ipconfig /renew
Ipconfig /Registerdns

Thanks
0
Comment
Question by:jskfan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 8

Expert Comment

by:NotLogical
ID: 24841829
Hi,

The easiest way to do this is as follows. Start notepad, and copy the following text into it:

@echo off
echo. >> c:\Result.txt
ipconfig /flushdns >> c:\Result.txt
ipconfig /release >> c:\Result.txt
ipconfig /renew >> c:\Result.txt
ipconfig /Registerdns >> c:\Result.txt

Save this as (for example) c:\Show_Ipconfig.cmd, and you are ready to go!

This script will continually append to the c:\Result.txt file. If you want to create a new file everytime this script is run, change the second line to read "echo. > c:\Result.txt". Please note that there is no space between the echo and the "."!

Cheers,

NotLogical
0
 

Author Comment

by:jskfan
ID: 24842079
it pops up black screen (CMD window)
it stays on that windows forever
it creates 2 text files (Result) one with 0 bytes and one with incrementing bytes if I stop the script from running and go to the Result files there is nothing inside.
0
 
LVL 8

Expert Comment

by:NotLogical
ID: 24842217
Hi,

I just tried this under Windows XP, without trouble. Did you copy and paste the script directly from the text above?

Please keep in mind the following: the script will appear to "hang" if any of the commands take long to execute. So, if the DHCP release/renew take 45 seconds (due to a problem with the DHCP server), the entire script will have just a window showing and nothing will seem to happen.

Just in case, I have attached it with this comment. Please rename it from a ".txt" to a ".cmd" before using. The modified script will also show you textual progress of what it is doing. Thus, you will know which step is slow...

Cheers,

NotLogical

Show-Ipconfig.txt
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:jskfan
ID: 24842467
to make it simple.
Can you run the Ipconfig /all and put the result in Result.txt?
0
 
LVL 8

Expert Comment

by:NotLogical
ID: 24842522
Sure!

Simply take the script as indicated previously, and remove all but one of the ipconfig lines. Then, change the "/" option to be "/all" instead of whatever was there previously.

If you want to wipe out the contents of the Result.txt file between every run, change the ">>" to a single ">" in the second line of the script.

NotLogical
@echo off
echo. >> c:\Result.txt
echo Getting IP information...
ipconfig /all >> c:\Result.txt
echo IP information retrieved.

Open in new window

0
 

Author Comment

by:jskfan
ID: 24842940
do you know why it takes too long through a batch file.
if you run it in a command line: ipconfig /all it displays the config in a second.
0
 
LVL 3

Assisted Solution

by:cclassen
cclassen earned 150 total points
ID: 24844616
How are you launching the batch file, and where are you running it from?
is it possible it is not running under an appropriate security context for the commands?

If you are launching one batch file from another, it may be trying to run under 'system' context, which won't have the appropriate rights.

Can you post your file(s) here for review?  
0
 
LVL 8

Expert Comment

by:NotLogical
ID: 24845288
Hi again,

Could you explain what you mean by "too long?" Do you mean a 1/2 second, or several seconds? Can you post the output of Result.txt? Could you give a little more information about your setup?

There are several things which can affect CMD script execution -  but these are beyond the scope of your original question.

Cheers,

NotLogical
0
 
LVL 1

Assisted Solution

by:alex_vj
alex_vj earned 150 total points
ID: 24941401
Hey jskfan,

Try the following in a batch file and lemme know if it works for you.

set Logfile=C:\result.txt
@echo RENEW DNS/IP BATCH > "%Logfile%"
@echo ================== >> "%Logfile%"
ipconfig /flushdns >> "%Logfile%"2>&1
ipconfig /release >> "%Logfile%"2>&1
ipconfig /renew >> "%Logfile%"2>&1
ipconfig /registerdns >> "%Logfile%"2>&1

@echo RENEW DNS/IP BATCH HAS ENDED...
@echo REVIEW C:\result.txt FOR DETAILS. CLOSE TO EXIT !
@pause>nul
0
 
LVL 1

Expert Comment

by:alex_vj
ID: 24941415
Hey jskfan,

Also remember that the above batch script will need to be run as an administrator to give it the relevant permissions to execute the script. Right click the batch file and choose the Run As option if needed.
0
 

Author Comment

by:jskfan
ID: 25077609
how do you run this batch file against remote computers
0
 
LVL 8

Accepted Solution

by:
NotLogical earned 200 total points
ID: 25085490
0
 

Author Comment

by:jskfan
ID: 25109057
I have PStools.
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question