首页 > 代码库 > Autoit3 自动添加打印机
Autoit3 自动添加打印机
从网上找的代码进行了修改!!如下
ProgressOn("处理中,请稍候...BY:天祈", "", "", -1, -1, 2 + 16) ProgressSet(0, "已完成 0%", "正在创建变量...") $fileURL=@ScriptDir & "userprint.ini" ;MsgBox(0, "", $fileURL) If (FileExists($fileURL)==0)Then IniWrite($fileURL,"print","SetPrinterIP","定义打印机IP地址") IniWrite($fileURL,"print","SetPrinterName","定义打印机名称可任意更改") IniWrite($fileURL,"WIN7_32","drvpatch","打印机驱动所在位置") IniWrite($fileURL,"WIN7_32","SetPrinterDriver","定义打印机驱动选择") IniWrite($fileURL,"WIN7_64","drvpatch","") IniWrite($fileURL,"WIN7_64","SetPrinterDriver","") IniWrite($fileURL,"WIN_XP","drvpatch","") IniWrite($fileURL,"WIN_XP","SetPrinterDriver","") Exit EndIf Sleep(300) $SetPrinterIP = IniRead($fileURL,"print","SetPrinterIP","") ;定义打印机IP地址 $SetPrinterName = IniRead($fileURL,"print","SetPrinterName","") ;定义打印机名称"任意更改" If @OSVersion="WIN_7" Then If @OSArch="X86" Then $drvpatch = IniRead($fileURL,"WIN7_32","drvpatch","") ;打印机驱动所在位置 $SetPrinterDriver= IniRead($fileURL,"WIN7_32","SetPrinterDriver","") ;定义打印机驱动选择 Else $drvpatch = IniRead($fileURL,"WIN7_64","drvpatch","") ;打印机驱动所在位置 $SetPrinterDriver= IniRead($fileURL,"WIN7_64","SetPrinterDriver","") ;定义打印机驱动选择 EndIf EndIf If @OSVersion="WIN_XP" Then $drvpatch = IniRead($fileURL,"WIN_XP","drvpatch","") ;打印机驱动所在位置 $SetPrinterDriver= IniRead($fileURL,"WIN_XP","SetPrinterDriver","") ;定义打印机驱动选择 EndIf $Patch = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\" $Patch001 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\" $i = 1 $s = "" ProgressSet(10, "已完成 10%", "正在检测端口信息...") Sleep(300) Do $Var = RegEnumKey($Patch, $i) $i = $i + 1 $s = $s & $Var& "/" ProgressSet(10 + $i, "已完成 " & 10 + $i& "%", "正在检测端口信息...") Sleep(300) Until StringLeft($Var, 3) <> "IP_" $x = StringInStr($s, "IP_" & $SetPrinterIP) $PortName = "IP_" & $SetPrinterIP $NewPatch = $Patch & $PortName $NewPatch001 = $Patch001 & $PortName ProgressSet(20, "已完成 20%", "正在检测端口是否存在...") Sleep(300) If $x = 0 Then ProgressSet(30, "已完成 30%", "端口不存在,在正在创建端口...") Sleep(300) RegWrite($NewPatch) RegWrite($NewPatch, "Protocol", "REG_DWORD", "00000001") RegWrite($NewPatch, "Version", "REG_DWORD", "00000001") RegWrite($NewPatch, "HostName", "REG_SZ", "") RegWrite($NewPatch, "IPAddress", "REG_SZ", $SetPrinterIP) RegWrite($NewPatch, "HWAddress", "REG_SZ", "") RegWrite($NewPatch, "PortNumber", "REG_DWORD", "9100") RegWrite($NewPatch, "SNMP Community", "REG_SZ", "public") RegWrite($NewPatch, "SNMP Enabled", "REG_DWORD", "00000001") RegWrite($NewPatch, "SNMP Index", "REG_DWORD", "00000001") ProgressSet(50, "已完成 50%", "端口不存在,正在创建端口...") Sleep(300) RegWrite($NewPatch001) RegWrite($NewPatch001, "Protocol", "REG_DWORD", "00000001") RegWrite($NewPatch001, "Version", "REG_DWORD", "00000001") RegWrite($NewPatch001, "HostName", "REG_SZ", "") RegWrite($NewPatch001, "IPAddress", "REG_SZ", $SetPrinterIP) RegWrite($NewPatch001, "HWAddress", "REG_SZ", "") RegWrite($NewPatch001, "PortNumber", "REG_DWORD", "9100") RegWrite($NewPatch001, "SNMP Community", "REG_SZ", "public") RegWrite($NewPatch001, "SNMP Enabled", "REG_DWORD", "00000001") RegWrite($NewPatch001, "SNMP Index", "REG_DWORD", "00000001") ProgressSet(65, "已完成 65%", "正在启动打印服务...") ;RunWait(@ComSpec& " /c sc start spooler", "", @SW_HIDE) $PIDcopy=Run(@ComSpec& " /c sc start spooler", "", @SW_HIDE) ProcessWaitClose($PIDcopy) ProgressSet(70, "已完成 70%", "准备添加打印机...") Sleep(300) Else ProgressSet(80, "已完成 60%", "端口已经存在,准备添加打印机...") Sleep(300) EndIf ProgressSet(90, "已完成 90%", "正在添加打印机...") RunWait(@ComSpec& ‘ /c rundll32 printui.dll,PrintUIEntry /if /b "‘ & $SetPrinterName& ‘" /f ‘& $drvpatch&‘ /r "‘ & $PortName& ‘" /m "‘ & $SetPrinterDriver& ‘"‘, "", @SW_HIDE) ;MsgBox (0,"注意","添加打印机完毕!") Sleep(300) ProgressSet(100, "已完成 100%", "添加打印机完毕!") ProgressOff() MsgBox(0, "", "添加完毕!") Run("RUNDLL32 SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder")
Autoit3 自动添加打印机
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。