[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[网络工具] 适用于精简版操作系统的批处理备份网络设置

因为有些精简版系统精简了些文件,无法使用ipconfig来查询或netsh来设置,又因为通过ipconfig、netsh、wmic取出的设置在未接网线情况下无法得到结果,所以自己写了这个批。 其中引用到的sys_cmd.exe是我集合的一个包,里面含adsl.exe是Dialupass.exe 更名的,需要的朋友自己到网上去下载,还原部分的宽带连接是抄的代码了,不是我做的。

备份:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. cd /d D:\我的文档\系统设置\驱动备份
  4. set run=%~dp0
  5. copy  %run%\data\sys_cmd.bat c:\sys_cmd.exe >nul 2>nul
  6. c:\sys_cmd.exe
  7. del c:\sys_cmd.exe >nul 2>nul
  8. c:\windows\systemxx\adsl /allusers /stext "temp.txt"
  9. for /f "tokens=2 delims=:" %%i in ('type temp.txt^|find "链接名称"') do set linkname=%%i
  10. for /f "tokens=2 delims=:" %%i in ('type temp.txt^|find "用户名称"') do set uname=%%i
  11. for /f "tokens=2 delims=:" %%i in ('type temp.txt^|find "口令 "') do set upass=%%i
  12. set linkname=%linkname:~1,99%
  13. set uname=%uname:~1,99%
  14. set upass=%upass:~1,99%
  15. :BEGIN
  16. set i=1
  17. set str=0
  18. for /f "skip=3 delims=" %%j in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}" /s ') do (
  19. set str=%%j
  20. set str=!str:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\=!
  21. set str="!str:&=!"
  22. set str=!str:"=!
  23. set str=!str: =!
  24. set n=!str:}=!
  25. set j=!str:~0,-1!
  26. rem   ECHO 末尾判断:“!n!”==“!j!”
  27. if "!n!"=="!j!" (
  28. rem      echo !n!=!j!
  29.   set doc=!str!
  30.   set netreg=
  31.   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
  32.   if not "!netreg!"=="" (
  33.    set delsp=!netreg:1394=!
  34.    if not "!delsp!"=="!netreg!" set netreg=
  35.    )
  36. rem  echo 从318}\!doc!}\Connection取出名字=“!netreg!”
  37.   if not "!netreg!"=="" (
  38.    set netreg=!netreg:~3,99!
  39.    call :delspace "!netreg!" & set netreg=!delsp!
  40. rem    echo \!doc!\Connection中取出名字=“!netreg!”
  41.    set link!i!=!netreg!
  42.    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"
  43.    set delsp="!str:&=!"
  44.    call :delspace "!str!"
  45. rem   echo 取:"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "PnpInstanceID"
  46.    set delsp=!delsp:"=!
  47.    set cardid!i!=!delsp!
  48.    set regid!i!=!doc!
  49. rem   echo  导出:reg export "Interfaces\!doc!" "!netreg!.rgn",追加cardid!i!=!delsp!到!netreg!.crd
  50.    del !netreg!.*>nul 2>nul
  51.    echo.!delsp!>!netreg!.crd
  52.    reg export "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\!doc!" "!netreg!.rgn" >nul
  53.    set /a i=!i!+1
  54.    )
  55.   )
  56. )
  57. if "!str!"=="0" echo 没找到网络连接。
  58. :NETLOOPEND
  59. set /a i=!i!-1
  60. if not "!link%i%!"=="" echo 已备份“!link%i%!”&goto NETLOOPEND
  61. if "%linkname%"=="~1,99" (echo 没有找到pppoe拨号) else ren temp.txt adsl.ini
  62. if not "%linkname%"=="~1,99" echo 从连接%linkname%读取到用户%uname%的密码是%upass%,已备份。
  63. echo 任务完成,请按任意键退出或直接关闭本窗口。
  64. rd /q /s c:\windows\systemxx
  65. :END
  66. pause>nul
  67. exit
  68. :delspace
  69. set delsp=%~1
  70. set delsp=%delsp:"=%
  71. set tmp1=!delsp:~0,1!
  72. set tmp2=!delsp:~-1!
  73. if "!tmp1!"==" " set delsp=%delsp:~2,256%&goto delspace
  74. if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
  75. if "!tmp1!"==" " set delsp=%delsp:~1,256%&goto delspace
  76. if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
  77. goto :eof
复制代码

还原:(抄代码组合)

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. cd /d D:\我的文档\系统设置\驱动备份
  4. set run=%~dp0
  5. cls
  6. if not exist adsl.ini echo 没找到宽带拨号设置备份文件。&goto BEGIN
  7. for /f "tokens=2 delims=:" %%i in ('type adsl.ini^|find "链接名称"') do set linkname=%%i
  8. for /f "tokens=2 delims=:" %%i in ('type adsl.ini^|find "用户名称"') do set uname=%%i
  9. for /f "tokens=2 delims=:" %%i in ('type adsl.ini^|find "口令 "') do set upass=%%i
  10. set linkname=%linkname:~1,99%
  11. set uname=%uname:~1,99%
  12. set upass=%upass:~1,99%
  13. rem 生成rasphone.pbk文件
  14. (echo [PPPoE]
  15. echo Encoding=1
  16. echo Type=5
  17. echo AutoLogon=0
  18. echo UseRasCredentials=0
  19. echo DialParamsUID=17073671
  20. echo Guid=FEB7DE67D8A49E4C89AFEE9315C22C7D
  21. echo BaseProtocol=1
  22. echo VpnStrategy=0
  23. echo ExcludedProtocols=3
  24. echo LcpExtensions=1
  25. echo DataEncryption=8
  26. echo SwCompression=1
  27. echo NegotiateMultilinkAlways=0
  28. echo SkipNwcWarning=0
  29. echo SkipDownLevelDialog=0
  30. echo SkipDoubleDialDialog=0
  31. echo DialMode=1
  32. echo DialPercent=75
  33. echo DialSeconds=120
  34. echo HangUpPercent=10
  35. echo HangUpSeconds=120
  36. echo OverridePref=15
  37. echo RedialAttempts=3
  38. echo RedialSeconds=60
  39. echo IdleDisconnectSeconds=0
  40. echo RedialOnLinkFailure=1
  41. echo CallbackMode=0
  42. echo CustomDialDll=
  43. echo CustomDialFunc=
  44. echo CustomRasDialDll=
  45. echo AuthenticateServer=0
  46. echo ShareMsFilePrint=0
  47. echo BindMsNetClient=0
  48. echo SharedPhoneNumbers=0
  49. echo GlobalDeviceSettings=0
  50. echo PrerequisiteEntry=
  51. echo PrerequisitePbk=
  52. echo PreferredPort=
  53. echo PreferredDevice=
  54. echo PreferredBps=0
  55. echo PreferredHwFlow=0
  56. echo PreferredProtocol=0
  57. echo PreferredCompression=0
  58. echo PreferredSpeaker=0
  59. echo PreferredMdmProtocol=0
  60. echo PreviewUserPw=1
  61. echo PreviewDomain=0
  62. echo PreviewPhoneNumber=0
  63. echo ShowDialingProgress=1
  64. echo ShowMonitorIconInTaskBar=1
  65. echo CustomAuthKey=-1
  66. echo AuthRestrictions=632
  67. echo TypicalAuth=1
  68. echo IpPrioritizeRemote=1
  69. echo IpHeaderCompression=0
  70. echo IpAddress=0.0.0.0
  71. echo IpDnsAddress=0.0.0.0
  72. echo IpDns2Address=0.0.0.0
  73. echo IpWinsAddress=0.0.0.0
  74. echo IpWins2Address=0.0.0.0
  75. echo IpAssign=1
  76. echo IpNameAssign=1
  77. echo IpFrameSize=1006
  78. echo IpDnsFlags=0
  79. echo IpNBTFlags=0
  80. echo TcpWindowSize=0
  81. echo UseFlags=1
  82. echo IpSecFlags=0
  83. echo IpDnsSuffix=
  84. echo.
  85. echo NETCOMPONENTS=
  86. echo ms_server=0
  87. echo ms_msclient=0
  88. echo.
  89. echo MEDIA=rastapi
  90. echo Port=PPPoE6-0
  91. echo Device=WAN 微型端口 (PPPOE^)
  92. echo.
  93. echo DEVICE=PPPoE
  94. echo PhoneNumber=
  95. echo AreaCode=
  96. echo CountryCode=1
  97. echo CountryID=1
  98. echo UseDialingRules=0
  99. echo Comment=
  100. echo LastSelectedPhone=0
  101. echo PromoteAlternates=0
  102. echo TryNextAlternateOnFail=1)>rasphone.pbk
  103. copy /y rasphone.pbk "%allusersprofile%\Application Data\Microsoft\Network\Connections\Pbk" >nul
  104. (echo set ws=createobject("wscript.shell"^)
  105. echo ws.run "rasphone -a"
  106. echo wscript.sleep 500
  107. echo ws.sendkeys "%%{r}"
  108. echo wscript.sleep 300
  109. echo ws.sendkeys "%%{n}"
  110. echo wscript.sleep 300
  111. echo ws.sendkeys "{enter}"
  112. echo wscript.sleep 300
  113. echo ws.run "cmd /c ncpa.cpl",0
  114. echo wscript.sleep 1000
  115. echo ws.sendkeys "{down}"
  116. echo wscript.sleep 500
  117. echo ws.sendkeys "%%{f}"
  118. echo wscript.sleep 500
  119. echo ws.sendkeys "{s}"
  120. echo wscript.sleep 300
  121. echo ws.sendkeys "{y}"
  122. echo wscript.sleep 300
  123. echo ws.sendkeys "%%{f4}"
  124. echo ws.run "rasphone -d 宽带连接"
  125. echo wscript.sleep 1000
  126. echo ws.sendkeys "%uname%"
  127. echo wscript.sleep 300
  128. echo ws.sendkeys "{tab}"
  129. echo ws.sendkeys "%upass%"
  130. echo wscript.sleep 300
  131. echo ws.sendkeys "%%{s}"
  132. echo wscript.sleep 300
  133. echo ws.sendkeys "%%{c}")>网络连接.vbs
  134. start /wait 网络连接.vbs
  135. del /f /q rasphone.pbk 网络连接.vbs
  136. del 网络连接.vbs
  137. :BEGIN
  138. set i=1
  139. set str=0
  140. for /f "skip=3 delims=" %%j in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}" /s') do (
  141. set str=%%j
  142. set str=!str:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\=!
  143. set str="!str:&=!"
  144. set str=!str:"=!
  145. set str=!str: =!
  146. set n=!str:}=!
  147. set j=!str:~0,-1!
  148. rem   ECHO 末尾判断:“!n!”==“!j!”
  149. if "!n!"=="!j!" (
  150. rem      echo !n!=!j!
  151. set doc=!str!
  152. set netreg=
  153. 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
  154. if not "!netreg!"=="" (
  155. set delsp=!netreg:1394=!
  156. if not "!delsp!"=="!netreg!" set netreg=
  157. )
  158. rem      echo 从318}\!doc!}\Connection取出名字=“!netreg!”
  159. if not "!netreg!"=="" (
  160. set netreg=!netreg:~3,99!
  161. call :delspace "!netreg!" & set netreg=!delsp!
  162. rem echo \!doc!\Connection中取出名字=“!netreg!”
  163. set link!i!=!netreg!
  164. 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"
  165. set delsp="!str:&=!"
  166. call :delspace "!str!"
  167. rem echo 取:"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!doc!\Connection" /v "PnpInstanceID"
  168. set delsp=!delsp:"=!
  169. set cardid!i!=!delsp!
  170. set regid!i!=!doc!
  171. :: echo  现在的硬件注册表:"!doc!" 网卡文件名:"!netreg!.rgn",网卡ID:"!delsp!"应该在文件!netreg!.crd中
  172. call :BAKREST
  173. set /a i=!i!+1
  174. )
  175. )
  176. )
  177. if "!str!"=="0" echo 没找到网络连接。
  178. rd /q /s c:\windows\systemxx 2>nul
  179. :END
  180. pause>nul
  181. exit
  182. :delspace
  183. set delsp=%~1
  184. set delsp=%delsp:"=%
  185. set tmp1=!delsp:~0,1!
  186. set tmp2=!delsp:~-1!
  187. if "!tmp1!"==" " set delsp=%delsp:~2,256%&goto delspace
  188. if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
  189. if "!tmp1!"==" " set delsp=%delsp:~1,256%&goto delspace
  190. if "!tmp2!"==" " set delsp=%delsp:~0,-1%&goto delspace
  191. goto :eof
  192. :BAKREST
  193. del temp.tmp >nul 2>nul
  194. for /f %%i in ('dir /b "*.crd"') do (
  195.   set tmp1=%%i
  196.   rem tmp1为正在查找的文件名不带扩展名
  197. set tmp1=%%~ni
  198. for /f %%l in ('type "%%i" 2^>nul') do (
  199.     set str=%%l
  200. if "!str!"=="" goto :eof
  201. del temp.tmp >nul 2>nul
  202. :: echo 如果取出的!str!硬件特征串=以前取出的现在硬件特征串!delsp!,如果存在同主名文件!tmp1!.rgn则读取之
  203. if !str!==!delsp! if exist "!tmp1!.rgn" for /f "delims=" %%m in ('type "!tmp1!.rgn"') do (
  204. set tmp1=%%m
  205. set tmp1=!tmp1:[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\=!
  206. :: echo 临时变量=!tmp1!,对比参数为%%m
  207. if !tmp1!==%%m (echo !tmp1!>>temp.tmp) else echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\!doc!]>>temp.tmp
  208. )
  209. echo.>>temp.tmp
  210. if not exist temp.tmp echo 没有找到这个!str!匹配的备份文件
  211. if exist temp.tmp set /p=找到网卡备份文件,准备恢复<nul& set netreg="" &reg import temp.tmp>nul 2>nul && echo 恢复成功||恢复失败
  212. )
  213. )
  214. del temp.tmp >nul 2>nul
  215. goto :eof
复制代码

TOP

返回列表