[英]Why does a batch file executed from a WinRAR SFX not work on accessing hosts file?
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.但是在将此批处理文件打包到 WinRAR 自解压存档中并在解压过程中自动运行时,它无法按预期工作。
You are creating a 32-bit RAR self-extracting archive.您正在创建一个 32 位 RAR 自解压存档。 Therefore the batch file is processed by 32-bit
cmd.exe
which results in accessing %SystemRoot%\\SysWOW64
instead of %SystemRoot%\\System32
according to Microsoft's File System Redirector documentation.因此,根据 Microsoft 的文件系统重定向器文档,批处理文件由 32 位
cmd.exe
处理,这会导致访问%SystemRoot%\\SysWOW64
而不是%SystemRoot%\\System32
。 You should also take a look on WOW64 Implementation Details and Registry Keys Affected by WOW64 .您还应该查看WOW64 实施详细信息和受 WOW64 影响的注册表项。
The directory %SystemRoot%\\SysWOW64
does not contain drivers\\etc\\hosts
.目录
%SystemRoot%\\SysWOW64
不包含drivers\\etc\\hosts
。 The hosts
file exists on 64-bit Windows only in subdirectory of System32
for 64-bit applications.对于 64 位应用程序,
hosts
文件仅存在于 64 位 Windows 的System32
子目录中。
Sysnative
redirector 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 the hosts
file which usually only malware modifies, but no friendly application installed with a RAR self-extracting archive. Sysnative
重定向器仅适用于在 64 位 Windows 上运行的 32 位应用程序,可用于确定批处理文件在哪个环境中运行以访问hosts
文件,该文件通常仅由恶意软件修改,但没有安装带有 RAR 自解压的友好应用程序存档。
@echo off
set "SystemPath=%SystemRoot%\System32"
if exist "%SystemRoot%\Sysnative\cmd.exe" set "SystemPath=%SystemRoot%\Sysnative"
set "HostsFile=%SystemPath%\drivers\etc\hosts"
%SystemPath%\attrib.exe -r %HostsFile%
pause
Please note that %SystemRoot%\\Sysnative
is neither a directory nor a link in file system.请注意
%SystemRoot%\\Sysnative
既不是目录也不是文件系统中的链接。 It is a redirector for 32-bit applications on 64-bit Windows.它是 64 位 Windows 上 32 位应用程序的重定向器。 So with 64-bit Windows Explorer as started by default on 64-bit Windows or any other 64-bit application
%SystemRoot%\\Sysnative
does not exist at all.因此,在 64 位 Windows 或任何其他 64 位应用程序上默认启动 64 位 Windows 资源管理器时,
%SystemRoot%\\Sysnative
根本不存在。 And 32-bit applications can only check if there is any file in %SystemRoot%\\Sysnative
, but can't check if a directory %SystemRoot%\\Sysnative
exists.而 32 位应用程序只能检查
%SystemRoot%\\Sysnative
是否有任何文件,而无法检查目录%SystemRoot%\\Sysnative
存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.