本帖最后由 pcl_test 于 2015-2-8 23:25 编辑
回复 3# Heisenberg
注册表位置无所谓的话,你自己把代码添加进去吧,reg- @echo off
- setlocal enabledelayedexpansion
- ::指定hosts所在目录
- cd /d "C:\windows\system32\drivers\etc\"
- for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "IPv4"') do set "localip=%%i"
-
- for /f "eol=# delims=" %%j in ('type "hosts"') do echo %%j>>$$1
- set n=1
- for /f "tokens=1*" %%a in ($$1) do (
- if !n! lss 3 (
- echo %%a %%b>>$$2
- ) else (
- echo %%a %%b>>$$3
- )
- set /a n+=1
- )
-
- set m=1
- for /f "tokens=1*" %%s in ($$2) do (
- if !m! equ 1 (
- echo 读取%%s,执行将注册表下某项值设为%%t
- ) else (
- echo 读取%%s,执行将注册表下某项值设为%%t
- )
- set /a m+=1
- )
-
- for /f "tokens=1*" %%e in ($$3) do (
- if %localip% equ %%e (
- echo 执行修改主机名为%%f
- set "number=%%f"
- echo 执行修改后三位!number:~-3!
- pause
- del $$* /s /q >nul
- exit
- )
- )
- echo 没有找到匹配项
-
- del $$* /s /q >nul
- pause
复制代码
|