操作 AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(六)
自动化操作的稳定性,便利性虽然已经满足了要求,但是页面上呈现的按钮太多了,可以做的更加简单一些。
1. 简化页面的按钮,把5个按钮减少至3个,把Display HID按钮功能整合到create license里面;把保存图片按钮功能放到保存License操作中;
2. 优化输入框。由3个简化为2个,因为HID是固定的,不应该支持手动修改,而expired date默认为当前日期延后2个月,是支持修改的;
代码如下:
#include <ScreenCapture.au3>
#include <GuiConstantsEx.au3>
#include <date.au3>
#include <GuiTab.au3>
#include <GuiEdit.au3> Opt("WinTitleMatchMode")
AutoItSetOption("SendKeyDelay")
AutoItSetOption("WinWaitDelay")
;区域截图
Func screen_capture($path)
if FileExists($path)= or StringInStr($path,"\")= Then
MsgBox(, "Path Error", "Please input correct Path info!")
Else
$handle = WinGetHandle(".NET Reactor")
if $handle="" then return
ConsoleWrite(_Now() & " "& "Screen capture win handle: " & $handle & @CRLF)
WinActivate($handle)
$control = ControlGetHandle($handle,"","[Name:groupBox6]")
ConsoleWrite(_Now() & " "& "Screen capture Control handle: " & $control & @CRLF)
;_ScreenCapture_Capture("D:\abc.jpg", ,,,)
_ScreenCapture_CaptureWnd($path & "\AutoIt.jpg", $control)
EndIf
EndFunc ;无论焦点在哪儿,都回归到包含 EvaluationType 行
Func init($handle)
$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")
ConsoleWrite(_Now()& " "& $text & @CRLF)
$text2 = $text
While StringInStr($text, "EvaluationType =") =
ConsoleWrite(_Now()& " "& $text & @CRLF)
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
ConsoleWrite(_Now()& " "& $text & @CRLF)
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)
Dim $hid
if FileExists($filepath) Then
$matches = StringRegExp($filepath, "\w{4}-\w{4}-\w{4}-\w{4}-\w{4}", , )
If IsArray($matches) Then
$hid = $matches[]
Return $hid
EndIf FileChangeDir($filepath)
$search = FileFindFirstFile("*.txt")
; 检查搜索是否成功
If $search = - Then
Return "No HID .txt file found in the path"
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[]
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[]
ExitLoop
EndIf
$hid = ""
WEnd
FileClose($file2)
WEnd
; 关闭搜索句柄
FileClose($search)
Else
Return "File path is not correct"
EndIf
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
MsgBox(, "Create license error", "Please check the hardware ID or Expire Date format")
Else
$handle = WinGetHandle(".NET Reactor")
if $handle="" then return
ConsoleWrite(_Now() & " "& "Set hardware ID Window handle: " & $handle & @CRLF)
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)
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)
ControlSend($handle,"","", "{up 2}{enter}{up 2}")
Else
collapse($handle)
init($handle)
EndIf
EndIf
EndFunc ;保存 License
Func save_license($path)
if FileExists($path)= or StringInStr($path,"\")= Then
MsgBox(, "Path Error", "Please input correct Path info!")
Else
$handle = WinGetHandle(".NET Reactor")
if $handle="" then return
ConsoleWrite(_Now() & " "& "Save License win handle: " & $handle & @CRLF)
WinActivate($handle) $control_handle = ControlGetHandle($handle,"","[Name:button1]")
ConsoleWrite(_Now() & " "& "Save License Create License button: " & $handle & @CRLF)
ControlClick($handle,"",$control_handle) $check = WinWaitActive("Save License As..")
if $check = Then
ConsoleWrite(_Now() & " " & "Save License As pop up window failed" & @CRLF)
Return
EndIf
$save_window_handle = WinGetHandle("Save License As..")
ConsoleWrite(_Now() & " "& "Save License popup window handle: " & $save_window_handle & @CRLF) $save_input_control = ControlGetHandle($save_window_handle,"","Edit1")
ConsoleWrite(_Now() & " "& "Save License input field handle: " & $save_input_control & @CRLF) ControlSetText($save_window_handle,"",$save_input_control,$path & "\SageTouch.License")
$save_button_handle = ControlGetHandle($save_window_handle,"","Button1")
ConsoleWrite(_Now() & " "& "Save License Save button: " & $save_button_handle & @CRLF) ControlClick($save_window_handle,"",$save_button_handle)
if WinWait("确认另存为","",)<> Then
$popup_handle = WinGetHandle("确认另存为")
WinWaitActive($popup_handle)
ControlClick($popup_handle,"", "Button1")
EndIf
If WinWait("All Done", "", ) <> Then
$popup_handle = WinGetHandle("All Done")
WinWaitActive($popup_handle)
ControlClick($popup_handle,"", "Button1")
EndIf EndIf
;获取窗口句柄
EndFunc ;检查 License 是否是正确的
Func exam_license($path)
If FileExists($path & "\SageTouch.License")= or StringInStr($path,"\")= Then
MsgBox(, "Exam license","Can not find license to exam")
Else
$handle = WinGetHandle(".NET Reactor")
if $handle="" then return
WinActivate($handle)
SendKeepActive($handle)
$handle2 = ControlGetHandle($handle, "", "[NAME:menuStrip1]")
if $handle2 = "" then return
ConsoleWrite(_Now() & " " & "Get menu handle" & $handle2 & @CRLF)
ControlSend($handle, "","","{ALT}{Tab 2}{Enter}{Down}{Enter}")
$check = WinWaitActive("License Examiner", "", )
if $check = Then
ConsoleWrite(_Now() & " " & "License Examiner pop up window failed" & @CRLF)
Return
EndIf
$license_exam_handle = WinGetHandle("License Examiner")
ConsoleWrite(_Now() & " "& "License examiner window handle: " & $license_exam_handle & @CRLF) $open_license_handle = ControlGetHandle($license_exam_handle,"","[Name:button2]")
ConsoleWrite(_now() & " Open License button handle: "&$open_license_handle & @CRLF)
ControlClick($license_exam_handle,"",$open_license_handle) $check = WinWaitActive("Please Select License File", "", )
if $check = Then
ConsoleWrite(_Now() & " " & "Select License File pop up window failed" & @CRLF)
Return
EndIf $select_license_handle = WinGetHandle("Please Select License File")
ConsoleWrite(_Now()& " "& "Select License File window handle: " & $select_license_handle & @CRLF) $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)
EndIf
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) ;$display_HID = GUICtrlCreateButton("Display HID", , , , )
$exam_License = GUICtrlCreateButton("Exam License", , , , )
$Create_License = GUICtrlCreateButton("Create License", , , , )
$Save_License = GUICtrlCreateButton("Save License", , , , ) GUISetState()
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自动化实现。(七)
版本六中存在一个显著问题是: 当exe文件生存之后,运行的时候,通过consoleWrite函数打印出来的数据是无法展示出来的.这就存在一个问题:当运行失败的时候,我还是看不到任何log信息. 于是, ...
- AutoIt 软件自动化操作
AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作. 它利用模拟键盘按键,鼠标移动和窗口/控件的组合来实现 ...
- AutoIt脚本在做自动化操作的时候,如何进行错误捕获?
我的自动化脚本在运行的时候,会生成一个界面,点击该页面上的按钮能够进行自动化操作. 经常遇到的一个问题是: 脚本运行一半,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是一种全新的基础设施管理方式,是一个服务器基础架构集中 ...
随机推荐
- C# PropertyGrid控件应用心得 【转】
源文 : http://blog.csdn.net/luyifeiniu/article/details/5426960 c#stringattributesobjectmicrosoftclass ...
- 电话号码 【trie树】
电话号码 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描写叙述 给你一些电话号码,请推断它们是否是一致的,即是否有某个电话是还有一个电话的前缀. 比方: Emerg ...
- Swift----编程语言语法
1 简单介绍 今天凌晨Apple刚刚公布了Swift编程语言,本文从其公布的书籍<The Swift Programming Language>中摘录和提取而成.希望对各位的iOS&a ...
- 矩形嵌套-记忆化搜索(dp动态规划)
矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 有n个矩形,每个矩形能够用a,b来描写叙述,表示长和宽. 矩形X(a,b)能够嵌套在矩形Y(c,d)中当且仅 ...
- Django知识梳理
请求周期: url > 路由 > 函数或类 > 返回字符串或模板语言 Form 表单提交: 先处理模板语言再讲HTML发出去 提交 > url > 函数或类中的方法 — ...
- Ubuntu 16.04 引导修复(Boot Repair)----lianwang----anzhuang windows hou(双系统修复一)
2016-01-26 20:54 12548人阅读 评论(1) 收藏 举报 分类: =======学习心得=======(23) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] ...
- Android Studio 工程的 .gitignore
新建一个 Android Studio 工程时会默认建立两个 .gitignore 文件 .gitignore *.iml .gradle /local.properties /.idea/works ...
- tomcat 7安装
JAVA环境安装 1.下载包 http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin 2.安装 jdk-6u45 ...
- 在mac下搭建Apacheserver
Apache作为最流行的Webserver端软件之中的一个.它的长处与地位不言而喻.以下介绍下在mac下搭建Apacheserver的步骤: (1)"前往" –>" ...
- 监控hadoop任务结果shell脚本
需求:每日hadoop结果文件中,找出数据不完整的日期和没有跑出数据的日期,重新进行跑hadoop任务 分析:在result/目录生成的文件中数据有2个特点 第一:日期有,但是数据不完整 第二:日期对 ...