2

ホスト ファイル内の IP アドレスを検索して置き換えるバッチ ファイルを作成しようとしています。

少し調べてこれを見つけましたが、うまくいかないようです。「完了」という最後のエコーが聞こえます。しかし、うまくいきません。

@echo off

REM Set a variable for the Windows hosts file location
set hostpath=%systemroot%\system32\drivers\etc
set hostfile=hosts

REM Make the hosts file writable
attrib -r %hostpath%\%hostfile%

setlocal enabledelayedexpansion
set string=%hostpath%\%hostfile%

REM set the string you wish to find
set find=OLD IP

REM set the string you wish to replace with
set replace=NEW IP
call set string=%%string:!find!=!replace!%%
echo %string%

REM Make the hosts file un-writable
attrib +r %hostpath%\%hostfile%

echo Done.
4

3 に答える 3