?
Solved

write Ipconfig commands with a batch file

Posted on 2009-07-13
13
Medium Priority
?
1,731 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
WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Suggested Courses

765 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