Jump to content

Script halts after IE load


Recommended Posts

Hi All,

I am trying to automate inputting of username and password into a website.  Usually this works fine, but for some reason after loading IE, the script just stops.  No errors, just, nothing.  I think this might have something to do with the domain policy or IE policy of the customer, because when we take the machine off the domain, it works fine.  Has anyone encountered group policy from prohibiting AutoIt working correctly?

The code is below for reference

#AutoIt3Wrapper_UseX64=n
Opt("MustDeclareVars", 1)

;=======================================
; Consts & Globals
;=======================================
Global Const $DISPATCHER_NAME                                   = "vSphere Web Client"
Global Const $CLIENT_EXECUTABLE                                 = "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
Global Const $ERROR_MESSAGE_TITLE                               = "PSM " & $DISPATCHER_NAME & " Dispatcher error message"
Global Const $LOG_MESSAGE_PREFIX                                = $DISPATCHER_NAME & " Dispatcher - "
Global Const $EXACT_TITLE_MATCH = 3


AutoItSetOption("WinTitleMatchMode", $EXACT_TITLE_MATCH)

Global $TargetUsername
Global $TargetPassword
Global $TargetAddress
Global $ConnectionClientPID = 0

;=======================================
; Code
;=======================================
Exit Main()

;=======================================
; Main
;=======================================
Func Main()

    ; Init PSM Dispatcher utils wrapper
    ToolTip ("Initializing...")
    if (PSMGenericClient_Init() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("successfully initialized Dispatcher Utils Wrapper")

    ; Get the dispatcher parameters
    FetchSessionProperties()

    LogWrite("mapping local drives")
    if (PSMGenericClient_MapTSDrives() <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    LogWrite("starting client application")
    ToolTip ("Starting " & $DISPATCHER_NAME & "...")
      RegWrite ( "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" , "1A10", "REG_DWORD", 0 )
   RegWrite ( "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" , "2500", "REG_DWORD", 3 ) ; disable protected mode in IE to prevent flash popups
   RegWrite ( "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main" , "NoProtectedModeBanner", "REG_DWORD", 1 ) ; disable warning about protected mode.
   RegWrite ( "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\" & $TargetAddress , "http", "REG_DWORD", 00000002 )
   RegWrite ( "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\" & $TargetAddress , "https", "REG_DWORD", 00000002 ) ; add targetaddress to trusted sites.
tooltip("finished writing reg keys")
    Local $oIE = _IECreate("https://" & $TargetAddress & ":9443/vsphere-client/#/")
    tooltip("inside ie function")
      With $oIE
         .Left = 0
         .Right = 0
         .Resizable = False
         .StatusBar = False
         .TheaterMode = True
         .Toolbar = False
         .Visible = True
         .Fullscreen = True
     EndWith
     tooltip("before clientPID")
    $ConnectionClientPID = WinGetProcess("[CLASS:IEFrame]")
    if ($ConnectionClientPID == 0) Then
        Error(StringFormat("Failed to execute process [%s]", $CLIENT_EXECUTABLE, @error))
    EndIf
    ; Send PID to PSM as early as possible so recording/monitoring can begin
    LogWrite("sending PID to PSM")
    if (PSMGenericClient_SendPID($ConnectionClientPID) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    ; ------------------
    ; Handle login here!
    ; ------------------
Tooltip("inside login")
    WinWait("Certificate Error: Navigation Blocked - Internet Explorer")
    send("{TAB 2}")
    SEND("{ENTER}")
    WinWait("vSphere Web Client - Internet Explorer")
    ; - Enter  Credentials
    Sleep("15000")
    ToolTip("Waiting for background processes to load")
    Send($TargetUsername)
    Send("{TAB}")
    Send($TargetPassword)
    Send("{Enter}")
    BlockInput(0)


    ; Terminate PSM Dispatcher utils wrapper
    LogWrite("Terminating Dispatcher Utils Wrapper")
    PSMGenericClient_Term()

    Return $PSM_ERROR_SUCCESS
EndFunc


;==================================
; Functions
;==================================
; #FUNCTION# ====================================================================================================================
; Name...........: Error
; Description ...: An exception handler - displays an error message and terminates the dispatcher
; Parameters ....: $ErrorMessage - Error message to display
;                  $Code         - [Optional] Error code
; ===============================================================================================================================
Func Error($ErrorMessage, $Code = -1)

    ; If the dispatcher utils DLL was already initialized, write an error log message and terminate the wrapper
    if (PSMGenericClient_IsInitialized()) Then
        LogWrite($ErrorMessage, 0)
        PSMGenericClient_Term()
    EndIf

    Local $MessageFlags = BitOr(0, 16, 262144) ; 0=OK button, 16=Stop-sign icon, 262144=MsgBox has top-most attribute set

    MsgBox($MessageFlags, $ERROR_MESSAGE_TITLE, $ErrorMessage)

    ; If the connection component was already invoked, terminate it
    if ($ConnectionClientPID <> 0) Then
        ProcessClose($ConnectionClientPID)
        $ConnectionClientPID = 0
    EndIf

    Exit $Code
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: LogWrite
; Description ...: Write a PSMWinSCPDispatcher log message to the standard PSM log file
; Parameters ....: $sMessage - [IN] The message to write
;                  $LogLevel - [IN] Defined if the message should be handled as an error message.
;                                   Valid values are either $LOG_LEVEL_TRACE or $LOG_LEVEL_ERROR.
; Return values .: $PSM_ERROR_SUCCESS - Success, otherwise error - Use PSMGenericClient_PSMGetLastErrorString for details.
; ===============================================================================================================================
Func LogWrite($sMessage, $LogLevel = $LOG_LEVEL_TRACE)
    Return PSMGenericClient_LogWrite($LOG_MESSAGE_PREFIX & $sMessage, $LogLevel)
EndFunc

Func FetchSessionProperties() ; CHANGE_ME
    if (PSMGenericClient_GetSessionProperty("Username", $TargetUsername) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("Password", $TargetPassword) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf

    if (PSMGenericClient_GetSessionProperty("Address", $TargetAddress) <> $PSM_ERROR_SUCCESS) Then
        Error(PSMGenericClient_PSMGetLastErrorString())
    EndIf
EndFunc

 

Link to comment
Share on other sites

Where does it stop? Does it exit the script or just hang at some point? You have 2 WinWaits that could be causing it to stop at either one of those points, can't tell because you don't include the target address.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

1 hour ago, Juvigy said:

I think this is related to security across different domains. Instead of IECreate(address) try _IEcreate (blank) and then _IENavigate or $oIE.navigete2

You legend, this was it exactly!  I opened a blank IE, let it do its thing, then navigated to the website successfully.

 

Thank you so much!

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