找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 33065|回复: 3

[网络连接] [已解决]批处理根据MAC地址修改计算机名、计算机描述

[复制链接]
发表于 2011-1-20 16:11:37 | 显示全部楼层 |阅读模式
本帖最后由 lx427 于 2011-7-7 02:50 编辑

公司内部全部要重装系统,要求计算机名、计算机描述都要规范,我做了个批处理,经过不断的实践,终于弄出来了,不过有个小小的不足,当同时存在有宽带连接和本地连接时,这个批处理会没有用,因为获取到的MAC地址有两个,而这个批处理默认的会拿宽带的MAC地址去匹配,所以会修改失败,关于这个问题,我发了一个求助贴,
http://www.bathome.net/thread-13159-1-1.html   
请大家指导完善一下,让这个批处理适应能力更强,这个贴子是我几个月前就发了的,自已在这几个月中把这个批处理东拼西凑给弄出来了,哈哈!感谢二楼给我提供的代码,让我在他提供的代码基础上进行了修改才弄出来,也许对于大家来说是再简单不过的事,我对于我等网络管理员来说那就省了不少事,我要说声,谢谢!!
这个是我根据MAC地址修改计算机名  IP的批处理,IP地址是自动获取的,当然还有一个批处理设置静态IP的,根据表中MAC自动设置相应的IP,网关,并指定DNS我到时也会贴出来

  1. @echo off
  2. for /f "tokens=12 delims= " %%i in ('ipconfig /all^|find /i "Physical Address"') do set mac=%%i
  3. for /f "tokens=1,2*" %%i in ('ipconfig /all^|find "Ethernet adapter"')  do set Ethernet=%%k
  4. for /f "tokens=1,2" %%i in ('more /e +13 %0 ^|find /i "%mac:~,-1%"') do set "name=%%i"
  5. for /f "tokens=4" %%j in ('more /e +13 %0 ^|find /i "%mac:~,-1%"') do set "p=%%j"
  6. reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
  7. reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
  8. reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
  9. reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
  10. reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
  11. netsh interface ip set address "%Ethernet:~,-2%"  source=dhcp
  12. netsh interface ip set dns "%Ethernet:~,-2%" source=dhcp
  13. exit
  14. PC001        192.168.1.100        00-E0-4C-41-11-A6        祥子
  15. PC002        192.168.1.101        00-e0-62-0b-1f-6c        郝文婕
  16. PC003        192.168.1.102        00-e0-62-0b-22-6d        漆浪
  17. PC004        192.168.1.103        00-e0-66-02-b0-1e        彭雅娜
  18. PC005        192.168.1.104        00-e0-66-02-f1-c2        李颖诗
  19. PC006        192.168.1.105        00-e0-66-19-de-e9        陈永行
  20. PC007        192.168.1.106        00-e0-66-02-f4-15        宁智雄
  21. PC008        192.168.1.107        00-e0-66-02-b0-1e        彭雅娜
  22. PC009        192.168.1.108        00-e0-4c-41-11-b3        冯晶晶
  23. PC010        192.168.1.109        00-e0-66-02-df-8c        周国香
  24. PC011        192.168.1.110        00-e0-66-02-dd-d8        邓国花
  25. PC012        192.168.1.111        00-e0-66-0d-71-d9        邱瑾
  26. PC013        192.168.1.112        00-e0-66-19-de-ea        胡孝龙
复制代码

评分

参与人数 1PB +2 收起 理由
zm900612 + 2 感谢给帖子标题标注[已解决]字样

查看全部评分

发表于 2011-1-20 17:43:04 | 显示全部楼层
仅对楼主提供的代码修改:
  1. @echo off
  2. set "r=HKLM\System\CurrentControlSet"
  3. set Mask=255.255.255.0
  4. set Gateway=192.168.1.1
  5. set Dns=202.103.96.112
  6. for /f "tokens=1,2* delims=:. " %%a in ('ipconfig /all') do (
  7.         if /i "%%a %%b"=="Physical Address" set Mac=%%c
  8.         if /i "%%a %%b"=="Ethernet adapter" set E=%%c
  9. )
  10. for /f "tokens=1-4" %%a in ('more +19<"%~f0"') do if "%%c"=="%Mac%" set "N=%%a"&set "Ip=%%b"&set "P=%%d"
  11. (
  12. reg add "%r%Control\ComputerName\ActiveComputerName" /v ComputerName /d %N% /f
  13. reg add "%r%Services\Tcpip\Parameters" /v "NV Hostname" /d %N% /f
  14. reg add "%r%Services\Tcpip\Parameters" /v Hostname /d %N% /f
  15. reg add "%r%Services\Tcpip\Parameters" /v srvcomment /d %P% /f
  16. netsh interface ip set address "%E:~,-2%" static %Ip% %Mask% %Gateway% 1
  17. netsh interface ip set dns "%E:~,-2%" static %Dns%
  18. )>nul
  19. exit
  20. PC005        192.168.1.101        00-0f-ea-bc-61-da        A005
  21. PC006        192.168.1.102        00-23-54-d3-ee-95        A006
  22. PC007        192.168.1.103        00-e0-4c-46-c5-59        A007
  23. PC008        192.168.1.104        00-22-15-b6-d0-3c        A008
  24. PC009        192.168.1.106        00-25-11-c5-6d-d7        A009
  25. PC010        192.168.1.107        6c-f0-49-c1-f7-80        A010
  26. PC011        192.168.1.108        00-e0-4c-19-1a-ad        A011
  27. PC012        192.168.1.109        00-1f-c6-a2-86-de        A012
  28. PC013        192.168.1.110        00-23-54-d3-ee-98        A013
  29. PC014        192.168.1.111        00-b0-c4-a1-f5-a0        A014
复制代码

[ 本帖最后由 hanyeguxing 于 2011-1-20 17:44 编辑 ]

评分

参与人数 1技术 +1 收起 理由
zm900612 + 1 乐于助人

查看全部评分

 楼主| 发表于 2011-2-9 23:04:01 | 显示全部楼层
我测试了一下,没有用啊
发表于 2011-2-11 18:09:30 | 显示全部楼层

回复 3楼 的帖子

把@echo off删掉,看看执行过程是哪里出错了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 22:03 , Processed in 0.075130 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表