基于AutoIt3的打印机安装
Posted mjy2wxy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于AutoIt3的打印机安装相关的知识,希望对你有一定的参考价值。
#Region ;**** 编译指令由 AutoIt3Wrapper 选项编译窗口创建 **** #AutoIt3Wrapper_Icon=favicon.ico #AutoIt3Wrapper_Compile_Both=y #EndRegion ;**** 编译指令由 AutoIt3Wrapper 选项编译窗口创建 **** #cs ---------------------------------------------------------------------------- Version: 1.0 Author: MaJunyi #ce ---------------------------------------------------------------------------- #include <StringConstants.au3> ; for 正则表达式 #include <GUIConstantsEx.au3> ; for GUI #include <WinAPIShellEx.au3>; for winShell #include <InetConstants.au3>; for download ; CPL文件,又叫控制面板项(Control Panel Item),多保存于系统安装目录的system32文件夹下,它们分别对应着控制面板中的项目 ; 优化: ; 1. 可以添加一号楼绝大部分打印机 ; 2. 可添加二号楼3.4.5楼打印机 ; 3. 可进入---控制面板\所有控制面板项\设备和打印机(control printers) ; 不足: ; 1. 暂未添加用户名至网络打印机 ; 2. 打印楼层单一 $headlabel = "打印机添加和安装" GUICreate($headlabel, 400, 280) $okbutton = GUICtrlCreateButton("确认安装", 30, 200, 70, 30) $localPrintBtn = GUICtrlCreateButton("已安装的打印机", 120, 200, 100, 30) $printDriverBtn = GUICtrlCreateButton("打印机驱动", 240, 200, 100, 30) $guiTop = 20 GUICtrlCreateLabel("请选择您的位置:", 30, $guiTop) $guiTop+=20 Local $idRadio1 = GUICtrlCreateRadio("一号楼", 40, $guiTop) $guiTop1 = $guiTop $guiTop+=20 Local $idRadio231 = GUICtrlCreateRadio("二号楼-3楼车间", 40, $guiTop) $guiTop231 = $guiTop $guiTop+=20 Local $idRadio232 = GUICtrlCreateRadio("二号楼-3楼办公区", 40, $guiTop) $guiTop232 = $guiTop $guiTop+=20 Local $idRadio241 = GUICtrlCreateRadio("二号楼-4楼车间", 40, $guiTop) $guiTop241 = $guiTop $guiTop+=20 Local $idRadio242 = GUICtrlCreateRadio("二号楼-4楼办公区", 40, $guiTop) $guiTop242 = $guiTop $guiTop+=20 Local $idRadio25 = GUICtrlCreateRadio("二号楼-5楼", 40, $guiTop) $guiTop25 = $guiTop ; 信息化打印机 ; 172.16.51.233 ; net use \\172.16.51.233\TOSHIBA Universal Printer 2 ; 检测是否云桌面 isCloudOrNot() GUISetState(@SW_SHOW) Sleep(200) ; 下载驱动 $printDriverIp = "\\192.168.2.174" ; GUICtrlCreateLabel("连接及下载打印机驱动,从" & $printDriverIp, 30, 30) ; Sleep(200) ; $openNetPrint = _WinAPI_ShellExecute ($printDriverIp) ; GUICtrlCreateLabel("尝试连接打印机(会显示打印机任务,需去打印机刷卡才会打印)", 30, 50) ; Sleep(200) ; GUICtrlCreateLabel("打开 " & $ctrlPrintShow, 30, 70) ; net use \\192.168.2.174\eFollow_Printer /user:HEM100 ; Script Start - Add your code below here ; 检测是否云桌面 ; 云桌面: eip.hxgroup.com 172.30.17.248 Func isCloudOrNot() Local $string0 = StringRegExp(@IPAddress1, ‘(172.30.)(\d+.\d+)‘, $STR_REGEXPARRAYMATCH) If Not @error Then $isYun = 0 MsgBox(0,‘‘, ‘您是尊贵的云桌面用户,不能添加打印机‘) Else If @error==1 Then ; Return "您不是云桌面用户" Return "正在为您添加打印机" Else Return "请联系开发人员,错误代码:" & @error ; 2: 正则表达式错误, 数组无效. EndIf EndIf EndFunc Global $chooseRadio Global $driverIp Global $driverIpFile $LianJieTipsLeft = 200 While 1 $msg = GUIGetMsg() Select Case $msg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED $chooseRadio = 1 ; MsgBox($MB_SYSTEMMODAL, ‘Info‘, $chooseRadio) GUICtrlCreateLabel("驱动服务器" & canConnectOrNot(‘192.168.2.174‘), $LianJieTipsLeft, $guiTop1+5) Case $msg = $idRadio231 And BitAND(GUICtrlRead($idRadio231), $GUI_CHECKED) = $GUI_CHECKED $chooseRadio = 231 ;ok $driverIpFile = "\UNIV_driver\Setup.exe" $driverIp = "\\172.16.11.234" GUICtrlCreateLabel("驱动服务器" & canConnectOrNot(‘172.16.11.234‘), $LianJieTipsLeft, $guiTop231+5) Case $msg = $idRadio232 And BitAND(GUICtrlRead($idRadio232), $GUI_CHECKED) = $GUI_CHECKED $chooseRadio = 232 ;ok $driverIpFile = "\UNIV_driver\essetup.exe" $driverIp = "\\172.16.11.220" GUICtrlCreateLabel("驱动服务器" & canConnectOrNot(‘172.16.11.220‘), $LianJieTipsLeft, $guiTop232+5) Case $msg = $idRadio241 And BitAND(GUICtrlRead($idRadio241), $GUI_CHECKED) = $GUI_CHECKED $chooseRadio = 241 ;ok $driverIpFile = "\UNIV_driver\Setup.exe" $driverIp = "\\172.16.242.245" GUICtrlCreateLabel("驱动服务器" & canConnectOrNot(‘172.16.242.245‘), $LianJieTipsLeft, $guiTop241+5) Case $msg = $idRadio242 And BitAND(GUICtrlRead($idRadio242), $GUI_CHECKED) = $GUI_CHECKED $chooseRadio = 242 ;ok $driverIpFile = "\UNIV_driver\essetup.exe" $driverIp = "\\172.16.11.228" GUICtrlCreateLabel("驱动服务器" & canConnectOrNot(‘172.16.11.228‘), $LianJieTipsLeft, $guiTop242+5) Case $msg = $idRadio25 And BitAND(GUICtrlRead($idRadio25), $GUI_CHECKED) = $GUI_CHECKED $chooseRadio = 25 ;ok $driverIpFile = "\UNIV_driver\Setup.exe" $driverIp = "\\172.16.241.172" GUICtrlCreateLabel("驱动服务器" & canConnectOrNot(‘172.16.241.172‘), $LianJieTipsLeft, $guiTop25+5) Case $msg = $okbutton If $chooseRadio == 1 Then MsgBox(0,"","尝试连接打印机(会显示打印机任务,需去打印机刷卡才会打印)") $openNetPrintFile = _WinAPI_ShellExecute ("\\192.168.2.174\eFollow_Printer") ElseIf $chooseRadio > 1 Then $mLink = $driverIp & $driverIpFile $openNetPrintFile = _WinAPI_ShellExecute ($mLink) ; downloadFile(‘printDriver.exe‘, "file://172.16.11.234/UNIV_driver/Setup.exe") Else MsgBox(0,"","请选择您的位置") EndIf ; ExitLoop Case $msg = $localPrintBtn ; $ctrlPrintShow = "控制面板\硬件和声音\设备和打印机" ; $openPrintDir = _WinAPI_ShellExecute("::2227A280-3AEA-1069-A2DE-08002B30309D") $openPrintDir = Run(@SystemDir & "\control.exe printers") Case $msg = $printDriverBtn $openNetPrintFile = _WinAPI_ShellExecute ("\\192.168.2.36\常用软件\打印机驱动") Case $msg = $GUI_EVENT_CLOSE ; 关闭对话框事件 ExitLoop EndSelect WEnd ; 检测是否能连接上指定IP Func canConnectOrNot($testIP) ; Ping网站,超时时间为 1000 毫秒. Local $iPing = Ping($testIP, 1000) If $iPing Then Return "连接成功" Else ;当函数执行失败时(返回 0)@error 包含数值的具体信息: If @error == 1 Then Return "离线" ElseIf @error == 2 Then Return "无法到达" ElseIf @error == 3 Then Return "目标错误" ElseIf @error == 4 Then Return "其他错误-连接超时" Else Return "连接超时" EndIf EndIf EndFunc Func downloadFile($mFile, $link) ProgressOn("下载新版本:"&$mFile, "正在更新版本,请稍候...", "0%") Local $i = 0 Do Sleep(100) ;$i = $i+1 $i = Round(FileGetSize($mFile)/1024/10) ; Update the progress value of the progress bar window. ProgressSet($i, $i & "%") Until InetGetInfo($link, $INET_DOWNLOADCOMPLETE) ; Set the "subtext" and "maintext" of the progress bar window. ProgressSet(100, "更新完成", "Complete") Sleep(1000) ; Close the progress window. ProgressOff() EndFunc
以上是关于基于AutoIt3的打印机安装的主要内容,如果未能解决你的问题,请参考以下文章