先吐槽下科密A1考勤,软件其实是自带有自动同步的功能的,但是设置后软件在同步的时间点后竟然直接弹出错误框,寻求科密技术支持,人家直接回复A1考勤只能手动同步,不能自动同步。(人家自动同步的版本是需要另外收费的)

接下来是重点,既然寻求技术支持无果,那么就只能自己动手解决了,下面是用AutoIt写的自动同步脚本,放在服务器上,然后根据你的需要设置windows的任务计划即可按照你需要的时间进行自动同步了。

同步考勤记录的AutoIt代码:

#include <File.au3>

Local Const $LogFile = @ScriptDir & "\" & @YEAR & @MON & ".log"
Local Const $IniFile = @ScriptDir & "\app.ini"
Local Const $CM_CLIENT = IniRead($IniFile, "General", "CM_CLIENT", "")

_FileWriteLog($LogFile, "======考勤记录同步开始执行======" )
MainFunc()
_FileWriteLog($LogFile, "======考勤记录同步执行结束======")

Func MainFunc()
   ;获取窗口
   Local $hWndMain = WinGetHandle("[CLASS:CM_CLIENT; TITLE:终端管理]","")
   If @error Then
	  $hWndMain = 0
	  if $CM_CLIENT <> "" Then
		 Run($CM_CLIENT)
		 $hWndMain = WinWait("[CLASS:CM_CLIENT; TITLE:终端管理]", "", 15)
	  EndIf
   EndIf
   If ($hWndMain == 0) Then
	  _FileWriteLog($LogFile, "获取 CM_CLIENT 窗口失败!" )
	  Return
   EndIf
   
   WinActivate($hWndMain)
   WinWaitActive($hWndMain)
   
   ; 切换到 同步 页面
   Local $hWnd  = ControlGetHandle($hWndMain, "[CLASS:TRzBmpButton]","数据采集")
   If @error Then
        _FileWriteLog($LogFile, "获取 数据采集 按钮失败!" )
        return
    EndIf
    ControlClick($hWndMain,"",$hWnd )
    
    Sleep(1000)
   
    ; 同步
    Local $hWnd  = ControlGetHandle($hWndMain, "[CLASS:TBitBtn]","采集(&O)")
    If @error Then
        _FileWriteLog($LogFile, "获取 采集 按钮失败!" )
        return
    EndIf
    ControlClick($hWndMain,"",$hWnd )

    ; 关闭弹出对话框
    Local $hWndDiag = WinWait("[CLASS:#32770; TITLE:终端管理]", "", 900)
     If ($hWndDiag <> 0) Then
        WinActivate($hWndDiag)
        WinWaitActive($hWndDiag)
        Local $text = ControlGetText($hWndDiag, "", "Static2")
        _FileWriteLog($LogFile, $text & " " )
        WinClose($hWndDiag)
        WinWaitClose($hWndDiag)
     EndIf
    
    ; 关闭主窗口
    WinClose($hWndMain)
    
EndFunc

同步时间的AutoIt代码:

#include <File.au3>

Local Const $LogFile = @ScriptDir & "\" & @YEAR & @MON & ".log"
Local Const $IniFile = @ScriptDir & "\app.ini"
Local Const $CM_CLIENT = IniRead($IniFile, "General", "CM_CLIENT", "")

_FileWriteLog($LogFile, "======时间同步开始执行======" )
MainFunc()
_FileWriteLog($LogFile, "======时间同步执行结束======")

Func MainFunc()
   ;获取窗口
   Local $hWndMain = WinGetHandle("[CLASS:CM_CLIENT; TITLE:终端管理]","")
   If @error Then
	  $hWndMain = 0
	  if $CM_CLIENT <> "" Then
		 Run($CM_CLIENT)
		 $hWndMain = WinWait("[CLASS:CM_CLIENT; TITLE:终端管理]", "", 15)
	  EndIf
   EndIf
   If ($hWndMain == 0) Then
	  _FileWriteLog($LogFile, "获取 CM_CLIENT 窗口失败!" )
	  Return
   EndIf
   
   WinActivate($hWndMain)
   
      ; 切换到 设备设置 页面
   Local $hWnd  = ControlGetHandle($hWndMain, "[CLASS:TRzBmpButton]","设备设置")
   If @error Then
        _FileWriteLog($LogFile, "获取 设备设置 按钮失败!" )
        return
    EndIf
    ControlClick($hWndMain,"",$hWnd )
    
    Sleep(1000)

    ;打开设备属性设置窗口
    Local $hWnd  = ControlGetHandle($hWndMain, "[CLASS:TButton]","属性设置(&A)")
    If @error Then
        _FileWriteLog($LogFile, "获取 属性设置 按钮失败!" )
        return
    EndIf
    ControlClick($hWndMain,"",$hWnd )
    
    ;激活设备属性设置窗口
     Local $hWndSub = WinWait("[CLASS:TEquPropertySetFForm; TITLE:设备属性设置]", "", 5)
     WinActivate($hWndSub)
     
     ; 取消获取设置状态
     $hWnd  = ControlGetHandle($hWndSub, "[CLASS:TCheckBox]","获取设备状态")
     ControlClick($hWndSub,"",$hWnd )

    ;单击确认按钮
    $hWnd  = ControlGetHandle($hWndSub, "[CLASS:TBitBtn]","确定(&O)")
    ControlClick($hWndSub,"",$hWnd )
    Local $hWndDiag = WinWait("[CLASS:#32770; TITLE:终端管理]", "", 300)
    If ($hWndDiag <> 0) Then
    WinActivate($hWndDiag)
    WinWaitActive($hWndDiag)
    Local $text = ControlGetText($hWndSub, "", "TMemoExt1")
    $text  = StringReplace($text ,@CRLF," | ")
    $text  = StringReplace($text ,"|  |","|")
    _FileWriteLog($LogFile, $text  & " ")
    Local $text = ControlGetText($hWndDiag, "", "Static2")
    $text  = StringReplace($text ,@CR," | ")
    _FileWriteLog($LogFile, $text  & " ")
    WinClose($hWndDiag)
    WinWaitClose($hWndDiag)
    EndIf

    ; 关闭设备属性窗口
    WinClose($hWndSub)
    WinWaitClose($hWndSub)
    
    ; 关闭主窗口
    WinClose($hWndMain)
    
EndFunc


原文链接地址:https://blog.exsvc.cn/article/autoit-comet-a1-sync.html
转载请注明:转载自 易科博客 ,谢谢!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注