Skip to content

Instantly share code, notes, and snippets.

@cminhho
Last active August 29, 2015 14:27
Show Gist options
  • Save cminhho/eb8a9ac385231fd9a2d6 to your computer and use it in GitHub Desktop.
Save cminhho/eb8a9ac385231fd9a2d6 to your computer and use it in GitHub Desktop.
Login TPC
#include <Constants.au3>
#include <IE.au3>
;
; AutoIt Version: 1.0
; Language: English
; Platform: Window7
; Author: Chung Ho
;
; Script Function:
; Opens MobilePASS, get password paste into tpc then quits the application.
;
; *********************************************
; Setup your config here
; *********************************************
Local $tokenID = 1234; your MobilePass application password
Local $tpcUsername = "hmchung@tma.com.vn"; your TPC login email
Local $mobilePassUrl = "E:\Software Center\Developer Tools\MobilePASS.exe"; MobilePass Applciatoion location
Local $tpcUrl = "https://tpc-sslvpn-apac.alcatel-lucent.com/workplace/access/home"
Local $passcode
Func LoginTPC()
;create the webpage
$oIE = _IECreate ($tpcUrl, 1, 1, 1, 1)
;find the object in the page with the name "Log in to"
$o_loginTo = _IEGetObjByName ($oIE, "realmID")
_IEFormElementSetValue ($o_loginTo, 148)
;find the object in the page with the name "submit" and click on it
$o_submit = _IEGetObjByName ($oIE, "realmButton")
_IEAction ($o_submit, "click")
;wait the end of loading
_IELoadWait ($oIE)
;find the object in the page with the name "username"
$o_user = _IEGetObjByName ($oIE, "data_0")
_IEFormElementSetValue ($o_user, $tpcUsername)
;find the object in the page with the name "password"
$o_password = _IEGetObjByName ($oIE, "data_1")
_IEFormElementSetValue ($o_password, $passcode )
;find the object in the page with the name "submit" and click on it
$o_login = _IEGetObjByName ($oIE, "okButton")
_IEAction ($o_login, "click")
EndFunc
Func OpenMobilePass()
; Run MobilePASS
Local $iPID = Run($mobilePassUrl)
; Wait for the MobilePASS to become active. The classname "MobilePASS" is monitored instead of the window title
Local $hWnd = WinWait("[CLASS:MobilePASS]", "", 1)
; Enter Token PIN
Local $setToken = ControlSetText("MobilePASS", "", "[CLASS:Edit;INSTANCE:1]", $tokenID)
; Retrieve the handle of the continue control in MobilePASS. The handle returned by WinWait is used for the "title" parameter of ControlGetHandle.
ControlClick("MobilePASS","","[CLASS:Button;INSTANCE:3]")
;Give MobilePASS some time to load
Sleep(2000)
; Retrieve the text of the edit control
$passcode = ControlGetText("MobilePASS", "", "[CLASS:Edit;INSTANCE:1]")
; End MobilePASS app
ProcessClose($iPID)
EndFunc
Func CloseApplicationProcess($vVar1)
;Local $mpProc = "MobilePASS.exe"
While ProcessExists($vVar1)
ProcessClose($vVar1)
Wend
EndFunc
Func CloseWindow($vVar1)
While WinExists($vVar1)
WinClose($vVar1)
Wend
EndFunc
; *********************************************
; Event
; *********************************************
CloseApplicationProcess("MobilePASS.exe"); close all MobilePASS application process instances
CloseWindow("TPC Portal - Windows Internet Explorer"); close all TPC application process instances
OpenMobilePass(); Open the MobilePASS app
LoginTPC(); Login TPC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment