Code: Select all
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win7
; Author: J.G. 12/22/2016 11:07AM
;
; Script Function:
; Assist in backing up (exporting) HPNA Policies
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; #SingleInstance Force ; At the moment I want the reload message
web := IEGet("HP Network Automation: Import/Export Policies")
; elements := web.document.getElementsByTagName("div") ; has innertext
elements := web.document.getElementsByTagName("input") ; has type = hidden/button/checkbox, id & value, name = "eid", title,
; not label, class
names := ""
ids := ""
Loop % elements.length
{
if elements[A_Index -1].type = "checkbox"
{
if web.document.GetElementbyID(elements[A_Index -1].id).checked = -1
{
names := names elements[A_Index -1].title "`n"
ids := ids elements[A_Index -1].id "`n"
web.document.GetElementbyID(elements[A_Index -1].id).click()
}
}
if elements[A_Index -1].type = "button"
{
if elements[A_Index -1].title = "Export Policy"
{
exporter := elements[A_Index -1]
}
}
}
namearray := StrSplit(names,"`n")
idarray := StrSplit(ids,"`n")
Loop, % idarray.MaxIndex()-1
{
web.document.GetElementbyID(idarray[A_Index]).click()
;<input type="button" name="Submit" title="Export Policy" value="Export" class="FormButton" onclick="submitExportForm('config_policy.exp')">
thisname := namearray[A_Index]
exporter.click()
Sleep 1000
WinActivate, HP Network Automation: Import/Export Policies
WinWaitActive, HP Network Automation: Import/Export Policies
; Things I've tried but didn't work
; ControlFocus, DirectUIHWND2
; ControlSend, DirectUIHWND2, {Tab 2}{Down 2}{Enter} ; Didn't work
; WinActivate, ahk_class DirectUIHWND2
; ControlFocus, ahk_class DirectUIHWND1
; WinActivate, ahk_class DirectUIHWND1
WinWaitActive, Save As
; SendInput {Home} ; If we want to leave the config_policy.exp string unchanged
SendInput %thisname% ; {Space} Only need the space if we're prepending the name and leaving config_policy.exp
WinWaitClose, Save As
WinActivate, HP Network Automation: Import/Export Policies
WinWaitActive, HP Network Automation: Import/Export Policies
if web.document.GetElementbyID(idarray[A_Index]).checked = -1
web.document.GetElementbyID(idarray[A_Index]).click()
}
; ----------------------------------------------------------------------------------------------------
IEGet(Name="") ; Retrieve pointer to existing IE window/tab
{
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
: RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
For wb in ComObjCreate( "Shell.Application" ).Windows
{
wbLocName := wb.LocationName
wbFullName := wb.FullName
If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
{
Return wb
} ; If
} ; For wb
} ;written by Jethrow
From: Jay Grace