NSIS一键安装网络打印机

为了方便安装打印机,所以特地写了这个脚本。希望对大家有所帮助。

在窗体中创建Droplist,并且读取选择值,来进行后续操作。

点击安装来触发

function OnClickinstall
 SetShellVarContext all
 ${NSD_GetText} $DropList1 $stext
 
 ${if} $stext == "20楼打印机"
 ;===打印机IP地址===
 StrCpy $ipadd '192.168.1.42'
 ;===打印机名称===
 StrCpy $pname 'KONICA MINOLTA 500/420/360VXL'
 ;===驱动程序总文件===
 StrCpy $local "\\172.16.0.5\Software\驱动程序\20楼新打印机驱动\20楼打印机32位驱动\KOBZOJB_.inf"
 ${andIf} ${RunningX64}
 push $local
 StrCpy $local "\\172.16.0.5\Software\驱动程序\20楼新打印机驱动\20楼打印机64位驱动\KOBZOJB_.inf"
 ${endif} 
 
 ${if} $stext == '19楼打印机'
 ;===打印机IP地址===
 StrCpy $ipadd '192.168.8.41' 
 ;===打印机名称===
 StrCpy $pname 'HP Universal Printing PCL 6'
 ;===驱动位置=== 
 StrCpy $local "\\172.16.0.5\Software\驱动程序\19楼新打印机驱动\HP Universal Print Driver\pcl6-x32\hpcu175u.inf"
 ;===驱动程序总文件===
 ${andIf} ${RunningX64}
 push $local
 StrCpy $local "\\172.16.0.5\Software\驱动程序\19楼新打印机驱动\HP Universal Print Driver\pcl6-x64\hpcu175u.inf" 
 ${endif} 
 
 ${if} $stext == '38楼打印机'
 ;===打印机IP地址===
 StrCpy $ipadd '192.168.10.39' 
 ;===打印机名称===
 StrCpy $pname 'KONICA MINOLTA 501/421/361PCL'
 ;===驱动位置=== 
 StrCpy $local "\\192.168.10.10\驱动程序\打印机驱动\打印机安装文件\PCL_Win7_32\Win_x86\KOBZEJ__.inf"
 ;===驱动程序总文件===
 ${andIf} ${RunningX64}
 push $local
 StrCpy $local "\\192.168.10.10\驱动程序\打印机驱动\打印机安装文件\PCL_Win7_64\Win_x64\KOBZEJ__.inf" 
 ${endif} 
 
 ;===添加打印机端口===
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports' "StatusUpdateInterval" "0000000a"
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports' "StatusUpdateEnabled" "00000001"
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports' "LprAckTimeout" "000000b4"
 
 ;===添加具体端口===
 MessageBox MB_ICONINFORMATION|MB_OK '你选择安装的打印机为$stext $\n$\r 该打印机IP地址为$ipadd $\n$\r 驱动程序位置为:$local' 
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "Protocol" "00000001"
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "Version" "00000002"
 WriteRegStr HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "HostName" $ipadd
 WriteRegStr HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "IPAddress" ""
 WriteRegStr HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "HWAddress" ""
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "PortNumber" "9100"
 WriteRegStr HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "SNMP Community" "public"
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "SNMP Enabled" "00000000"
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "SNMP Index" "00000001"
 WriteRegDWORD HKLM 'SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\$ipadd' "PortMonMibPortIndex" "00000000"

 
 ;===重启打印机安装服务===
 nsExec::Exec 'net stop spooler'
 nsExec::Exec 'net start spooler'
 
 ;===调用系统组件安装打印机===
 ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "$pname" /r $ipadd /m "$pname" /z /f "$local" '
 ExecWait 'rundll32 printui.dll,PrintUIEntry /y /n "$pname" /q'
 MessageBox MB_ICONINFORMATION|MB_OK '安装成功,如有问题,请和本人联系'
 
FunctionEnd
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容