Example of a quick way to edit a host file with a BAT script _dos/bat

Source: Internet
Author: User

When doing web program development sometimes do such an operation, is to modify the Hosts file to do virtual domain name mapping to facilitate local development, For example, the www.jb51.net this domain point to the local 127.0.0.1, the operation itself is not complicated, but in the Windows environment, hosts file hidden deep, so we have to Baidu every time the Hosts file path and then a layer to open the file directory to find this file , if the change of frequent words, is really more trouble, so here I summed up a relatively good and slightly master a way to share.

First, use text editing software such as Notepad to write the following code:

Copy Code code as follows:

:: Remove the Hosts file read-only attribute
Attrib-r C:\windows\system32\drivers\etc\hosts
:: Edit Hosts file with Notepad
Notepad C:\windows\system32\drivers\etc\hosts
:: Add read-only attribute to Hosts file
attrib +r C:\windows\system32\drivers\etc\hosts

Then save the file as a. bat file with the suffix name (for example, Hosts.bat).

Second, put the file into the \Windows\System32 directory, in fact, this is not necessarily placed in this directory, you can create a new directory in any location, and then copy the full path of the directory to the WINDOWS system environment variables inside.

OK, a simple two-step, after the need to modify the hosts file, directly in the operation of the input hosts, the system will automatically turn the hosts file into a writable, and then open the Hosts file, waiting for editing after the exit and automatically turn the file into read-only. Very convenient

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.