poohbbs 发表于 2009-6-27 23:27:39

一键安装打印机

代码由论坛里他人代码更改而成ProgressOn("处理中,请稍候...BY:风の曙光", "", "", -1, -1, 2 + 16)
        ProgressSet(0, "已完成 0%", "正在创建变量...")
        Sleep(300)
        $SetPrinterIP = "192.168.0.2"                                     ;定义打印机IP地址
        $SetPrinterName = "五楼东厅hp1160打印机"                        ;定义打印机名称"任意更改"
        $drvpatch = "\\192.168.0.18\drv\hp\onekey\LJP1160\hpc1160b.inf"   ;打印机驱动所在位置
        $SetPrinterDriver= "hp LaserJet 1160 PCL 5e"               ;定义打印机驱动选择
        $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(30, "已完成 30%", "正在检测端口是否存在...")
        Sleep(300)
        If $x = 0 Then
                ProgressSet(40, "已完成 40%", "端口不存在,在正在创建端口...")
                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(60, "已完成 60%", "端口不存在,正在创建端口...")
                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(70, "已完成 70%", "正在停止打印服务...")
                RunWait(@ComSpec & " /c sc stop spooler", "", @SW_HIDE)
                ProgressSet(75, "已完成 80%", "正在启动打印服务...")
                RunWait(@ComSpec & " /c sc start spooler", "", @SW_HIDE)
                ProgressSet(80, "已完成 80%", "准备添加打印机...")
                Sleep(300)
        Else
                ProgressSet(60, "已完成 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")

xlcwxl 发表于 2009-7-2 09:50:42

很不错哦
谢谢分享

74554128 发表于 2009-7-4 18:00:28

:face (17):

efan5555 发表于 2009-7-23 22:25:15

太棒了,谢谢!

xiaoluoit 发表于 2009-7-25 17:09:09

好东西学习了!

gnlee123 发表于 2009-11-17 23:40:52

正好需要用到,太感謝了.:face (20):

gnlee123 发表于 2009-11-17 23:41:20

正好需要用到,太感謝了.:face (20):

zhusheng8701 发表于 2009-12-11 19:20:05

:face (33):路过、、、
收藏备用

qzit0595 发表于 2009-12-12 12:47:48

:face (8):

boyhong 发表于 2010-4-19 12:44:16

感谢分享,,,,正需要~

6678720 发表于 2010-10-5 14:26:39

喔,谢谢楼主分享,好强的Au3

aux649350702 发表于 2011-2-22 08:14:45

好东西,呵呵

tssheng 发表于 2011-3-2 18:54:04

收藏一下。。。。

wa18239 发表于 2011-3-11 14:59:45

收下了,谢谢!!经测试可用!

lzhzlh 发表于 2011-3-29 17:45:25

支持下,谢谢分享
页: [1] 2 3
查看完整版本: 一键安装打印机