1

I'm developing an HTA file and i"m trying to create a link in wich the user will be logged off when clicked.

My function:

function fn_fecha()
{
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("C:\\Windows\\System32\\logoff.exe");
}

and the call:

<tr>
<td WIDTH=300>
</td>            
<td>
<a id=hsair href="#" onclick="javascript:fn_fecha"  >SAIR</a>
</td>               
</tr>

I've tried both the function with just one "\" (c:\windows\system32\logoff.exe) and the function with fn_fecha(), but it does not find the file when i do this. The HTA file is hosted on a server (but is not open via IIS).

4

2 回答 2

1

在 Windows 7 x64 中,您可以找到文件夹“C:\Windows\SysWOW64”,其中包含一些 32 位应用程序和库以创建 32 位兼容环境。

(另请参阅:为什么在 64 位 Windows 上 64 位 DLL 转到 System32 而 32 位 DLL 转到 SysWoW64?

在这种情况下,您打算调用 C:\Windows\System32\logoff.exe,但不知何故,路径已重定向到不存在的 C:\Windows\SysWOW64\logoff.exe。所以在这里你得到一个文件未找到的错误。

你可以做一个实验来证明。只需将可执行文件复制到 C:\Windows\SysWOW64\test1.exe,然后尝试使用 mshta 运行以下代码。看到魔法了吗?

    <script>new ActiveXObject("WScript.Shell").Run(
"C:\\Windows\\System32\\test1.exe");</script>

PS 令我惊讶的是,mshta.exe 和 wshom.ocx 都是 64 位的,那么为什么 Windows 将路径指向 SysWOW64?

于 2013-07-11T13:46:01.010 回答
0

解决方案

而不是指定路径 C:\Windows\System32 使用特殊别名%WINDIR%\Sysnative

function fn_fecha()
{
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("%WINDIR%/Sysnative/logoff.exe");
}

解释

您的 32 位应用程序正在尝试访问为 64 位代码保留的 %Windir%\System32 文件夹中的代码。如此Microsoft 知识库文章所述,Windows 正在静默重定向您的请求:

在运行 64 位版本 Windows 的计算机上...32 位应用程序无法访问以下文件夹:

%WinDir%\System32

因此,32 位应用程序无法启动 System32 文件夹中的任何 64 位应用程序。此外,32 位应用程序无法检索有关 System32 文件夹或 System32 文件夹的子文件夹中的任何文件的文件信息......

出现此问题的原因是 Windows 64 位 (WOW64) 上的 Windows 提供文件系统重定向。在 64 位版本的 Windows 中...%WinDir%\System32 文件夹是为 64 位应用程序保留的。当 32 位应用程序尝试访问 System32 文件夹时,访问被重定向到以下文件夹:

%WinDir%\SysWOW64

默认情况下,启用文件系统重定向。

在您的情况下logoff.exe,SysWOW64 文件夹中不存在,产生文件未找到错误。文章解释了特殊别名%WinDir%\Sysnative绕过了不需要的文件重定向:

WOW64 将 Sysnative 文件夹识别为特殊别名。因此,文件系统不会将访问重定向到 Sysnative 文件夹之外。这种机制灵活且易于使用。您可以使用 Sysnative 文件夹绕过文件系统重定向。

请注意,本文中提到的修补程序仅适用于 Windows Server 2003/XP。此功能内置于更高版本的 Windows。

于 2016-03-23T20:08:39.743 回答