AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(七)
版本六中存在一个显著问题是:
当exe文件生存之后,运行的时候,通过consoleWrite函数打印出来的数据是无法展示出来的。这就存在一个问题:当运行失败的时候,我还是看不到任何log信息。
于是,我对程序再次进行了优化,代码如下:
#include <ScreenCapture.au3>
#include <GuiConstantsEx.au3>
#include <date.au3>
#include <GuiTab.au3>
#include <GuiEdit.au3>
#include <GuiScrollBars.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3> Opt("WinTitleMatchMode")
AutoItSetOption("SendKeyDelay")
AutoItSetOption("WinWaitDelay")
Global $hListBox ;区域截图
Func screen_capture($path)
If Not FileExists($path) or StringInStr($path,"\")= Then
_GUICtrlListBox_AddString($hListBox, _Now() & " " & "Failed to Save Screen Capture Picture: Path is not correct")
return
EndIf $handle = WinGetHandle(".NET Reactor")
if $handle="" then
_GUICtrlListBox_AddString($hListBox, _Now() & " " & "Failed to Screen Capture: can not get .NET Reactor window handle")
return
EndIf _GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get Screen capture Window Handle")
WinActivate($handle)
$control = ControlGetHandle($handle,"","[Name:groupBox6]")
if $control = "" then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Get Screen capture Group box handle")
return
EndIf
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get Screen capture Group box handle")
_ScreenCapture_CaptureWnd($path & "\AutoIt.jpg", $control)
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Save picture as AutoIt.jpg")
EndFunc ;无论焦点在哪儿,都回归到包含 EvaluationType 行
Func init($handle)
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
$text2 = $text
While StringInStr($text, "EvaluationType =") =
ControlSend($handle,"","", "{UP}")
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
If $text = $text2 And $text2 = "False" Then
ControlSend($handle,"","", "{Down}")
ExitLoop
EndIf
WEnd
EndFunc ;无论选项展开了多少次,都让所有的展开项收缩
Func collapse($handle)
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
ControlSend($handle,"","", "{Down}")
$text2 = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
While $text <> $text2
If StringInStr($text,$text2) <> Then
ControlSend($handle,"","", "{up}{enter}{down}")
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
ControlSend($handle,"","", "{Down}")
$text2 = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
Else
$text = $text2
ControlSend($handle,"","", "{Down}")
$text2 = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
EndIf
WEnd
EndFunc ;Display the HID in text field automatic
Func GetHid($filepath)
IF Not FileExists($filepath) or StringInStr($filepath,"\")= Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get HID: File path is not correct")
Return ""
EndIf
Dim $hid
$matches = StringRegExp($filepath, "\w{4}-\w{4}-\w{4}-\w{4}-\w{4}", , )
If IsArray($matches) Then
$hid = $matches[]
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get HID from file path")
Return $hid
EndIf
FileChangeDir($filepath)
$search = FileFindFirstFile("*.txt")
; 检查搜索是否成功
If $search = - Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to found HID from .txt file in the path")
Return
EndIf
While
$file = FileFindNextFile($search)
If @error Then
ExitLoop
EndIf
$matches = StringRegExp($file, "\w{4}-\w{4}-\w{4}-\w{4}-\w{4}", , )
If IsArray($matches) Then
$hid = $matches[]
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get HID from Text file name")
ExitLoop
EndIf Local $file2 = FileOpen($file)
If $file2 = - Then
ExitLoop
EndIf
While
Local $line = FileReadLine($file2)
If @error = - Then ExitLoop
$matches = StringRegExp($line, "\w{4}-\w{4}-\w{4}-\w{4}-\w{4}", , )
If IsArray($matches) Then
$hid = $matches[]
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get HID from txt file in file path")
ExitLoop
EndIf
$hid = ""
WEnd
FileClose($file2)
WEnd
; 关闭搜索句柄
FileClose($search)
Return $hid
EndFunc ;设置 Hardware ID
Func set_hardwareID($hardware_id, $date)
if StringLen($hardware_id) <> or StringInStr($hardware_id, "-")= or StringInStr($date,"/")= or StringLen($date)< Or StringLen($date)> Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to set HID: hardware ID or Expire Date format wrong")
return
EndIf
$handle = WinGetHandle(".NET Reactor")
if $handle="" then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get .NET Reactor handle")
Return
EndIf
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "get .NET Reactor handle")
WinActivate($handle)
$tab_control = ControlGetHandle($handle,"", "[name:tabControl2]")
_GUICtrlTab_ClickTab($tab_control, )
SendKeepActive($handle)
ControlSend($handle,"","", "{tab 4}")
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
While StringInStr($text, "RSAKeyValue") <>
ControlSend($handle,"","", "{tab 4}")
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
WEnd init($handle)
collapse($handle)
init($handle) ;输入日期
ControlSend($handle,"","", "{down}{enter}{down 2}")
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
If StringInStr($text,"/") <> Then
ControlSetText($handle,"", "[Class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1; Text:False]",$date)
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Set Date in Grid " & $date)
ControlSend($handle,"","", "{up 2}{enter}{up}")
Else
collapse($handle)
init($handle)
EndIf ;输入Hardware ID
ControlSend($handle,"","", "{down 2}{enter}{down 2}")
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
If StringInStr($text,"-") <> Then
ControlSetText($handle,"", "[Class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1; Text:False]",$hardware_id)
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Set HID in Grid " & $hardware_id)
ControlSend($handle,"","", "{up 2}{enter}{up 2}")
Else
collapse($handle)
init($handle)
EndIf
EndFunc ;保存 License
Func save_license($path)
if FileExists($path)= or StringInStr($path,"\")= Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Save License: Path is not correct")
Return
EndIf
$handle = WinGetHandle(".NET Reactor")
if $handle="" then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Save License: Failed to Get .NET reactor handle")
Return
EndIf
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get Save License Window handle")
WinActivate($handle) $control_handle = ControlGetHandle($handle,"","[Name:button1]")
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "get Save License pop up")
ControlClick($handle,"",$control_handle) $check = WinWaitActive("Save License As..")
if $check = Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to save license: Read pop up window failed")
Return
EndIf
$save_window_handle = WinGetHandle("Save License As..")
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get save license as pop up window") $save_input_control = ControlGetHandle($save_window_handle,"","Edit1")
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get Save License input field handle") ControlSetText($save_window_handle,"",$save_input_control,$path & "\SageTouch.License")
$save_button_handle = ControlGetHandle($save_window_handle,"","Button1")
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get Save License Save button") ControlClick($save_window_handle,"",$save_button_handle)
if WinWait("确认另存为","",)<> Then
$popup_handle = WinGetHandle("确认另存为")
WinWaitActive($popup_handle)
ControlClick($popup_handle,"", "Button1")
WinWaitClose($popup_handle, "", "Button1")
EndIf
If WinWait("All Done", "", ) <> Then
$popup_handle = WinGetHandle("All Done")
WinWaitActive($popup_handle)
ControlClick($popup_handle,"", "Button1")
WinWaitClose($popup_handle, "", "Button1")
EndIf
EndFunc ;检查 License 是否是正确的
Func exam_license($path)
If FileExists($path & "\SageTouch.License")= or StringInStr($path,"\")= Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to find Sagetouch.License in the path")
Return
EndIf
$handle = WinGetHandle(".NET Reactor")
if $handle="" then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Exam license, not get .Net Reactor win handle")
Return
EndIf WinActivate($handle)
SendKeepActive($handle)
$handle2 = ControlGetHandle($handle, "", "[NAME:menuStrip1]")
if $handle2 = "" then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get Exam License Menu handle failed")
Return
EndIf
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get menu handle")
ControlSend($handle, "","","{ALT}{Tab 2}{Enter}{Down}{Enter}")
$check = WinWaitActive("License Examiner", "", )
if $check = Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get exam license Pop up")
Return
EndIf
$license_exam_handle = WinGetHandle("License Examiner")
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get License Examiner pop up") $open_license_handle = ControlGetHandle($license_exam_handle,"","[Name:button2]")
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get button on License Examiner pop up")
ControlClick($license_exam_handle,"",$open_license_handle) $check = WinWaitActive("Please Select License File", "", )
if $check = Then
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Select License File pop up window")
Return
EndIf $select_license_handle = WinGetHandle("Please Select License File")
_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Select License File pop up window") $select_license_input_handle = ControlGetHandle($select_license_handle,"","Edit1")
$open_button_handle = ControlGetHandle($select_license_handle,"","Button1")
ControlSetText($select_license_handle,"",$select_license_input_handle,$path & "\SageTouch.License")
ControlClick($select_license_handle,"",$open_button_handle)
EndFunc ;Create a new GUI
GUICreate("Create License", , ) GUICtrlCreateLabel("Hardware ID", , , , )
$hardware_id = GUICtrlCreateLabel("XXXX-XXXX-XXXX-XXXX-XXXX", , , , ) GUICtrlCreateLabel("Expire Date", , , , )
$tTime = _Date_Time_GetSystemTime()
$aTime = _Date_Time_SystemTimeToArray($tTime)
$date = $aTime[] & "/" & $aTime[] & "/" & ""
$date2 = _DateAdd("M", , $date)
$date = GUICtrlCreateInput($date2, , , , ) GUICtrlCreateLabel("License File Path", , , , )
$path = GUICtrlCreateInput("", , , , )
GUICtrlSetState(-, $GUI_FOCUS) $exam_License = GUICtrlCreateButton("Exam License", , , , )
$Create_License = GUICtrlCreateButton("Create License", , , , )
$Save_License = GUICtrlCreateButton("Save License", , , , ) Global $hListBox = GUICtrlCreateList("Create License Log Info", , , , , BitOR($WS_BORDER, $WS_VSCROLL, $LBS_DISABLENOSCROLL, $LBS_NOTIFY, $WS_HSCROLL)) GUISetState()
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_UpdateHScroll($hListBox)
_GUICtrlListBox_EndUpdate($hListBox) While
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $Create_License
$hid = GetHid(GUICtrlRead($path))
GUICtrlSetData($hardware_id, $hid)
GUISetState()
set_hardwareID(GUICtrlRead($hardware_id), GUICtrlRead($date))
Case $msg = $Save_License
save_license(GUICtrlRead($path))
screen_capture(GUICtrlRead($path))
Case $msg = $exam_License
exam_license(GUICtrlRead($path))
EndSelect
Wend
界面如下:

AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(七)的更多相关文章
- 操作 AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(六)
自动化操作的稳定性,便利性虽然已经满足了要求,但是页面上呈现的按钮太多了,可以做的更加简单一些. 1. 简化页面的按钮,把5个按钮减少至3个,把Display HID按钮功能整合到create lic ...
- AutoIt脚本在做自动化操作的时候,如何进行错误捕获?
我的自动化脚本在运行的时候,会生成一个界面,点击该页面上的按钮能够进行自动化操作. 经常遇到的一个问题是: 脚本运行一半,GUI程序出现了异常情况,这个时候,再次点击生成的界面上的按钮,不会有任何反应 ...
- AutoIt 软件自动化操作
AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作. 它利用模拟键盘按键,鼠标移动和窗口/控件的组合来实现 ...
- sikuli--前端自动化操作的神器
前端自动话操作应用很广泛,从网购秒杀活动实现自动化抢购,到区块链货币高频交易前端脚本编写(非合作交易所不提供api的情况下). 自动化的流派分为2类,一类是对DOM对象进行解析的,这个是主流,但是受特 ...
- splinter python浏览器自动化操作,模拟浏览器的行为
Splinter可以非常棒的模拟浏览器的行为,Splinter提供了丰富的API,可以获取页面的信息判断当前的行为所产生的结果 最近在研究网站自动登录的问题,涉及到需要实现浏览器自动化操作,网上有 ...
- Python实现浏览器自动化操作
Python实现浏览器自动化操作 (2012-08-02 17:35:43) 转载▼ 最近在研究网站自动登录的问题,涉及到需要实现浏览器自动化操作,网上有不少介绍,例如使用pamie,但是只是 ...
- [转载]Python实现浏览器自动化操作
原文地址:Python实现浏览器自动化操作作者:rayment 最近在研究网站自动登录的问题,涉及到需要实现浏览器自动化操作,网上有不少介绍,例如使用pamie,但是只是支持IE,而且项目也较久没 ...
- Saltstack自动化操作记录(2)-配置使用 【转】
之前梳理了Saltstack自动化操作记录(1)-环境部署,下面说说saltstack配置及模块使用: 为了试验效果,再追加一台被控制端minion机器192.168.1.118需要在master控制 ...
- Saltstack自动化操作记录(1)-环境部署【转】
早期运维工作中用过稍微复杂的Puppet,下面介绍下更为简单实用的Saltstack自动化运维的使用. Saltstack知多少Saltstack是一种全新的基础设施管理方式,是一个服务器基础架构集中 ...
随机推荐
- iOS集成百度地图方法步骤
前言:app中的导航功能越来越流行,现在我自己做的项目中也有此需求,做过了后记录下笔记. 由于源代码保密所以这里仅仅提供demo,下面是效果图 一:iOS地图SDK 1.打开 百度地图api链接 i ...
- 微服务指南走北(三):Restful API 设计简述
API的定义取决于选择的IPC通信方式,假设是消息机制(如 AMQP 或者 STOMP).API则由消息频道(channel)和消息类型.假设是使用HTTP机制,则是基于请求/响应(调用http的ur ...
- POJ 1017 Packets(积累)
[题意简述]:这个是别人的博客,有清晰的题意描写叙述.和解题思路,借助他的想法,能够非常好的解决问题! [分析]:贪心?模拟?见代码 //216K 16Ms #include<iostream& ...
- const、typedef 、 define总结
constkeyword const=read only,修饰的为仅仅读变量而不是常量.const修饰的变量不能用作数组的维数也不能放在switch语句的case:之后. 主要作用有: 1.通过把不希 ...
- PHP 实现Word,excel等转换pdf
近期做一个项目,须要将用户上传的word,excel文档转成PDF文档保存并打印.在网上找了非常多资料.并不全面,所以自己写了一份比較全面的教程来分享. 以下是操作步骤: 1. 安装免费 ...
- 广告制胜无它,顺应人性尔——leo鉴书63
近期看了几本怎样写文案的书.对广告有了些兴趣.查了下相关销量排行,位置比較高的是本叫<科学的广告+我的广告生涯>的书,是同一作者(Claude C. Hopkins)两本书的合集.前者是他 ...
- Solaris 目录与文件管理
熟悉系统目录结构 掌握27个常用命令 掌握针对目录.文件的操作 掌握查找与文件内容的操作 一.命令 命令:内部命令(不依赖其他文件,可以直接执行)与外部命令 .他是用于实现某一类功能的指令或程序,其执 ...
- 【java读书笔记】——Collection集合之六大接口(Collection、Set、List、Map、Iterator和Comparable)
两个月之前准备软考时,简单的从理论上总结了最经常使用的数据结构和算法,比方:线性表,链表,图.在进行java开发时,jdk为我们提供了一系列对应的类来实现主要的数据结构.jdk所提供的容器API位于j ...
- jmeter后置处理器之正則表達式提取器
新浪围脖>@o蜗牛快跑o 使用这个组件时,注意使用带分组的正則表達式 使用正则分组方便提取干净数据.以免再次处理数据字符串 正則表達式在线工具推荐:点击打开链接 正則表達式语法參考:点击打 ...
- IOS UIScrollView滚动到指定位置
[mScrollView setContentOffset:CGPointMake(0,200) animated:YES];