版本六中存在一个显著问题是:

当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,"\")=0 Then_GUICtrlListBox_AddString($hListBox, _Now() & " " & "Failed to Save Screen Capture Picture: Path is not correct")returnEndIf$handle = WinGetHandle(".NET Reactor")if $handle="" then_GUICtrlListBox_AddString($hListBox, _Now() & " " & "Failed to Screen Capture: can not get .NET Reactor window handle")returnEndIf_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")returnEndIf_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 = $textWhile StringInStr($text, "EvaluationType =") = 0ControlSend($handle,"","", "{UP}")$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")If $text = $text2 And $text2 = "False" ThenControlSend($handle,"","", "{Down}")ExitLoopEndIfWEnd
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 <> $text2If StringInStr($text,$text2) <> 0 ThenControlSend($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 = $text2ControlSend($handle,"","", "{Down}")$text2 = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")EndIfWEnd
EndFunc;Display the HID in text field automatic
Func GetHid($filepath)IF Not FileExists($filepath) or StringInStr($filepath,"\")=0 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get HID: File path is not correct")Return ""EndIfDim $hid$matches = StringRegExp($filepath, "\w{4}-\w{4}-\w{4}-\w{4}-\w{4}", 1, 1)If IsArray($matches) Then$hid = $matches[0]_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get HID from file path")Return $hidEndIfFileChangeDir($filepath)$search = FileFindFirstFile("*.txt"); 检查搜索是否成功If $search = -1 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to found HID from .txt file in the path")ReturnEndIfWhile 1$file = FileFindNextFile($search)If @error ThenExitLoopEndIf$matches = StringRegExp($file, "\w{4}-\w{4}-\w{4}-\w{4}-\w{4}", 3, 1)If IsArray($matches) Then$hid = $matches[0]_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get HID from Text file name")ExitLoopEndIfLocal $file2 = FileOpen($file)If $file2 = -1 ThenExitLoopEndIfWhile 1Local $line = FileReadLine($file2)If @error = -1 Then ExitLoop$matches = StringRegExp($line, "\w{4}-\w{4}-\w{4}-\w{4}-\w{4}", 3, 1)If IsArray($matches) Then$hid = $matches[0]_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get HID from txt file in file path")ExitLoopEndIf$hid = ""WEndFileClose($file2)WEnd; 关闭搜索句柄FileClose($search)Return $hid
EndFunc;设置 Hardware ID
Func set_hardwareID($hardware_id, $date)if StringLen($hardware_id) <> 24 or StringInStr($hardware_id, "-")=0 or StringInStr($date,"/")=0 or StringLen($date)<8 Or  StringLen($date)>19 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to set HID: hardware ID or Expire Date format wrong")returnEndIf$handle = WinGetHandle(".NET Reactor")if $handle="" then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get .NET Reactor handle")ReturnEndIf_GUICtrlListBox_AddString($hListBox, _Now() & " "& "get .NET Reactor handle")WinActivate($handle)$tab_control = ControlGetHandle($handle,"", "[name:tabControl2]")_GUICtrlTab_ClickTab($tab_control, 2)SendKeepActive($handle)ControlSend($handle,"","", "{tab 4}")$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")While StringInStr($text, "RSAKeyValue") <>0ControlSend($handle,"","", "{tab 4}")$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")WEndinit($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,"/") <>0 ThenControlSetText($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}")Elsecollapse($handle)init($handle)EndIf;输入Hardware IDControlSend($handle,"","", "{down 2}{enter}{down 2}")$text = ControlGetText($handle,"","[class:WindowsForms10.EDIT.app.0.1f550a4_r15_ad1]")If StringInStr($text,"-") <>0 ThenControlSetText($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}")Elsecollapse($handle)init($handle)EndIf
EndFunc;保存 License
Func save_license($path)if FileExists($path)= 0 or StringInStr($path,"\")=0 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Save License: Path is not correct")ReturnEndIf$handle = WinGetHandle(".NET Reactor")if $handle="" then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Save License: Failed to Get .NET reactor handle")ReturnEndIf_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 = 0 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to save license: Read pop up window failed")ReturnEndIf$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("确认另存为","",1)<>0 Then$popup_handle = WinGetHandle("确认另存为")WinWaitActive($popup_handle)ControlClick($popup_handle,"", "Button1")WinWaitClose($popup_handle, "", "Button1")EndIfIf WinWait("All Done", "", 1) <> 0 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")=0 or StringInStr($path,"\")=0 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to find Sagetouch.License in the path")ReturnEndIf$handle = WinGetHandle(".NET Reactor")if $handle="" then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Exam license, not get .Net Reactor win handle")ReturnEndIfWinActivate($handle)SendKeepActive($handle)$handle2 = ControlGetHandle($handle, "", "[NAME:menuStrip1]")if $handle2 = "" then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get Exam License Menu handle failed")ReturnEndIf_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Get menu handle")ControlSend($handle, "","","{ALT}{Tab 2}{Enter}{Down}{Enter}")$check = WinWaitActive("License Examiner", "", 5)if $check = 0 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to get exam license Pop up")ReturnEndIf$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", "", 5)if $check = 0 Then_GUICtrlListBox_AddString($hListBox, _Now() & " "& "Failed to Select License File pop up window")ReturnEndIf$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", 550, 450)GUICtrlCreateLabel("Hardware ID", 30, 30, 250, 20)
$hardware_id = GUICtrlCreateLabel("XXXX-XXXX-XXXX-XXXX-XXXX", 30, 50, 250, 20)GUICtrlCreateLabel("Expire Date", 300, 30, 200, 20)
$tTime = _Date_Time_GetSystemTime()
$aTime = _Date_Time_SystemTimeToArray($tTime)
$date = $aTime[2] & "/"  & $aTime[0] & "/" & "1"
$date2 = _DateAdd("M", 2, $date)
$date = GUICtrlCreateInput($date2, 300, 50, 200, 20)GUICtrlCreateLabel("License File Path", 30, 100, 120, 20)
$path = GUICtrlCreateInput("", 30, 120, 472, 20)
GUICtrlSetState(-1, $GUI_FOCUS)$exam_License = GUICtrlCreateButton("Exam License", 30, 180, 120, 20)
$Create_License = GUICtrlCreateButton("Create License", 180, 180, 120, 20)
$Save_License = GUICtrlCreateButton("Save License", 330, 180, 120, 20)Global $hListBox = GUICtrlCreateList("Create License Log Info", 5, 230, 540, 190, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_DISABLENOSCROLL, $LBS_NOTIFY, $WS_HSCROLL))GUISetState()
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_UpdateHScroll($hListBox)
_GUICtrlListBox_EndUpdate($hListBox)While 1$msg = GUIGetMsg()SelectCase $msg = $GUI_EVENT_CLOSEExitCase $msg = $Create_License$hid = GetHid(GUICtrlRead($path))GUICtrlSetData($hardware_id, $hid)GUISetState()set_hardwareID(GUICtrlRead($hardware_id), GUICtrlRead($date))Case $msg = $Save_Licensesave_license(GUICtrlRead($path))screen_capture(GUICtrlRead($path))Case $msg = $exam_Licenseexam_license(GUICtrlRead($path))EndSelect
Wend

界面如下:

转载于:https://www.cnblogs.com/autotest/p/3414095.html

AutoIT:界面与自动化操作结合来简化日常劳动: .Net Reactor验证License,设置License,创建License,截图AutoIt自动化实现。(七)...相关推荐

  1. AutoIt脚本在做自动化操作的时候,如何进行错误捕获?

    我的自动化脚本在运行的时候,会生成一个界面,点击该页面上的按钮能够进行自动化操作. 经常遇到的一个问题是: 脚本运行一半,GUI程序出现了异常情况,这个时候,再次点击生成的界面上的按钮,不会有任何反应 ...

  2. AutoHotkey/AutoIt自动化操作轻松入门系列

    转自:http://www.autohotkey.net/~yonken/article/tutorial1.htm 前言:据我了解需要编写AutoHotkey/AutoIt脚本来实现自动化操作的用户 ...

  3. 解放双手|利用 PyAutoGUI 快速构建自动化操作脚本

    一.背景 我们经常遇到需要进行大量重复操作的时候,比如网页上填表,对 web 版本 OA 进行操作,自动化测试或者给新系统首次添加数据等.这些操作的特点往往是:数据同构,大多是已经有了的结构化数据:操 ...

  4. python windows记事本_pywinauto自动化操作记事本

    一.什么是pywinauto Pywinauto是基于Python开发的,用于操作Windows标准图形界面的自动化测试的脚本模块. 二.pywinauto可以用来做什么 1.可以应用在程序中,来解决 ...

  5. pptx库ppt演示 python_Python自动化操作PPT看这一篇就够了

    作者:超级大洋葱806 https://tangxing.blog.csdn.net/article/details/109568830 1.PPT自动化能干什么?有什么优势? 它可以代替你自动制作P ...

  6. windows自动化操作——程序员必备

    windows下自动化脚本,提高生产力必备. 不定期更新 目录 1 bat脚本 1.1 映射网络驱动器 1.2 开机自启动 1.3 自动添加环境变量脚本 2 自动化软件 2.1 mobaxterm的宏 ...

  7. 使用selenium自动化操作浏览器

    欢迎关注"生信修炼手册"! selenium是一个浏览器自动测试工具,通过驱动程序来自动化操作对应的浏览器,包括了打开浏览器窗口,定位元素,点击按钮,上传文件等操作,支持以下多款主 ...

  8. 【开源库分享】雷电模拟器自动化操作库 C#版本

    LD.CORE 雷电模拟器自动化操作库 Github 功能简介 雷电模拟器管理操作 雷电模拟器ADB命令操作:按键,点击,滑动,输入等 雷电模拟器界面UI XML 文件分析 雷电模拟器地理位置切换 雷 ...

  9. au3 ui html,AutoIt UI及常用操作

    @[TOC] [还有视频讲解在我的B站-宝哥chbxw](https://www.bilibili.com/video/BV1Ga4y1Y7C4/), 希望大家可以支持一下,谢谢. # 前言之分层 A ...

  10. 分享个变形金刚地球之战挂机脚本,自动化操作

    分享个变形金刚地球之战挂机脚本,自动化操作 变形金刚地球之战这个游戏太耗时间了,这里给大家介绍一个节省时间精力自动打活动.资源的工具. 变形金刚地球之战辅助功能: 1.自动选择打资源.打活动 2.勾选 ...

最新文章

  1. C/C++利用三元组实现稀疏矩阵运算
  2. type=file的未选择任何文件修改_PDF文件怎样输入到CAD图纸中?懂得这个功能可以快速实现...
  3. java 搭建企业应用框架_溯源微服务开发体系:一位Java开发者的转型思考
  4. python qq机器人框架有哪些_使用Python的Tornado框架实现一个简单的WebQQ机器人
  5. React基础语法学习
  6. stl向量最大值_C ++ STL中向量的最小和最大元素
  7. 【Servlet】Servlet生命周期
  8. springboot整合rabbitMQ-路由模型
  9. python压缩和读取.tar.bz2格式的压缩包
  10. 关闭tensorflow运行时的警告信息1
  11. 《转》通往高级工程师的道路
  12. html中script标签的使用方法
  13. C++MFC控件属性的解释
  14. 环信即时通信聊天理解
  15. WIN10系统连接蓝牙音箱,显示已连接但无声音
  16. 程序员到底是吃青春饭还要奋斗?那么行业前景又如何?
  17. Wox自制主题 - Material
  18. uniapp引入字体图标库
  19. 阿里的黄金时代|一点财经
  20. 【电气设计】理论知识学习(持续更新中...)

热门文章

  1. zabbix为啥持续报警
  2. [苹果开发者账号]06 转让开发者账号后,开发者年费自动续费问题
  3. JAVA基础-多线程中锁机制
  4. python:maya 一个人性化的时间处理库
  5. css骨架图,【CSS】骨架屏 Skeleton 效果
  6. 2021年危险化学品经营单位安全管理人员最新解析及危险化学品经营单位安全管理人员模拟试题
  7. linux渗透后清除日志,后渗透阶段清理痕迹方式总结
  8. 使用java压缩文件成zip——三种方式压缩文件速度对比
  9. Drools实战-个人所得税计算器
  10. java m个苹果n个篮子_m个苹果放在n个盘子中有多少种结果