1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

batファイルでhostsへバーチャルホストを追記する方法

Last updated at Posted at 2015-10-09

batファイル作成

@echo off
if not "%1" == "-" powershell "$obj=New-Object -Com Shell.Application ; $obj.ShellExecute('%~f0','-','','runas')" & exit /b
type C:\WINDOWS\System32\drivers\etc\hosts
set /p INPUT="please type vhostname: "
echo .
echo 127.0.0.1		%INPUT% >> C:\WINDOWS\System32\drivers\etc\hosts
cmd /k type C:\WINDOWS\System32\drivers\etc\hosts

問題点

右クリックの「管理者として実行」からじゃないとアクセスを拒否される。

どなたか解決策を・・・!

追記

zetamattaさんからご教授頂いた部分を追記しました!ありがとうございます!

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?