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")