简体   繁体   English

Javascript Windows注销-logoff.exe

[英]Javascript Windows Logoff - logoff.exe

I'm developing an HTA file and i"m trying to create a link in wich the user will be logged off when clicked. 我正在开发HTA文件,并且尝试创建一个链接,以使用户在单击时将注销。

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. 我已经尝试了仅使用一个“ \\”(c:\\ windows \\ system32 \\ logoff.exe)的功能以及使用fn_fecha()的功能,但是在执行此操作时找不到文件。 The HTA file is hosted on a server (but is not open via IIS). HTA文件托管在服务器上(但无法通过IIS打开)。

In Windows 7 x64 you can find the folder "C:\\Windows\\SysWOW64", which contains some 32-bit applications and libraries to create a 32-bit compatible environment. 在Windows 7 x64中,您可以找到文件夹“ C:\\ Windows \\ SysWOW64”,其中包含一些32位应用程序和库来创建32位兼容环境。

(See also: Why do 64-bit DLLs go to System32 and 32-bit DLLs to SysWoW64 on 64-bit Windows? ) (另请参见: 为什么在64位Windows上,64位DLL进入System32,为什么32位DLL进入SysWoW64?

In this case, you meant to invoke C:\\Windows\\System32\\logoff.exe, but somehow the path had been redirected to C:\\Windows\\SysWOW64\\logoff.exe, which does not exist. 在这种情况下,您打算调用C:\\ Windows \\ System32 \\ logoff.exe,但是以某种方式将路径重定向到了C:\\ Windows \\ SysWOW64 \\ logoff.exe,该路径不存在。 So here you got a file-not-found error. 因此,这里出现了一个文件未找到的错误。

You can do a experiment to prove it. 您可以做一个实验来证明这一点。 Just copy an executable to C:\\Windows\\SysWOW64\\test1.exe, and try run the following code with mshta. 只需将可执行文件复制到C:\\ Windows \\ SysWOW64 \\ test1.exe,然后尝试使用mshta运行以下代码。 See the magic? 看到魔术了吗?

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

PS To my surprise, both mshta.exe and wshom.ocx are 64-bit, then why does Windows direct the path to SysWOW64? PS令我惊讶的是,mshta.exe和wshom.ocx都是64位的,那么Windows为什么将路径定向到SysWOW64?

Solution

Instead of specifying the path C:\\Windows\\System32 use the special alias %WINDIR%\\Sysnative 代替指定路径C:\\ Windows \\ System32,使用特殊别名%WINDIR%\\ Sysnative

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

Explanation 说明

Your 32-bit application is trying to access code in the %Windir%\\System32 folder which is reserved for 64-bit code. 您的32位应用程序正试图访问%Windir%\\ System32文件夹中的代码,该文件夹保留用于64位代码。 Windows is silently redirecting your request as explained by this Microsoft KB article : Windows正在按照Microsoft知识库文章的说明静默地重定向您的请求:

On a computer that is running a 64-bit version of Windows...a 32-bit application cannot access the following folder: 在运行Windows 64位版本的计算机上... 32位应用程序无法访问以下文件夹:

%WinDir%\\System32 %WINDIR%\\ SYSTEM32

Therefore, the 32-bit application cannot start any 64-bit applications in the System32 folder. 因此,该32位应用程序不能启动System32文件夹中的任何64位应用程序。 Additionally, the 32-bit application cannot retrieve file information about any files in the System32 folder or in the subfolders of the System32 folder.... 此外,32位应用程序无法检索有关System32文件夹或System32文件夹的子文件夹中任何文件的文件信息。

This behavior occurs because Windows on Windows 64-bit (WOW64) provides file system redirection. 出现此现象的原因在于Windows 64位(WOW64)上的Windows提供了文件系统重定向。 In a 64-bit version of Windows...the %WinDir%\\System32 folder is reserved for 64-bit applications. 在Windows的64位版本中,%WinDir%\\ System32文件夹保留用于64位应用程序。 When a 32-bit application tries to access the System32 folder, access is redirected to the following folder: 当32位应用程序尝试访问System32文件夹时,访问将重定向到以下文件夹:

%WinDir%\\SysWOW64 %WINDIR%\\ Syswow64资料

By default, file system redirection is enabled. 默认情况下,启用文件系统重定向。

In your case logoff.exe doesn't exist in the SysWOW64 folder, producing the file not found error. 在您的情况下,SysWOW64文件夹中不存在logoff.exe ,从而产生文件未找到错误。 The article explains that the special alias %WinDir%\\Sysnative bypasses the unwanted file redirection: 本文介绍了特殊别名%WinDir%\\ Sysnative绕过了不需要的文件重定向:

WOW64 recognizes the Sysnative folder as a special alias. WOW64将Sysnative文件夹识别为特殊别名。 Therefore, the file system does not redirect access away from the Sysnative folder. 因此,文件系统不会将访问重定向到Sysnative文件夹之外。 This mechanism is flexible and easy to use. 该机制灵活且易于使用。 You can use the Sysnative folder to bypass file system redirection. 您可以使用Sysnative文件夹绕过文件系统重定向。

Note that the hotfix mentioned in the article only applies to Windows Server 2003/XP. 请注意,本文中提到的修补程序仅适用于Windows Server 2003 / XP。 This functionality is built in to later versions of Windows. 此功能内置于Windows的更高版本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM