Search code examples
javascripthtalogoff

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.

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).


Solution

  • 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.

    (See also: Why do 64-bit DLLs go to System32 and 32-bit DLLs to SysWoW64 on 64-bit Windows?)

    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. 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. See the magic?

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

    P.S. To my surprise, both mshta.exe and wshom.ocx are 64-bit, then why does Windows direct the path to SysWOW64?