[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

write Ipconfig commands with a batch file

Posted on 2009-07-13
13
Medium Priority
?
1,758 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 600 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 600 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 800 total points
ID: 25085490
0
 

Author Comment

by:jskfan
ID: 25109057
I have PStools.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Configuring Remote Assistance for use with SCCM
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

649 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