Skip to content

Batch (Updater and DNS cache) crashed my system... #2893

Open
@Enelass

Description

@Enelass

https://github.com/StevenBlack/hosts/blob/dbdcb032706dfe548745266218501afa93c14ad5/updateHostsWindows.bat

On modern Windows 10 and Windows 11 systems, the file paths

%SYSTEMROOT%\SysWOW64\config\system
%SYSTEMROOT%\system32\config\system
do not exist. These paths were used in older privilege-checking batch file techniques, but Microsoft has since hardened system directories and registry hives. Trying to access these on Windows 11 will typically result in an error, even when run as administrator.

Implications for your script
The script attempts to check for administrator rights by accessing these files with cacls.exe.
On Windows 11, this check will always fail because the files don’t exist, meaning the script will always try to re-launch itself with elevated privileges, or just fail the privilege check.
What to do instead?
A more robust, modern approach for checking admin rights in batch scripts is to use the NET SESSION command:

batch
net session >nul 2>&1
if %errorLevel% neq 0 (
echo Requesting administrative privileges...
goto UACPrompt
) else (
goto gotAdmin
)
net session requires admin rights, but doesn’t rely on deprecated or non-existent files.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions