Jump to content

Launching HTA in WinPE with Autoit


lyledg
 Share

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?

Cheers

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=Images\winicon.ico
#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")
    Exit
ElseIf Not FileExists(@ScriptDir & "\" & $CmdLine[1]) Then
    _FileWriteLog($logfile, " " & " ERROR 56: " & @ScriptDir & "\" & $CmdLine[1] & " file not found, exiting...")
    Exit
Else
    _FileWriteLog($logfile, " " & @ScriptDir & "\" & $CmdLine[1] & " file found, starting execution of script")
EndIf

;Get the handle of the Active Window
$handle = WinGetHandle($WindowName, "")
If @error Then
    _FileWriteLog($logfile, " " & $WindowName & " has not been found....waiting for it.")
Else
    _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")
        Exit
    Else
        _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... ")
        Exit
    EndIf
EndIf
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...