Windows Batch将记录添加到hosts文件

Tob*_*bia 5 hosts batch-file

我需要一个批处理文件来向Windows中的hosts文件添加一条记录,但是我不需要一个文件追加写入,因为我想检查这条记录是否已经存在.有可能吗?

npo*_*aka 9

type "%SystemRoot%\system32\drivers\etc\hosts" | find "my_record" ||echo my_record>>"%SystemRoot%\system32\drivers\etc\hosts"
Run Code Online (Sandbox Code Playgroud)

试试这个.您需要管理员权限才能在hosts文件中添加内容