Jump to content
Sign in to follow this  

Launching HTA in WinPE with Autoit

Recommended Posts


I am currently launching the code below from a x86 WinPE session. The Autoit script looks for a window called "Installation Progress" (Which btw is a another spawned program from WinPE) and attempts to minimize it, and then subsequently launches mshta.exe to display an HTA, which is supplied through command line argument.

The windows only minimizes when I move my mouse over the "Installation Progress", and once it the HTA exits I again have to move the mouse over the minimized window to restore it to it's original position.

So the script is working, sort of...but with manual intervention.

Any ideas how to fix this?


#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <file.au3>
Global $WindowName, $logfile, $val
AutoItSetOption("WinTitleMatchMode", 4)
;Set the Windows Name Properties for the Task sequence
$WindowName = "Installation Progress"
;$WindowName = "Untitled - Notepad"

$logfile = @WindowsDir & "\Temp\installation.log"
_FileWriteLog($logfile, " " & "Version 1.03")
If $CmdLine[0] = 0 Then
    _FileWriteLog($logfile, " " & "ERROR 55: Not enough command line arguments supplied, exiting")
ElseIf Not FileExists(@ScriptDir & "\" & $CmdLine[1]) Then
    _FileWriteLog($logfile, " " & " ERROR 56: " & @ScriptDir & "\" & $CmdLine[1] & " file not found, exiting...")
    _FileWriteLog($logfile, " " & @ScriptDir & "\" & $CmdLine[1] & " file found, starting execution of script")

;Get the handle of the Active Window
$handle = WinGetHandle($WindowName, "")
If @error Then
    _FileWriteLog($logfile, " " & $WindowName & " has not been found....waiting for it.")
    _FileWriteLog($logfile, " " & $WindowName & " window has been found, hiding it now.")
    WinSetState($handle, "", @SW_MINIMIZE)
    ; Wait for mshta.exe to execute
    _FileWriteLog($logfile, " About to Launch command: " & @SystemDir & "\mshta.exe " & '"' & @ScriptDir & "\" & $CmdLine[1] & '"')
    $val = ShellExecuteWait(@SystemDir & "\mshta.exe ", '"' & @ScriptDir & "\" & $CmdLine[1] & '"', @SystemDir, "", @SW_MAXIMIZE)

    If $val <> 0 Then
        _FileWriteLog($logfile, "Error launching Mshta.exe...")
        MsgBox(262160, "Error", "Error launching Mshta.exe")
        _FileWriteLog($logfile, " Mshta.exe successfully launched with supplied command line paramater")
        _FileWriteLog($logfile, " " & "Showing Task Sequence window again")
        WinSetState($handle, "", @SW_RESTORE)
        _FileWriteLog($logfile, " Exiting... ")

Share this post

Link to post
Share on other sites


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this