This batch code works on running the batch file directly:
set %windir%\system32\drivers\etc\hosts
attrib -r %hosts%
pause
But it does not work as expected on packing this batch file into a WinRAR self-extracting archive and running it automatically during extraction.
You are creating a 32-bit RAR self-extracting archive. Therefore the batch file is processed by 32-bit
cmd.exewhich results in accessing%SystemRoot%\SysWOW64instead of%SystemRoot%\System32according to Microsoft's File System Redirector documentation. You should also take a look on WOW64 Implementation Details and Registry Keys Affected by WOW64.The directory
%SystemRoot%\SysWOW64does not containdrivers\etc\hosts. Thehostsfile exists onĀ 64-bit Windows only in subdirectory ofSystem32for 64-bit applications.Sysnativeredirector existing only for 32-bit applications running on 64-bit Windows can be used to determine in which environment the batch file is running to access thehostsfile which usually only malware modifies, but no friendly application installed with a RAR self-extracting archive.Please note that
%SystemRoot%\Sysnativeis neither a directory nor a link in file system. It is a redirector for 32-bit applications on 64-bit Windows. So with 64-bit Windows Explorer as started by default on 64-bit Windows or any other 64-bit application%SystemRoot%\Sysnativedoes not exist at all. And 32-bit applications can only check if there is any file in%SystemRoot%\Sysnative, but can't check if a directory%SystemRoot%\Sysnativeexists.