中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-15 12:23
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » Search for the HOSTS file and insert lines
Printable Version  3,985 / 16
Floor1 zdh Posted 2006-11-18 05:43
初级用户 Posts 20 Credits 52
I want to find the HOSTS file (which may be a hidden file with no extension!) in the c: drive, and insert a line of text (such as "I o U") at the last line.
Grateful to all the experts who helped me! ;)
Floor2 vkill Posted 2006-11-18 05:59
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
for /f "tokens=*" %%? in ('dir /a-d/s/b c:\hosts') do (>>%%? echo I o U)
Floor3 zdh Posted 2006-11-18 06:07
初级用户 Posts 20 Credits 52
Error:
There should not be tekons=*" at this time
My HOSTS may not be in the root C drive directory, it may be somewhere in the C drive.
Floor4 NaturalJ0 Posted 2006-11-18 06:12
银牌会员 Posts 533 Credits 1,181
Change to tokens.
If the prompt file is read-only, it's best to handle it with attrib first.
Floor5 ccwan Posted 2006-11-18 06:19
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Floor6 vkill Posted 2006-11-18 06:24
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Originally posted by zdh at 2006-11-18 06:07:
Error:
At this time, there should not be tekons=*"
My HOSTS may not be in the root C drive directory, it may be in some place on the C drive.

Sweat, it was written wrong
Floor7 不得不爱 Posted 2006-11-18 06:25
超级版主 Posts 2,044 Credits 5,310 From 四川南充
for /f "tokens=*" %%a in ('dir /a-d/s/b c:\hosts') do echo I o U>>%%a
Floor8 kht000 Posted 2006-11-18 09:56
初级用户 Posts 14 Credits 45
ATTRIB -A -R -H C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS
ECHO I o U >> C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS
win2003
Floor9 tao0610 Posted 2006-11-18 13:34
高级用户 Posts 218 Credits 579
Want to add domain name resolution in the hosts under drivers\etc!
Floor10 zdh Posted 2006-11-18 21:29
初级用户 Posts 20 Credits 52
Originally posted by tao0610 at 2006-11-18 01:34 AM:
Want to add domain name resolution in the hosts under drivers\etc!

Yeah! Because it's too cumbersome to access with IP addresses in the local area network. It would be best if it could be resolved!
Floor11 tao0610 Posted 2006-11-19 15:25
高级用户 Posts 218 Credits 579
attrib -s -h %systemroot%\system32\drivers\etc\hosts
echo 202.108.22.5 www.baidu.com >> %systemroot%\system32\drivers\etc\hosts
Floor12 hxuan999 Posted 2006-11-23 07:28
中级用户 Posts 161 Credits 337
Learning
Floor13 Kinglion Posted 2007-04-26 00:55
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
@echo off
rem -----------------------------------------------
rem Powered by Kinglion Software Workroom
rem www.kinglion.org DNS Resolution Setup Program
rem Don't modify this file
rem -----------------------------------------------
if exist %ComSpec% goto nt

:9x
if not exist %windir%\hosts goto win9xgo
if not exist %windir%\hosts.bak goto win9xgo
del %windir%\hosts.bak
ren %windir%\hosts %windir%\hosts.bak

:win9xgo
echo 221.212.188.60 www.kinglion.org >> %windir%\hosts
goto end

:nt
if not exist %windir%\system32\drivers\etc\hosts goto ntgo
if not exist %windir%\system32\drivers\etc\hosts.bak goto ntgo
del %windir%\system32\drivers\etc\hosts.bak
ren %windir%\system32\drivers\etc\hosts %windir%\system32\drivers\etc\hosts.bak

:ntgo
echo 221.212.188.60 www.kinglion.org >> %windir%\system32\drivers\etc\hosts

:end
Floor14 lxmxn Posted 2007-04-26 01:25
版主 Posts 4,938 Credits 11,386
Brother Kinglion, you consider issues very comprehensively.
Floor15 zbjit Posted 2008-09-24 10:03
新手上路 Posts 4 Credits 6
The script on the 13th floor is great, learning
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023