简体   繁体   English

如何使用命令提示符或批处理文件在主机文件(位于C:/ windows / system32 / drivers / etc文件夹中)中设置文本?

[英]How to set texts in a hosts file (found in C:/windows/system32/drivers/etc folder) using command prompt or a batch file?

I want my system to automatically type certain statements in the host file in a sheduled time. 我希望我的系统在计划的时间内自动在主机文件中键入某些语句。 To do that I need to execute a batch file which contains the required commands for setting the statements in host file. 为此,我需要执行一个批处理文件,其中包含在主机文件中设置语句所需的命令。 What are the syntax required to set statements in a file, specifically a hosts file or a text file. 在文件(尤其是主机文件或文本文件)中设置语句所需的语法是什么?

This will add a couple of entries to the HOSTS file, when run as administrator: 当以管理员身份运行时,这将在HOSTS文件中添加几个条目:

@echo off
attrib -r -a -s -h C:\WINDOWS\System32\Drivers\etc\hosts 1>nul 
C:\WINDOWS\System32\Drivers\etc\hosts >> echo 200.100.10.20    www.bogus.com
C:\WINDOWS\System32\Drivers\etc\hosts >> echo 200.100.10.22    www.fake.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用批处理文件将文件从本地文件夹复制到“C:\\ Windows \\ System32 \\” - Copying a file from local folder to “C:\Windows\System32\” using batch file 电子fs - EPERM:不允许操作,打开'C:\\ Windows \\ System32 \\ drivers \\ etc \\ hosts' - Electron fs - EPERM: operation not permitted, open 'C:\Windows\System32\drivers\etc\hosts' C++ 重命名文件@C:\\Windows\\System32\\Drivers - C++ Rename File @ C:\Windows\System32\Drivers 从任务计划程序启动批处理文件指向 C:\Windows\system32 - Starting batch file from Task scheduler point to C:\Windows\system32 使用fopen函数未在system32文件夹中创建文件 - file is not created in system32 folder using fopen function c:\\ windows \\ system32 \\ dns删除.dns文件 - c:\windows\system32\dns deleting .dns file 如何使用 Windows 的 PHP 脚本动态更新我的驱动程序/etc/hosts 文件? - How to dynamically update my drivers/etc/hosts file using PHP script for windows? Windows路径不包含C:\\ WINDOWS \\ system32,可以使用批处理脚本添加它吗? - Windows path doesn't contain C:\WINDOWS\system32, can I add it using batch script? 将system32中的批处理文件目录更改为CMD命令执行点 - Change batch file directory in system32 to CMD command execution point Puppet 无法在 C:\\windows\\system32 文件夹中创建文件 - Puppet is not able to create files in C:\windows\system32 folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM