本帖最后由 wu26853767 于 2012-3-16 11:38 编辑
windowXP系统hosts文件被注释添加#之后可以使用- @echo off
- set "hostfile=C:\WINDOWS\system32\drivers\etc\hosts"
- set "tempfile=%temp%\host.tmp"
- for /f "delims=:" %%a in ('findstr /n "^127.0.0.1" "%hostfile%"') do (
- set "num=%%a"
- )
- type nul >"%tempfile%"
- for /f "tokens=1* delims=:" %%a in ('findstr /n .* "%hostfile%"') do (
- set "str=%%b"
- setlocal enabledelayedexpansion
- if %%a leq %num% (
- >>"%tempfile%" echo,%%b
- ) else if "!str:~0,1!" equ "#" (
- >>"%tempfile%" echo,!str:~1!
- ) else (
- >>"%tempfile%" echo,%%b
- )
- endlocal
- )
- move /y "%tempfile%" "%hostfile%"
复制代码 删除127.0.0.1以下的井号
但是window7里的hosts内容和XP不一样
window7的hosts的内容是:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
#192.168.1.100 www.baidu.com
请问windows7系统下的hosts文件解析被注释后怎么删除井号呢
最好是可以兼容XP的批处理
先谢过各位老大,windows7权限问题可以不考虑 |