path to hosts file from script
Posted: 15 Mar 2024 04:31
trying to read path of hosts file but it does not work in script
it output
but when trying
on command line, it give me
what am I doing wrong?
Code: Select all
@echo off
for /f "tokens=1,3" %%a in ('
reg query "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /V "DataBasePath"
') do (
if "%%~a"=="DataBasePath" set "hostspath=%%b"
)
if exist "%hostspath%\hosts" (echo yes) else (echo no)
echo "%hostspath%\hosts"
dir "%hostspath%\hosts"
Code: Select all
no
"%SystemRoot%\System32\drivers\etc\hosts"
The system cannot find the path specified.
Code: Select all
dir "%SystemRoot%\System32\drivers\etc\hosts"
Code: Select all
Directory of C:\WINDOWS\System32\drivers\etc
23/05/2021 16:13 895 hosts
1 File(s) 895 bytes
0 Dir(s) 42,341,171,200 bytes free