|
- $ErrorActionPreference = 'Stop'
- $root = Split-Path -Parent $PSScriptRoot
- $hta = Get-Content -LiteralPath (Join-Path $root 'MassMailer.hta') -Raw
- $match = [regex]::Match($hta, '(?s)<script language="JScript" type="text/javascript">(.*?)</script>')
- if (-not $match.Success) { throw 'HTA JScript block not found' }
- $check = Join-Path $root ('temp\hta-syntax-' + [guid]::NewGuid().ToString('N') + '.js')
- try {
- [System.IO.File]::WriteAllText($check, $match.Groups[1].Value)
- $scriptHost = Join-Path $env:SystemRoot 'SysWOW64\cscript.exe'
- & $scriptHost //nologo //E:JScript $check
- if ($LASTEXITCODE -ne 0) { throw 'HTA JScript syntax failed' }
- Write-Output 'HTA JScript syntax passed'
- }
- finally { if (Test-Path -LiteralPath $check) { Remove-Item -LiteralPath $check -Force } }
|