Sistemi operativi a 64 e HTA

Sui sistemi operativi a 64 bit come ad esempio Windows Server 2008 R2 esistono sia la versione a 32 bit che a 64 bit del Microsoft HTML Application Host (mshta.exe) che permette di eseguire i file HTA (HTML Application).

La versione a 64 bit si trova in %SystemRoot%\System32\mshta.exe, mentre la versione a 32 bit si trova in %SystemRoot%\SysWOW64\mshta.exe. Per maggiori informazioni sull’esecuzione delle applicazioni a 32 bit in OS a 64 tramite la tecnologia WOW64 si veda Running 32-bit Applications.

Per impostazione predefinita avviando un file HTA su Windows Server 2008 R2 viene aperto l’interprete HTA a 32:

image

Questo comporta che in alcuni casi gli script contenuti all’interno del fileHTA potrebbe andare in errore, ad esempio se vengono eseguite delle letture su alcune chiavi di registro nel ramo HKLM\SOFTWARE.

Si consideri ad esempio il seguente file hta che visualizza la data dell’ultimo download e dell’ultimo rilevamento tramite Windows Update:

<html>
<head>
  <title>Test HTML Application</title>
  <hta:application id=”Test”
    applicationname=”Test”
    version=”1.0″
    singleinstance=”yes”
    minimizeButton=”no”
    maximizeButton=”yes”
    windowstate=”maximize”
    borderStyle=”static”/>
  <script language=”vbscript”>
    Option Explicit

    Function ReadRegistryKey(path)       
      Dim ws
      ReadRegistryKey = Null
     
      Set ws = createobject(“WScript.Shell”)
      ReadRegistryKey = ws.RegRead(path)
      Set ws = Nothing
    End Function
  </script>
</head>

<body>

<p>Windows update last download:
<script>
document.write( _
ReadRegistryKey(“HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Download\LastSuccessTime“))
</script>
</p>

<p>Windows update last detect:
<script>
document.write( _
    ReadRegistryKey(“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Detect\LastSuccessTime“))
</script>
</p>

</body>
</html>

Se eseguito restituirà il seguente errore:

image

Per evitare l’errore occorre forzare l’utilizzo dell’interpreter a 64 bit tramite il comando:

%SystemRoot%\System32\mshta.exe test.hta 

image

image