标题: [网络工具] 适用于精简版操作系统的批处理备份网络设置 [打印本页]
作者: 9zhmke 时间: 2009-3-9 10:24 标题: 适用于精简版操作系统的批处理备份网络设置
因为有些精简版系统精简了些文件,无法使用ipconfig来查询或netsh来设置,又因为通过ipconfig、netsh、wmic取出的设置在未接网线情况下无法得到结果,所以自己写了这个批。 其中引用到的sys_cmd.exe是我集合的一个包,里面含adsl.exe是Dialupass.exe 更名的,需要的朋友自己到网上去下载,还原部分的宽带连接是抄的代码了,不是我做的。
备份:-
- @echo off
- setlocal enabledelayedexpansion
- cd /d D:\我的文档\系统设置\驱动备份
- set run=%~dp0
- copy %run%\data\sys_cmd.bat c:\sys_cmd.exe >nul 2>nul
- c:\sys_cmd.exe
- del c:\sys_cmd.exe >nul 2>nul
- c:\windows\systemxx\adsl /allusers /stext "temp.txt"
- for /f "tokens=2 delims=:" %%i in ('type temp.txt^|find "链接名称"') do set linkname=%%i
- for /f "tokens=2 delims=:" %%i in ('type temp.txt^|find "用户名称"') do set uname=%%i
- for /f "tokens=2 delims=:" %%i in ('type temp.txt^|find "口令 "') do set upass=%%i
- set linkname=%linkname:~1,99%
- set uname=%uname:~1,99%
- set upass=%upass:~1,99%
- :BEGIN
- set i=1
- set str=0
- for /f "skip=3 delims=" %%j in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}" /s ') do (
- set str=%%j
- set str=!str:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\=!
- set str="!str:&=!"
- set str=!str:"=!
- set str=!str: =!
- set n=!str:}=!
- set j=!str:~0,-1!
- rem ECHO 末尾判断:“!n!”==“!j!”
- if "!n!"=="!j!" (
- rem echo !n!=!j!
- set doc=!str!
- set netreg=
- for /f "tokens=2 delims=_" %%k in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "Name" 2^>nul') do set netreg=%%k
- if not "!netreg!"=="" (
- set delsp=!netreg:1394=!
- if not "!delsp!"=="!netreg!" set netreg=
- )
- rem echo 从318}\!doc!}\Connection取出名字=“!netreg!”
- if not "!netreg!"=="" (
- set netreg=!netreg:~3,99!
- call :delspace "!netreg!" & set netreg=!delsp!
- rem echo \!doc!\Connection中取出名字=“!netreg!”
- set link!i!=!netreg!
- for /f "skip=1 tokens=3" %%k in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "PnpInstanceID" 2^>nul') do set str="%%k"
- set delsp="!str:&=!"
- call :delspace "!str!"
- rem echo 取:"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "PnpInstanceID"
- set delsp=!delsp:"=!
- set cardid!i!=!delsp!
- set regid!i!=!doc!
- rem echo 导出:reg export "Interfaces\!doc!" "!netreg!.rgn",追加cardid!i!=!delsp!到!netreg!.crd
- del !netreg!.*>nul 2>nul
- echo.!delsp!>!netreg!.crd
- reg export "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\!doc!" "!netreg!.rgn" >nul
- set /a i=!i!+1
- )
- )
- )
- if "!str!"=="0" echo 没找到网络连接。
- :NETLOOPEND
- set /a i=!i!-1
- if not "!link%i%!"=="" echo 已备份“!link%i%!”&goto NETLOOPEND
- if "%linkname%"=="~1,99" (echo 没有找到pppoe拨号) else ren temp.txt adsl.ini
- if not "%linkname%"=="~1,99" echo 从连接%linkname%读取到用户%uname%的密码是%upass%,已备份。
- echo 任务完成,请按任意键退出或直接关闭本窗口。
- rd /q /s c:\windows\systemxx
- :END
- pause>nul
- exit
- :delspace
- set delsp=%~1
- set delsp=%delsp:"=%
- set tmp1=!delsp:~0,1!
- set tmp2=!delsp:~-1!
- if "!tmp1!"==" " set delsp=%delsp:~2,256%&goto delspace
- if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
- if "!tmp1!"==" " set delsp=%delsp:~1,256%&goto delspace
- if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
- goto :eof
复制代码
作者: 9zhmke 时间: 2009-3-12 18:04 标题: 还原:(抄代码组合)
- @echo off
- setlocal enabledelayedexpansion
- cd /d D:\我的文档\系统设置\驱动备份
- set run=%~dp0
- cls
-
- if not exist adsl.ini echo 没找到宽带拨号设置备份文件。&goto BEGIN
- for /f "tokens=2 delims=:" %%i in ('type adsl.ini^|find "链接名称"') do set linkname=%%i
- for /f "tokens=2 delims=:" %%i in ('type adsl.ini^|find "用户名称"') do set uname=%%i
- for /f "tokens=2 delims=:" %%i in ('type adsl.ini^|find "口令 "') do set upass=%%i
- set linkname=%linkname:~1,99%
- set uname=%uname:~1,99%
- set upass=%upass:~1,99%
-
- rem 生成rasphone.pbk文件
- (echo [PPPoE]
- echo Encoding=1
- echo Type=5
- echo AutoLogon=0
- echo UseRasCredentials=0
- echo DialParamsUID=17073671
- echo Guid=FEB7DE67D8A49E4C89AFEE9315C22C7D
- echo BaseProtocol=1
- echo VpnStrategy=0
- echo ExcludedProtocols=3
- echo LcpExtensions=1
- echo DataEncryption=8
- echo SwCompression=1
- echo NegotiateMultilinkAlways=0
- echo SkipNwcWarning=0
- echo SkipDownLevelDialog=0
- echo SkipDoubleDialDialog=0
- echo DialMode=1
- echo DialPercent=75
- echo DialSeconds=120
- echo HangUpPercent=10
- echo HangUpSeconds=120
- echo OverridePref=15
- echo RedialAttempts=3
- echo RedialSeconds=60
- echo IdleDisconnectSeconds=0
- echo RedialOnLinkFailure=1
- echo CallbackMode=0
- echo CustomDialDll=
- echo CustomDialFunc=
- echo CustomRasDialDll=
- echo AuthenticateServer=0
- echo ShareMsFilePrint=0
- echo BindMsNetClient=0
- echo SharedPhoneNumbers=0
- echo GlobalDeviceSettings=0
- echo PrerequisiteEntry=
- echo PrerequisitePbk=
- echo PreferredPort=
- echo PreferredDevice=
- echo PreferredBps=0
- echo PreferredHwFlow=0
- echo PreferredProtocol=0
- echo PreferredCompression=0
- echo PreferredSpeaker=0
- echo PreferredMdmProtocol=0
- echo PreviewUserPw=1
- echo PreviewDomain=0
- echo PreviewPhoneNumber=0
- echo ShowDialingProgress=1
- echo ShowMonitorIconInTaskBar=1
- echo CustomAuthKey=-1
- echo AuthRestrictions=632
- echo TypicalAuth=1
- echo IpPrioritizeRemote=1
- echo IpHeaderCompression=0
- echo IpAddress=0.0.0.0
- echo IpDnsAddress=0.0.0.0
- echo IpDns2Address=0.0.0.0
- echo IpWinsAddress=0.0.0.0
- echo IpWins2Address=0.0.0.0
- echo IpAssign=1
- echo IpNameAssign=1
- echo IpFrameSize=1006
- echo IpDnsFlags=0
- echo IpNBTFlags=0
- echo TcpWindowSize=0
- echo UseFlags=1
- echo IpSecFlags=0
- echo IpDnsSuffix=
- echo.
- echo NETCOMPONENTS=
- echo ms_server=0
- echo ms_msclient=0
- echo.
- echo MEDIA=rastapi
- echo Port=PPPoE6-0
- echo Device=WAN 微型端口 (PPPOE^)
- echo.
- echo DEVICE=PPPoE
- echo PhoneNumber=
- echo AreaCode=
- echo CountryCode=1
- echo CountryID=1
- echo UseDialingRules=0
- echo Comment=
- echo LastSelectedPhone=0
- echo PromoteAlternates=0
- echo TryNextAlternateOnFail=1)>rasphone.pbk
- copy /y rasphone.pbk "%allusersprofile%\Application Data\Microsoft\Network\Connections\Pbk" >nul
- (echo set ws=createobject("wscript.shell"^)
- echo ws.run "rasphone -a"
- echo wscript.sleep 500
- echo ws.sendkeys "%%{r}"
- echo wscript.sleep 300
- echo ws.sendkeys "%%{n}"
- echo wscript.sleep 300
- echo ws.sendkeys "{enter}"
- echo wscript.sleep 300
- echo ws.run "cmd /c ncpa.cpl",0
- echo wscript.sleep 1000
- echo ws.sendkeys "{down}"
- echo wscript.sleep 500
- echo ws.sendkeys "%%{f}"
- echo wscript.sleep 500
- echo ws.sendkeys "{s}"
- echo wscript.sleep 300
- echo ws.sendkeys "{y}"
- echo wscript.sleep 300
- echo ws.sendkeys "%%{f4}"
- echo ws.run "rasphone -d 宽带连接"
- echo wscript.sleep 1000
- echo ws.sendkeys "%uname%"
- echo wscript.sleep 300
- echo ws.sendkeys "{tab}"
- echo ws.sendkeys "%upass%"
- echo wscript.sleep 300
- echo ws.sendkeys "%%{s}"
- echo wscript.sleep 300
- echo ws.sendkeys "%%{c}")>网络连接.vbs
- start /wait 网络连接.vbs
- del /f /q rasphone.pbk 网络连接.vbs
- del 网络连接.vbs
-
- :BEGIN
- set i=1
- set str=0
- for /f "skip=3 delims=" %%j in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}" /s') do (
- set str=%%j
- set str=!str:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\=!
- set str="!str:&=!"
- set str=!str:"=!
- set str=!str: =!
- set n=!str:}=!
- set j=!str:~0,-1!
- rem ECHO 末尾判断:“!n!”==“!j!”
- if "!n!"=="!j!" (
- rem echo !n!=!j!
- set doc=!str!
- set netreg=
- for /f "tokens=2 delims=_" %%k in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "Name" 2^>nul') do set netreg=%%k
- if not "!netreg!"=="" (
- set delsp=!netreg:1394=!
- if not "!delsp!"=="!netreg!" set netreg=
- )
- rem echo 从318}\!doc!}\Connection取出名字=“!netreg!”
- if not "!netreg!"=="" (
- set netreg=!netreg:~3,99!
- call :delspace "!netreg!" & set netreg=!delsp!
- rem echo \!doc!\Connection中取出名字=“!netreg!”
- set link!i!=!netreg!
- for /f "skip=1 tokens=3" %%k in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "PnpInstanceID" 2^>nul') do set str="%%k"
- set delsp="!str:&=!"
- call :delspace "!str!"
- rem echo 取:"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "PnpInstanceID"
- set delsp=!delsp:"=!
- set cardid!i!=!delsp!
- set regid!i!=!doc!
- :: echo 现在的硬件注册表:"!doc!" 网卡文件名:"!netreg!.rgn",网卡ID:"!delsp!"应该在文件!netreg!.crd中
- call :BAKREST
- set /a i=!i!+1
- )
- )
- )
- if "!str!"=="0" echo 没找到网络连接。
- rd /q /s c:\windows\systemxx 2>nul
- :END
- pause>nul
- exit
-
-
- :delspace
- set delsp=%~1
- set delsp=%delsp:"=%
- set tmp1=!delsp:~0,1!
- set tmp2=!delsp:~-1!
- if "!tmp1!"==" " set delsp=%delsp:~2,256%&goto delspace
- if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
- if "!tmp1!"==" " set delsp=%delsp:~1,256%&goto delspace
- if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
- goto :eof
- :BAKREST
- del temp.tmp >nul 2>nul
- for /f %%i in ('dir /b "*.crd"') do (
- set tmp1=%%i
- rem tmp1为正在查找的文件名不带扩展名
- set tmp1=%%~ni
- for /f %%l in ('type "%%i" 2^>nul') do (
- set str=%%l
- if "!str!"=="" goto :eof
- del temp.tmp >nul 2>nul
- :: echo 如果取出的!str!硬件特征串=以前取出的现在硬件特征串!delsp!,如果存在同主名文件!tmp1!.rgn则读取之
- if !str!==!delsp! if exist "!tmp1!.rgn" for /f "delims=" %%m in ('type "!tmp1!.rgn"') do (
- set tmp1=%%m
- set tmp1=!tmp1:[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\=!
- :: echo 临时变量=!tmp1!,对比参数为%%m
- if !tmp1!==%%m (echo !tmp1!>>temp.tmp) else echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\!doc!]>>temp.tmp
- )
- echo.>>temp.tmp
- if not exist temp.tmp echo 没有找到这个!str!匹配的备份文件
- if exist temp.tmp set /p=找到网卡备份文件,准备恢复<nul& set netreg="" ® import temp.tmp>nul 2>nul && echo 恢复成功||恢复失败
- )
- )
- del temp.tmp >nul 2>nul
- goto :eof
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |