Board logo

标题: [特效代码] 批处理怎样实现计算机改名、加域、添加域用户到本地管理员? [打印本页]

作者: robbyzhang    时间: 2010-8-8 23:21     标题: 批处理怎样实现计算机改名、加域、添加域用户到本地管理员?

各位好!
      小弟公司最近新做了域,需要批量将用户的电脑加入域,想找一个脚本来实现相关功能。
作业顺序:1.修改本地管理员密码(代码已有)
                  2.修改用户计算机名称(公司统一格式)
                  3.加域
                  4.添加域账号为本地管理员;
现想通过一个脚本来实现后面3个功能,一直未找到合用的,小弟刚接触代码,暂无能力自己编写,
还请各位高手帮忙分享,谢谢啦!
作者: renmingwu    时间: 2010-8-9 09:43

修改完用户计算机名称后,如果不重启,那么加入域的就是没改前的计算机名吧!所以个人觉得一个脚本费劲!

刚才想了下,可以通过判断用一个脚本实现,即开始先得到本机名字,提示是否修改,然后重启,再判断是否加域,如未加,提示加域,最后再判断是否为管理员,然后提示添加。

[ 本帖最后由 renmingwu 于 2010-8-9 09:57 编辑 ]
作者: ntserver    时间: 2010-8-9 12:49

楼上的,等于没说。写出代码来才是王道
作者: renmingwu    时间: 2010-8-10 13:16

有想法就不错了,消灭0回复,再说有了想法才能慢慢做出来!
作者: a2035274    时间: 2010-8-11 07:54

这是我的老师给我的代码,我也不知道是谁写的。只能改IP,DNS,掩码,及机器名。
如果是局域网的话先用这个工具取得MAC然后就可以自己设置IP,机器名
http://www.qupan.com/down/wy94867_1224347.html
  1. @ECHO OFF
  2. @cls
  3. ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::
  4. ECHO :: GHOST完成后根据网卡MAC自动设置机名和IP的批处理 ::
  5. ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::
  6. ::::清空环境变量
  7. Set IPAddress=
  8. Set strMac=
  9. Set MacAddress=
  10. Set CName=
  11. Set scfile=
  12. Set sc=
  13. Set MacWMIC=
  14. Set ConnName=
  15. cd/d %temp%
  16. REM ::::请手动修改列表
  17. ECHO [ComputerName] [MacAddress] [IPAddress] >iplist.txt
  18. echo a02 00-04-61-4D-AA-1A 172.30.10.2  >>iplist.txt
  19. echo a03 00-04-61-4D-C8-78 172.30.10.3  >>iplist.txt
  20. echo a04 00-04-61-4D-C9-F7 172.30.10.4  >>iplist.txt
  21. echo a05 00-04-61-4D-C6-EE 172.30.10.5  >>iplist.txt
  22. echo a06 00-04-61-4E-24-68 172.30.10.6  >>iplist.txt
  23. echo a07 00-04-61-4D-B1-B7 172.30.10.7  >>iplist.txt
  24. echo a08 00-04-61-4D-B5-F6 172.30.10.8  >>iplist.txt
  25. echo a09 00-04-61-4E-24-6E 172.30.10.9  >>iplist.txt
  26. echo a10 00-04-61-4E-24-BF 172.30.10.10  >>iplist.txt
  27. echo a11 00-04-61-4D-C6-EF 172.30.10.11  >>iplist.txt
  28. echo a12 00-04-61-4D-C5-08 172.30.10.12  >>iplist.txt
  29. echo a13 00-04-61-48-16-C9 172.30.10.13  >>iplist.txt
  30. echo a14 00-04-61-4E-29-B9 172.30.10.14  >>iplist.txt
  31. echo a15 00-04-61-4E-2A-20 172.30.10.15  >>iplist.txt
  32. echo a16 00-04-61-4E-2A-4C 172.30.10.16  >>iplist.txt
  33. echo a17 00-04-61-4D-AF-D1 172.30.10.17  >>iplist.txt
  34. echo a18 00-04-61-4D-C9-F8 172.30.10.18  >>iplist.txt
  35. echo a19 00-04-61-4E-21-05 172.30.10.19  >>iplist.txt
  36. echo a20 00-04-61-48-16-C8 172.30.10.20  >>iplist.txt
  37. echo a21 00-04-61-4E-25-81 172.30.10.21  >>iplist.txt
  38. echo a22 00-04-61-4D-C6-DD 172.30.10.22  >>iplist.txt
  39. echo a23 00-04-61-4D-C5-7C 172.30.10.23  >>iplist.txt
  40. echo a24 00-04-61-4D-C9-AE 172.30.10.24  >>iplist.txt
  41. echo a25 00-04-61-4D-C5-7A 172.30.10.25  >>iplist.txt
  42. echo a26 00-04-61-4D-C5-06 172.30.10.26  >>iplist.txt
  43. echo a27 00-04-61-48-16-C7 172.30.10.27  >>iplist.txt
  44. echo a28 00-04-61-4D-C5-73 172.30.10.28  >>iplist.txt
  45. echo a29 00-04-61-4D-AF-45 172.30.10.29  >>iplist.txt
  46. echo a30 00-04-61-4E-34-B8 172.30.10.30  >>iplist.txt
  47. echo a31 00-04-61-4E-34-B9 172.30.10.31  >>iplist.txt
  48. echo a32 00-04-61-4D-B6-27 172.30.10.32  >>iplist.txt
  49. echo a33 00-04-61-4D-C1-5C 172.30.10.33  >>iplist.txt
  50. echo a34 00-04-61-4D-C5-3E 172.30.10.34  >>iplist.txt
  51. echo a35 00-04-61-4D-C1-36 172.30.10.35  >>iplist.txt
  52. echo a36 00-04-61-49-2F-8E 172.30.10.36  >>iplist.txt
  53. echo a37 00-04-61-4D-B5-CD 172.30.10.37  >>iplist.txt
  54. echo a38 00-04-61-4D-B5-F3 172.30.10.38  >>iplist.txt
  55. echo a39 00-04-61-4D-B6-32 172.30.10.39  >>iplist.txt
  56. echo a40 00-04-61-4D-AA-18 172.30.10.40  >>iplist.txt
  57. echo a41 00-04-61-4D-BB-4D 172.30.10.41  >>iplist.txt
  58. echo a42 00-04-61-4E-24-BE 172.30.10.42  >>iplist.txt
  59. echo a43 00-04-61-49-1E-41 172.30.10.43  >>iplist.txt
  60. echo a44 00-04-61-4D-C1-2D 172.30.10.44  >>iplist.txt
  61. echo a45 00-04-61-4D-C8-7B 172.30.10.45  >>iplist.txt
  62. echo a46 00-04-61-4E-25-75 172.30.10.46  >>iplist.txt
  63. echo a47 00-04-61-4D-C9-D4 172.30.10.47  >>iplist.txt
  64. echo a48 00-04-61-4D-C8-92 172.30.10.48  >>iplist.txt
  65. echo a49 00-04-61-4E-25-19 172.30.10.49  >>iplist.txt
  66. echo a50 00-04-61-4D-C9-F0 172.30.10.50  >>iplist.txt
  67. echo a51 00-04-61-4E-25-58 172.30.10.51  >>iplist.txt
  68. echo a52 00-04-61-49-10-3E 172.30.10.52  >>iplist.txt
  69. echo a53 00-04-61-4D-C8-B4 172.30.10.53  >>iplist.txt
  70. echo a54 00-04-61-4D-C8-83 172.30.10.54  >>iplist.txt
  71. echo a55 00-04-61-4E-27-B0 172.30.10.55  >>iplist.txt
  72. echo a56 00-04-61-4D-C1-3C 172.30.10.56  >>iplist.txt
  73. echo a57 00-04-61-4D-BB-4E 172.30.10.57  >>iplist.txt
  74. echo a58 00-04-61-4D-C8-33 172.30.10.58  >>iplist.txt
  75. echo b01 00-04-61-4E-28-03 172.30.10.101 >>iplist.txt  
  76. echo b02 00-04-61-4E-24-EE 172.30.10.102 >>iplist.txt  
  77. echo b03 00-04-61-4D-C8-C8 172.30.10.103 >>iplist.txt  
  78. echo b04 00-04-61-4D-CA-1A 172.30.10.104 >>iplist.txt  
  79. echo b05 00-04-61-4E-25-2C 172.30.10.105 >>iplist.txt
  80. echo b06 00-00-00-00-00-00 172.30.10.106 >>iplist.txt  
  81. echo b07 00-04-61-4E-28-04 172.30.10.107 >>iplist.txt  
  82. echo b08 00-04-61-4D-BB-5B 172.30.10.108 >>iplist.txt  
  83. echo b09 00-04-61-4D-B5-4A 172.30.10.109 >>iplist.txt  
  84. echo b10 00-04-61-4D-C6-E3 172.30.10.110 >>iplist.txt  
  85. echo b11 00-04-61-49-1F-F8 172.30.10.111 >>iplist.txt
  86. echo b12 00-00-00-00-00-00 172.30.10.112 >>iplist.txt  
  87. echo b13 00-04-61-4D-AF-6F 172.30.10.113 >>iplist.txt  
  88. echo b14 00-04-61-4D-C8-49 172.30.10.114 >>iplist.txt  
  89. echo b15 00-04-61-4E-2B-1A 172.30.10.115 >>iplist.txt  
  90. echo b16 00-04-61-4D-B1-9A 172.30.10.116 >>iplist.txt  
  91. echo b17 00-04-61-4E-32-A2 172.30.10.117 >>iplist.txt  
  92. echo b18 00-04-61-4D-C1-56 172.30.10.118 >>iplist.txt  
  93. echo b19 00-04-61-4D-BB-53 172.30.10.119 >>iplist.txt  
  94. echo b20 00-04-61-4E-25-84 172.30.10.120 >>iplist.txt  
  95. echo b21 00-04-61-49-36-D8 172.30.10.121 >>iplist.txt  
  96. echo b22 00-04-61-4D-C6-CE 172.30.10.122 >>iplist.txt  
  97. echo b23 00-04-61-4D-C6-CD 172.30.10.123 >>iplist.txt  
  98. echo b24 00-04-61-4E-27-CB 172.30.10.124 >>iplist.txt  
  99. echo b25 00-04-61-4E-25-57 172.30.10.125 >>iplist.txt  
  100. echo b26 00-04-61-4D-C9-D1 172.30.10.126 >>iplist.txt  
  101. echo b27 00-04-61-4E-2B-11 172.30.10.127 >>iplist.txt  
  102. echo b28 00-04-61-4D-CA-15 172.30.10.128 >>iplist.txt  
  103. echo b29 00-04-61-4E-27-D3 172.30.10.129 >>iplist.txt  
  104. echo b30 00-04-61-4E-24-F1 172.30.10.130 >>iplist.txt  
  105. echo b31 00-04-61-4D-C6-E4 172.30.10.131 >>iplist.txt  
  106. echo b32 00-04-61-4D-C1-3B 172.30.10.132 >>iplist.txt  
  107. echo b33 00-04-61-4D-B5-D5 172.30.10.133 >>iplist.txt  
  108. echo b34 00-04-61-4E-2B-18 172.30.10.134 >>iplist.txt  
  109. echo b35 00-04-61-4D-BB-52 172.30.10.135 >>iplist.txt  
  110. echo b36 00-04-61-4E-29-B3 172.30.10.136 >>iplist.txt  
  111. echo b37 00-04-61-4D-C5-79 172.30.10.137 >>iplist.txt  
  112. echo b38 00-04-61-4E-24-EF 172.30.10.138 >>iplist.txt  
  113. echo b39 00-04-61-4E-32-B8 172.30.10.139 >>iplist.txt
  114. echo b40 00-00-00-00-00-00 172.30.10.140 >>iplist.txt
  115. echo b41 00-04-61-4D-AF-D0 172.30.10.141 >>iplist.txt  
  116. echo b42 00-04-61-4E-25-45 172.30.10.142 >>iplist.txt  
  117. echo b43 00-04-61-4D-BB-54 172.30.10.143 >>iplist.txt  
  118. echo b44 00-04-61-4E-2A-1B 172.30.10.144 >>iplist.txt  
  119. echo b45 00-04-61-4D-C5-3D 172.30.10.145 >>iplist.txt  
  120. echo b46 00-04-61-4D-BB-4B 172.30.10.146 >>iplist.txt  
  121. echo b47 00-04-61-4D-C9-9C 172.30.10.147 >>iplist.txt  
  122. echo b48 00-04-61-4E-29-F2 172.30.10.148 >>iplist.txt  
  123. echo b49 00-04-61-4D-BB-5D 172.30.10.149 >>iplist.txt  
  124. echo b50 00-04-61-4E-24-6D 172.30.10.150 >>iplist.txt  
  125. echo b51 00-04-61-4E-2A-55 172.30.10.151 >>iplist.txt  
  126. echo b52 00-04-61-49-23-07 172.30.10.152 >>iplist.txt  
  127. echo b53 00-04-61-4E-28-06 172.30.10.153 >>iplist.txt
  128. echo b52 00-00-00-00-00-00 172.30.10.152 >>iplist.txt  
  129. echo b55 00-04-61-4E-27-CA 172.30.10.155 >>iplist.txt  
  130. echo b56 00-04-61-4E-25-59 172.30.10.156 >>iplist.txt
  131. echo b57 00-00-00-00-00-00 172.30.10.157 >>iplist.txt  
  132. echo b58 00-04-61-4D-C5-3F 172.30.10.158 >>iplist.txt  
  133. echo b59 00-04-61-4D-AF-C1 172.30.10.159 >>iplist.txt
  134. echo e01 00-E0-61-03-62-6D 172.30.10.201  >>iplist.txt
  135. echo e02 00-E0-61-03-57-10 172.30.10.202  >>iplist.txt
  136. echo e03 00-E0-61-03-5B-66 172.30.10.203  >>iplist.txt
  137. echo e04 00-E0-61-03-6F-9D 172.30.10.204  >>iplist.txt
  138. echo e05 00-E0-61-03-6A-F0 172.30.10.205  >>iplist.txt
  139. echo e06 00-E0-61-03-58-1D 172.30.10.206  >>iplist.txt
  140. echo e07 00-E0-61-03-58-D2 172.30.10.207  >>iplist.txt
  141. echo e08 00-E0-61-03-57-74 172.30.10.208  >>iplist.txt
  142. echo e09 00-E0-61-03-5F-21 172.30.10.209  >>iplist.txt
  143. echo e10 00-E0-61-03-6F-9B 172.30.10.210  >>iplist.txt
  144. echo e11 00-E0-61-02-B3-61 172.30.10.211  >>iplist.txt
  145. echo e12 00-E0-61-03-5B-67 172.30.10.212  >>iplist.txt
  146. echo e13 00-E0-61-02-B4-80 172.30.10.213  >>iplist.txt
  147. echo e14 00-E0-61-03-64-FA 172.30.10.214  >>iplist.txt
  148. echo e15 00-E0-61-03-55-00 172.30.10.215  >>iplist.txt
  149. echo e16 00-E0-61-03-75-7C 172.30.10.216  >>iplist.txt
  150. echo e17 00-E0-61-03-68-37 172.30.10.217  >>iplist.txt
  151. echo e18 00-E0-61-03-64-CC 172.30.10.218  >>iplist.txt
  152. echo e19 00-E0-61-03-5F-C6 172.30.10.219  >>iplist.txt
  153. echo e20 00-E0-61-03-5E-95 172.30.10.220  >>iplist.txt
  154. echo e21 00-E0-61-03-6C-D6 172.30.10.221  >>iplist.txt
  155. echo e22 00-00-00-00-00-00 172.30.10.222  >>iplist.txt
  156. echo e23 00-E0-61-03-6E-DA 172.30.10.223  >>iplist.txt
  157. echo e24 00-E0-61-03-53-0B 172.30.10.224  >>iplist.txt
  158. echo e25 00-E0-61-03-76-90 172.30.10.225  >>iplist.txt
  159. echo e26 00-E0-61-02-B2-90 172.30.10.226  >>iplist.txt
  160. echo e27 00-E0-61-03-72-1A 172.30.10.227  >>iplist.txt
  161. echo e28 00-E0-61-03-64-CA 172.30.10.228  >>iplist.txt
  162. echo e29 00-E0-61-03-58-DA 172.30.10.229  >>iplist.txt
  163. echo e30 00-E0-61-02-B3-67 172.30.10.230  >>iplist.txt
  164. echo e31 00-00-00-00-00-00 172.30.10.231  >>iplist.txt
  165. echo e32 00-E0-61-03-5F-26 172.30.10.232  >>iplist.txt
  166. echo e33 00-E0-61-03-58-3A 172.30.10.233  >>iplist.txt
  167. echo e34 00-E0-61-03-74-89 172.30.10.234  >>iplist.txt
  168. echo e35 00-E0-61-03-5B-57 172.30.10.235  >>iplist.txt
  169. echo e36 00-E0-61-03-58-24 172.30.10.236  >>iplist.txt
  170. echo e37 00-E0-61-03-68-33 172.30.10.237  >>iplist.txt
  171. echo e38 00-E0-61-03-68-35 172.30.10.238  >>iplist.txt
  172. echo e39 00-E0-61-03-5F-04 172.30.10.239  >>iplist.txt
  173. echo e40 00-E0-61-03-5E-91 172.30.10.240  >>iplist.txt
  174. echo e41 00-E0-61-03-6D-B3 172.30.10.241  >>iplist.txt
  175. echo e42 00-E0-61-03-58-22 172.30.10.242  >>iplist.txt
  176. echo e43 00-E0-61-0B-55-52 172.30.10.243  >>iplist.txt
  177. echo e44 00-E0-61-03-67-90 172.30.10.244  >>iplist.txt
  178. echo e45 00-E0-61-03-62-3D 172.30.10.245  >>iplist.txt
  179. echo e46 00-E0-61-03-76-91 172.30.10.246  >>iplist.txt
  180. echo e47 00-E0-61-03-71-3F 172.30.10.247  >>iplist.txt
  181. echo e48 00-E0-61-03-58-1C 172.30.10.248  >>iplist.txt
  182. echo e49 00-00-00-00-00-00 172.30.10.249  >>iplist.txt
  183. echo e50 00-E0-61-03-53-0A 172.30.10.250  >>iplist.txt
  184. echo e51 00-00-00-00-00-00 172.30.10.251  >>iplist.txt
  185. echo e52 00-E0-61-03-24-5F 172.30.10.252  >>iplist.txt
  186. echo e53 00-E0-61-03-58-CF 172.30.10.253  >>iplist.txt
  187. echo e54 00-E0-61-02-B3-65 172.30.10.254  >>iplist.txt
  188. echo e55 00-E0-61-03-69-D5 172.30.10.199 >>iplist.txt
  189. echo ead 00-E0-61-03-6E-D6 172.30.10.200  >>iplist.txt   
  190. REM ::::请手动修改子网掩码
  191. Set mask=255.255.255.0
  192. REM ::::请手动修改默认网关
  193. Set gway=172.30.10.1
  194. ECHO :::: 开始查找网卡 ::::
  195. ::::获取机器的TCP/IP 配置
  196. if exist ipconfig.txt del ipconfig.txt
  197. ipconfig /all >ipconfig.txt
  198. ::::分离出机器的物理地址,并保存到 ( phyaddr.txt) 文件中
  199. if exist phyaddr.txt del phyaddr.txt
  200. if exist phyaddr1.txt del phyaddr1.txt
  201. find "Physical Address" ipconfig.txt >phyaddr.txt
  202. Set sc=1
  203. Set scfile=phyaddr.txt
  204. goto scan
  205. ::::多网卡时,扫描每个网卡MAC地址
  206. :rescan1
  207. Set sc=%sc%1
  208. Set scfile=phyaddr1.txt
  209. find /v "%strMac%" phyaddr.txt >%scfile%
  210. Goto scan
  211. :rescan2
  212. Set sc=%sc%1
  213. Set scfile=phyaddr.txt
  214. find /v "%strMac%" phyaddr1.txt >%scfile%
  215. Goto scan
  216. :scan
  217. ::::从(c:\phyaddr.txt)文件中取得物理地址字符串,并赋给变量"MacAddress"
  218. for /f "skip=2 tokens=12" %%M in (%scfile%) do set strMac=%%M
  219. ::::以变量"strMac"为关键字搜索(iplist.txt)中相同的字符串行,并保存到(PCCfg.txt)
  220. find "%strMac%" iplist.txt >PCCfg.txt
  221. ::::找出机器名(从"PCCfg.txt"中分离出 机器名字段,并赋给变量"CName")
  222. for /f "skip=2 tokens=1" %%N in (PCCfg.txt) do set CName=%%N
  223. if not "%CName%"=="" Goto found
  224. ::::支持最多扫描5个网卡
  225. If "%sc%"=="11111" Goto failed
  226. If "%sc%"=="1" Goto rescan1
  227. if %scfile%==phyaddr.txt Goto rescan1
  228. if %scfile%==phyaddr1.txt Goto rescan2
  229. :found
  230. ECHO 本机 MAC: %strMac%
  231. ECHO 目标名称: %CName%
  232. ::::显示IP地址. (从"PCCfg.txt"中分离出 IP地址字段,并赋给变量"IPAddress")
  233. for /f "skip=2 tokens=3" %%I in (PCCfg.txt) do set IPAddress=%%I
  234. ECHO 目标地址: %IPAddress%
  235. ::::显示网卡MAC地址.(从"PCCfg.txt"中分离出 MAC地址字段,并赋给变量"MacAddress")
  236. for /f "skip=2 tokens=2" %%M in (PCCfg.txt) do set MacAddress=%%M
  237. ECHO 目标 MAC: %MacAddress%
  238. ::::创建注册表文件
  239. ::::用变量"%CName%"去替换实际的机器名
  240. ECHO Windows Registry Editor Version 5.00 >PCName.reg
  241. ECHO.>>PCName.reg
  242. ECHO [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] >>PCName.reg
  243. ECHO "ComputerName"="%CName%" >>PCName.reg
  244. ECHO.>>PCName.reg
  245. ECHO [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>PCName.reg
  246. ECHO "NV Hostname"="%CName%" >>PCName.reg
  247. ECHO "Hostname"="%CName%" >>PCName.reg
  248. ECHO :::: 正在更改设置 ::::
  249. REM 导入注册表文件。用的时候把" :: "去掉
  250. regedit /s PCName.reg
  251. REM 修改IP地址。用的时候把" :: "去掉
  252. netsh interface ip set address name="本地连接" source=static addr=%IPAddress% mask=%mask% gateway=%gway% gwmetric=1
  253. netsh interface ip set dns "本地连接" static 202.96.64.68
复制代码


用户名和管理员的密码我们一般都是手动改的。

[ 本帖最后由 a2035274 于 2010-8-11 19:21 编辑 ]
作者: rivch    时间: 2011-7-2 11:10

现在你要实现的,能实现了吧?




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