Board logo

标题: [系统相关] 修改mac地址的BAT脚本在xp下好用,到win7下就不行了,有知道原因的吗 [打印本页]

作者: swanseabrian    时间: 2021-9-1 20:08     标题: 修改mac地址的BAT脚本在xp下好用,到win7下就不行了,有知道原因的吗

修改mac地址,这脚本在xp下好用,到win7下就不行了,有知道原因的吗 下面是代码
  1. @echo off
  2. TITLE 网卡MAC地址随机更改工具
  3. echo.
  4. if not exist "devcon.exe" echo  缺少程序运行必要的组件,按任意键退出... &&pause>nul&&exit
  5. Setlocal ENABLEDELAYEDEXPANSION
  6. echo
  7. set x=x
  8. set y=y
  9. set z=z
  10. for /f "tokens=1,2 delims=:" %%i in ('ipconfig /all') do (
  11. set a=%%i
  12. set a=!a:~8,11!
  13. if "!a!"=="Description" (
  14.   set a=%%j
  15.   set b=!a:~1,14!
  16.   if not "!b!"=="wan (PPP/SLIP)" (
  17.   if not !y!==y if !z!==z set z=!a!
  18.   if not !x!==x if !y!==y set y=!a!
  19.   if !x!==x set x=!a!
  20.   set /a m=!m!+1
  21.   echo  !m!.!a!)
  22. )
  23. )
  24. echo --------------------------------------------------------------------------------
  25. :a
  26. set /a a=1
  27. if !a!==0 exit
  28. if !a! leq !m! if !a! geq 1 (
  29. if !a!==1 goto mac
  30. if !a!==2 set x=!y!&goto mac
  31. if !a!==3 set x=!z!&goto mac
  32. )
  33. echo.
  34. echo  请输入正确序号... &&pause>nul&&exit
  35. goto a
  36. ::******************************更改MAC入点
  37. ::******************************获得标识长度
  38. :mac
  39. set str=!x!
  40. :next1
  41. if not "!str!"=="" (
  42. set /a num+=1
  43. set "str=!str:~1!"
  44. goto next1
  45. )
  46. set /a num=%num%-1
  47. if exist "%programfiles%\Common Files\fehu" (rd /s /q "%programfiles%\Common Files\fehu" >nul >nul)
  48. ::*****************************生成随机MAC
  49. REM 下面是修改网卡长度的例如:0050 这是网卡前4位,想改几位把下面的数字2改为几
  50. set mactmp=00
  51. set/a js=2
  52. :start
  53. set/a mp=%random%%%15+1
  54. call :mtp
  55. set mactmp=%mactmp%%mp%
  56. set/a js=%js%+1
  57. if %js%==12 goto ennd
  58. goto start
  59. :mtp
  60. if %mp%==10 (set mp=a)
  61. if %mp%==11 (set mp=b)
  62. if %mp%==12 (set mp=c)
  63. if %mp%==13 (set mp=d)
  64. if %mp%==14 (set mp=e)
  65. if %mp%==15 (set mp=f)
  66. goto :eof
  67. :ennd
  68. set mtmp=%mactmp%
  69. set /a ct=0
  70. :loop
  71. if %ct% LEQ 9 set "n=0%ct%"
  72. if %ct% GEQ 10 set "n=%ct%"
  73. set /a tmp=%num%-1
  74. ::*****************************判断注册表项是否存在
  75.   reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\00!n!>nul
  76. if not errorlevel 1 goto f
  77. if errorlevel 1 (
  78.    cls
  79.    echo  未找到该网卡注册表项!!!按任意键退出程序!!
  80.    pause>nul
  81.    exit
  82.    )
  83. :f
  84. ::*****************************判断是否为网卡项
  85. reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\00!n!|find /i /n "!x:~1,%tmp%!">nul
  86. if not errorlevel 1 goto y
  87. if errorlevel 1 (
  88.    set /a ct=%ct%+1
  89.    goto loop
  90.    )
  91. :y
  92. ::*****************************修改
  93. reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\00!n! /胜利 networkaddress /t reg_sz /d !mtmp! /f>nul
  94. for /f "tokens=1,2 delims=:" %%i in ('devcon find PCI\*') do (
  95. set a=%%i
  96. set b=%%j
  97. set x=!x:~0,%num%!
  98. set b=!b:~0,%num%!
  99. if !x!==!b! goto ok
  100. )
  101. set a=!strd!
  102. ::*****************************处理标识串
  103. :ok
  104. for /f "delims=" %%i in ("!a!") do (
  105.     set str=%%i
  106.     set str=!str:^&=*!
  107. )
  108. ::*****************************生成网卡ID
  109. :next2
  110. if not "!str!"=="" (
  111. set /a onem+=1
  112. if "!str:~0,1!"=="*" goto last2
  113. set "str=!str:~1!"
  114. goto next2
  115. )
  116. set /a onem=0
  117. :last2
  118. set "str=!str:~1!"
  119. :next3
  120. if not "!str!"=="" (
  121. set /a twom+=1
  122. if "!str:~0,1!"=="*" goto last3
  123. set "str=!str:~1!"
  124. goto next3
  125. )
  126. set /a twom=0
  127. :last3
  128. set/a twom-=1
  129. set a=!a:~%onem%,%twom%!
  130. set a=*!a!*
  131. if "!a!"=="**" echo  请手工重新禁启用网卡... && goto end
  132. ::*****************************设置生效
  133. devcon disable !a! >nul >nul
  134. devcon enable !a! >nul >nul
  135. :end
  136. echo.
  137. echo  网卡名称:!x!
  138. echo  网卡MAC地址:!mtmp!
  139. echo.
  140. echo  已成功修改.
  141. if "!a!"=="**" echo  请手工重新禁启用网卡...
  142. ::*****************************IEd设置
  143. set/a c=101+%random%%%901
  144. set/a mac=%random%+10000
  145. set/a b=102+%random%%%902
  146. set/a d=1001+%random%%%9000
  147. set/a e=556+%random%%%+437
  148. set/a mac=%random%+10000
  149. set mac=80%c%-%b%-%e%%d%-%mac%
  150. reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Registration" /胜利 "ProductId" /t reg_sz /d %mac% /f
  151. ::*****************************IE版本设置
  152. set/a d=1001+%random%%%9000
  153. set/a mac=%random%+10000
  154. set mac=8.0.%d%.%mac%
  155. reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /胜利 "Version" /t reg_sz /d %mac% /f
  156. reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer" /胜利 "W2kVersion" /t reg_sz /d %mac% /f
  157. reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\active setup\installed components\{89820200-ecbd-11cf-8b85-00aa005b4383}" /胜利 "Version" /t reg_sz /d %mac% /f
  158. exit
复制代码

作者: newswan    时间: 2021-9-1 21:07

win7没有 devcon.exe ?
作者: swanseabrian    时间: 2021-9-1 21:56

回复 2# newswan


    什么意思
作者: newswan    时间: 2021-9-1 21:58

回复 3# swanseabrian


需要用到这个命令
作者: Batcher    时间: 2021-9-1 22:07

回复 1# swanseabrian


请参考Q-01观察一下哪行代码在报错以及详细的报错信息:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2