Ghost Batch code (IP backup recovery) that automatically recovers IP after WIN7/XP is installed _dos/bat

Source: Internet
Author: User
Tags manual writing

Today, the maintenance staff to find me said, recently to push Win7, temporary desktop cloud did not promote, or the use of manual installation of Win7 way. So, need me to help write a script, probably function is to ghost Win7 before the first export XP IP information, after ghost completion, automatically read this IP information to restore IP settings.
Ghost batch processing of IP automatically after installing WIN7/XP

Before actually wrote an XP, this is Win7, in fact, the same, spent nearly half an hour test success, now to record.
Lazy to toss the compatibility method, wrote 2 export IP scripts and an IP recovery script, for ghost Remote Installation Win7 automatically restore IP settings. (Traditional environment)


1, Export winxp system IP information:

@echo off&setlocal enabledelayedexpansion 
title Windows XP IP Information Export tool (with recovery script) 
echo IP information export ... 
for/f "tokens=1,2 delims=:"%%i in (' ipconfig ') do ( 
 echo%%i | find/i "IP address" >nul && echo ip:%%j>d:\ip.txt 
 echo%%i | find/i "Subnet Mask" >nul && Ech o mk:%%j>>d:\ip.txt 
 If "! gw! "equ" 1 "call:end 
 echo%%i | find/i" Default Gateway ">nul && echo gw:%%j>>d:\ip.txt && Set gw=1 
) 
 
: End 
echo= 
echo exported complete. Any key check ... 
Pause>nul 
Start "" D:\ip.txt 
exit

2, Export Win7 system IP Information

@echo off&setlocal enabledelayedexpansion 
title Windows 7 IP Information Export tool (in conjunction with IP recovery scripts) 
echo IP information export ... 
for/f "tokens=1,2 delims=:"%%i in (' ipconfig ') do ( 
 echo%%i | find/i "IPV4 address" >nul && echo ip:%%j>d:\ip.txt 
 echo%%i | find/i "Subnet mask" >nul && echo mk:%%j& Gt;>d:\ip.txt 
 If "! gw! "equ" 1 "call:end 
 echo%%i | find/i" Preset Gates ">nul && echo gw:%%j>>d:\ip.txt && set Gw=1
   ) 
 
: End 
echo= 
echo exported complete. Any key check ... 
Pause>nul 
Start "" D:\ip.txt 
exit

Ps: Testing process, found Win7 use ipconfig command, there will be a IPV6 gateway, resulting in an error, had to use an if out of the loop.
3, the final output to the D:\ip.txt format as follows (too lazy, on three lines, manual writing is also very fast!) ):

Copy Code code as follows:

ip:10.197.198.173
mk:255.255.255.254
gw:10.197.198.1

Finally, read the D:\IP.txt content and restore the IP by following this script:

@echo off&setlocal enabledelayedexpansion 
title Ghost the IP Recovery tool after 
REM to determine if the file exists if not 
exist D:\ip.txt Goto Error 
 
REM reads information from IP.txt and sets the variable 
for/f "tokens=1,2 delims=:"%%a in (d:\ip.txt) do ( 
 if/i "%%a" = "IP" set a Ddr=%%b 
 if/i "%%a" = "MK" set mask=%%b 
 if/i "%%a" = "GW" set gateway=%%b 
) 
  
Rem Gets the name of the first network card and sets the IP, Multiple NICs will be set to the first block of 
for/f tokens^=1^,2^ delims^=^ "%%j in" (' netsh interface ip show config ') does (  
    
    if "%%j" = "Interface" (
   netsh interface IP set address name= "%%k" Source=static addr=!addr! mask=!mask! gateway=!gateway!  
     Call:end      
       
      ) 
    if "%%j" = = "Interface" ( 
     netsh interface ip set address name= "%%k" source=static addr=!addr! mask=!mas K! gateway=!gateway!  
     Call:end      
   )  
 
: 
end Echo Set complete, 3S automatic exit! 
ping-n 3 127.1 >nul 
exit 
 
: Error 
CLS 
echo error: D packing directory not found Ip.txt file! Please set IP manually, any key to exit 
... Pause>nul 
exit

This script, such as simple, fan WINXP/7 and other systems can be compatible with IP settings, in fact, is to modify the previous written windows to get the actual name of the network connection, strengthen the IP class settings script compatibility script.

4. Scripting usage:

1, Packaging Ghost system mirroring, will set the IP script to join the startup item
2, Ghost Install the system first through the "Export script" or "manual method" in the D disk to establish ip.txt, write as above three information
3, through Onekey remote recovery Ghost system mirroring, and so on, after the restoration, IP script automatically restore D disk set a good IP, then you can remotely connect the computer for maintenance, the entire process does not require on-site operation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.