Solved

write Ipconfig commands with a batch file

Posted on 2009-07-13
13
1,698 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
  • 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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Question has a verified solution.

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

Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now