To content | To menu | To search

Windows の hosts に簡単にエントリーを追加したい

テキストエディタを管理者権限で起動してもらうのは面倒なので、もう少し簡単にならないかなあ、と思った。

だからといってコマンドプロンプトは簡単じゃないと思いながら。

コマンドプロンプトを、「管理者として実行」で起動。

type %SystemRoot%\System32\drivers\etc\hosts

で内容を表示できる。

0.0.0.0 spam.example.com

の様に追加すると、この例では spam.example.com にアクセスできないようになる。

echo "# hello" >> %SystemRoot%\System32\drivers\etc\hosts
echo '# hello' >> %SystemRoot%\System32\drivers\etc\hosts
echo # hello >> %SystemRoot%\System32\drivers\etc\hosts

とりあえずお試しとして、こんな感じで追加してみようとしたところ、

"# hello"
'# hello'
# hello

引用符がそのまま追記されてしまったので、そういうのは無しで良さそう。

なので単純に、

echo 0.0.0.0 spam.example.com >> %SystemRoot%\System32\drivers\etc\hosts

でよさそう。

失敗したら、素直にテキストエディタを管理者権限で起動して編集。

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

They posted on the same topic

Trackback URL : https://www.pseudomoon.jp/dotclear/index.php?trackback/93

This post's comments feed