Install network printers on Windows XP

From NSIS Wiki
Jump to navigationJump to search

Description

This script is used to create an installer that my Windows XP Pro users can run using the "Run As..." feature to install all network printers in all our locations without having to call me.

Installing a network printer from the command-line can be performed remotely by using the "rundll32 printui.dll,PrintUIEntry" command. This command can be run from one PC pushing the install of new printers onto client PCs. However, network printers require a change to the registry that cannot be done remotely (unless done manually via regedit) and then restarting a Windows service. This install gets around this and other issues, such as firewalls, by running on the local machine with Administrator rights.

Installing network printers requires three steps:

  1) add TCP/IP ports to Registry,
  2) restart Print Spooler to use new ports
  3) Install printers (drivers and entries into Printers Folder)

The Script

; Installer:    INSTALL_PRINTERS.EXE
; Date created: 30 September 2005
; Created by:   Charles Haven (jchaven@airpower-usa.com)
;
; This script is used to create an installer that my Windows XP Pro users can run using
; the "Run As..." feature to install all network printers in all our locations without having
; to call me.
;
; Installing a network printer from the command-line can be performed remotely by using the
; "rundll32 printui.dll,PrintUIEntry" command. This command can be run from one PC pushing the
; install of new printers onto client PCs. However, network printers require a change to the
; registry that cannot be done remotely (unless done manually via regedit) and then restarting a
; Windows service. This install gets around this by running on the local machine with Admin rights.
;
; Installing network printers requires three steps:
;   1) add TCP/IP ports to Registry,
;   2) restart Print Spooler to use new ports
;   3) Install printers (drivers and entries into Printers Folder)
;
; Additional resources:
;     https://engineering.purdue.edu/ECN/Resources/KnowledgeBase/Docs/20040216090320
;     http://www.robvanderwoude.com/2kprintcontrol.html
;     http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Newsletter~Archives+News~2005.6~Jun~-~Printer~Tips~and~Tricks.txt
;
; Note: This install creates a "fat" version of the install that includes all the drivers for the
; printers. If your PC's are always networked then you can create a "lite" version that installs the
; drivers from a network share. Just change the "/f" parameter in the "rundll32 printui.dll,PrintUIEntry"
; command to something like: "\\ntserver\install\Ricoh1013F_PCL_XP\OEMSETUP.INF"
;
; JCH -- 04 January 2006 -- Added Charlotte and Raleigh printers
; JCH -- 02 February 2006 -- Added High Point fax machine Ricoh 4410MF
; JCH -- 21 March 2006 -- Added Tupelo 1515MF
; ------------------------------------------------------------------------------------------------
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Windows XP Network Printers"
!define PRODUCT_VERSION "3.1"
!define PRODUCT_PUBLISHER "Air Power, Inc."
!define PRODUCT_WEB_SITE "http://www.airpower-usa.com"
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_TEXT "Installation complete.\r\n\nAll network printers installed in all locations have been setup on your computer.\r\n\nYou need to your default printer. Right-click on printer in Printers Folder to set as the default printer."
;!define MUI_FINISHPAGE_RUN "$SYSDIR\RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder"
;!define MUI_FINISHPAGE_RUN_NOTCHECKED
;!define MUI_FINISHPAGE_RUN_TEXT "Open Printers Folder"
 
; MUI 1.67 compatible ------
!include "MUI.nsh"
 
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
 
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
 
; Language files
!insertmacro MUI_LANGUAGE "English"
 
; MUI end ------
 
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Install_Printers.exe"
InstallDir "C:\Temp\JCH-INSTALL_PRINTERS"
ShowInstDetails nevershow
 
;Extract all printer drivers to C:\TEMP
Section "Driver Files" SEC00
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Extracting CPP500 printer driver files"
  SetDetailsPrint none
 
  ;Extract CPP500 POSTSCRIPT drivers to C:\Temp\...
  SetOutPath "$INSTDIR"
  SetOverwrite try
  ; Get all files in directory
  File /r "IP-901"
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Extracting Ricoh 1013F printer driver files"
  SetDetailsPrint none
 
  ;Extract 1013F drivers to C:\Temp\Ricoh1013F_PCL_XP
;  SetOutPath "$INSTDIR\Ricoh1013F_PCL_XP"
  SetOutPath "$INSTDIR"
  SetOverwrite try
  File /r "Ricoh1013F_PCL_XP"
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Extracting Ricoh 1515MF printer driver files"
  SetDetailsPrint none
 
  ;Extract 1515F drivers to C:\Temp\Ricoh1013F_PCL_XP
;  SetOutPath "$INSTDIR\Ricoh1515F_PCL6_XP"
  SetOutPath "$INSTDIR"
  SetOverwrite try
  File /r "Ricoh1515F_PCL6_XP"
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Extracting Ricoh 4410MF FAX printer driver files"
  SetDetailsPrint none
 
  ;Extract 4410MF drivers to C:\Temp\Ricoh4410MF
;  SetOutPath "$INSTDIR\Ricoh4410MF"
  SetOutPath "$INSTDIR"
  SetOverwrite try
  File /r "Ricoh4410MF"
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Extracting Ricoh 2020D printer driver files"
  SetDetailsPrint none
 
  ;Extract 1515F drivers to C:\Temp\Ricoh1013F_PCL_XP
;  SetOutPath "$INSTDIR\Ricoh2020D_PCL6_XP"
  SetOutPath "$INSTDIR"
  SetOverwrite try
  File /r "Ricoh2020D_PCL6_XP"
 
  sleep 1
SectionEnd
 
;Extract all batches to C:\TEMP - not used here but left as example
Section "Batch Files" SEC02
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Extracting miscellaneous files"
  SetDetailsPrint none
 
  ;Extract miscellaenous files
  SetOutPath "$INSTDIR"
  File "printers.bat"
  File "finish.txt"
  sleep 1
SectionEnd
 
;Add printer ports to registry
Section "Registry Files" SEC05
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Adding printer ports to registry"
  SetDetailsPrint none
 
  ;Include the results from Reg2NSIS utility
  !include printers.nsh
sleep 1
SectionEnd
 
;Restart Print Spooler service (needed to load new ports)
Section "Restart Spooler" SEC10
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Restarting Print Spooler service"
  SetDetailsPrint none
 
  ;Run command to restart services
  nsExec::Exec "net stop Spooler"
  sleep 2
  nsExec::Exec "net start Spooler"
  sleep 2
SectionEnd
 
;Execute rundll to install printers
; NOTE: ExecWait requires quotes in single-double-double-single format (' " " ') for this to work
Section "Exec Batch Files" SEC15
  SetOutPath $INSTDIR
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Removing existing printers"
  SetDetailsPrint none
 
  ; Removing printers
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1515 (Systems)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1515 (Tools)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1515 (Lenoir)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1515 (Raleigh)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1515 (Tupelo)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1013 (Salem)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1013 (Greenville)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Ricoh Aficio 1013 (Charlotte)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "IKON CPP500 Color Copier (High Point)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "HP Color LaserJet 8500 PCL (Chattanooga)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Epson Stylus Color 1520 (PSI)" /q'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /dl /n "Fax - Ricoh Aficio 4410NF (High Point)" /q'
  sleep 2
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Installing new printers"
  SetDetailsPrint none
 
  ; Installing printers
  ; Port NP01-M07 - used for Engineering plotter -- not installed here
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1515 (Systems)" /f "$INSTDIR\Ricoh1515F_PCL6_XP\OEMSETUP.INF" /q /r "NP01-M06" /m "RICOH Aficio 1515 PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1515 (Tools)" /f "$INSTDIR\Ricoh1515F_PCL6_XP\OEMSETUP.INF" /q /r "NP01-C05" /m "RICOH Aficio 1515 PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1515 (Lenoir)" /f "$INSTDIR\Ricoh1515F_PCL6_XP\OEMSETUP.INF" /q /r "NP03-01" /m "RICOH Aficio 1515 PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1515 (Raleigh)" /f "$INSTDIR\Ricoh1515F_PCL6_XP\OEMSETUP.INF" /q /r "NP02-01" /m "RICOH Aficio 1515 PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1515 (Tupelo)" /f "$INSTDIR\Ricoh1515F_PCL6_XP\OEMSETUP.INF" /q /r "NP06-01" /m "RICOH Aficio 1515 PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1013 (Salem)" /f "$INSTDIR\Ricoh1013F_PCL_XP\OEMSETUP.INF" /q /r "NP04-01" /m "RICOH Aficio 1013F PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1013 (Greenville)" /f "$INSTDIR\Ricoh1013F_PCL_XP\OEMSETUP.INF" /q /r "NP07-01" /m "RICOH Aficio 1013F PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Ricoh Aficio 1013 (Charlotte)" /f "$INSTDIR\Ricoh1013F_PCL_XP\OEMSETUP.INF" /q /r "NP08-01" /m "RICOH Aficio 1013F PCL 6" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Fax - Ricoh Aficio 4410NF (High Point)" /f "$INSTDIR\Ricoh4410MF\PRINTER.INF" /q /r "NP01-FAX1" /m "LAN-Fax F1" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "IKON CPP500 Color Copier (High Point)" /f "$INSTDIR\CPP500_PCL6_XP\OEMSETUP.INF" /q /r "NP01-055" /m "Fiery X3e 50C-K PCL v1.0" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "HP Color LaserJet 8500 PCL (Chattanooga)" /f "$WINDIR\inf\ntprint.inf" /q /r "NP05-01" /m "HP Color LaserJet 8500 PCL" /z /u'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /if /b "Epson Stylus Color 1520 (PSI)" /f "$WINDIR\inf\ntprint.inf" /q /r "NP01-P01" /m "Epson Stylus COLOR 1520 ESC/P 2" /z /u'
  sleep 1
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Applying details to new printers"
  SetDetailsPrint none
 
  ; Adding Printer comments
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1515 (Tools)" comment "Ricoh 1515MF B&W Copier in Tools Department"  location "High Point"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1515 (Systems)" comment "Ricoh 1515MF B&W Copier in Systems Division"  location "High Point"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1515 (Lenoir)" comment "Ricoh 1515MF B&W Copier in Lenoir branch"  location "Lenoir"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1515 (Raleigh)" comment "Ricoh 1515MF B&W Copier in Raleigh branch"  location "Raleigh"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1515 (Tupelo)" comment "Ricoh 1515MF B&W Copier in Tupelo branch"  location "Tupelo"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1013 (Salem)" comment "Ricoh 1013F B&W Copier in Salem branch"  location "Salem"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1013 (Greenville)" comment "Ricoh 1013F B&W Copier in Greenville branch"  location "Greenville"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Ricoh Aficio 1013 (Charlotte)" comment "Ricoh 1013F B&W Copier in Charlotte branch"  location "Charlotte"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "IKON CPP500 Color Copier (High Point)" comment "IKON CPP500 (old E-700) Color Copier"  location "High Point"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "HP Color LaserJet 8500 PCL (Chattanooga)" comment "Color Laser printer in Chattanooga"  location "Chattanooga"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Epson Stylus Color 1520 (PSI)" comment "Large format (11x17) inkjet printer at PSI"  location "Production Systems (HP)"'
  ExecWait 'rundll32 printui.dll,PrintUIEntry /Xs /q /n "Fax - Ricoh Aficio 4410NF (High Point)" comment "Ricoh fax machine at 336-889-2745"  location "High Point (336-889-2745)"'
  sleep 1
 
SectionEnd
 
Section -Post
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Deleting install folder"
  SetDetailsPrint none
 
  ; Delete install directory
  RmDir /r $INSTDIR
SectionEnd

Include Registry Entries

I used the Reg2Nsis utility to generate the NSIS code from my Registry and then cut-n-pasted the code I wanted several times. All I have to change in the code below is the port name ("NP01-9999") and the IP address to the network printer.

############################### reg2nsis begin #################################
# This NSIS-script was generated by the Reg2Nsis utility                       #
# Author  : Artem Zankovich                                                    #
# URL     : http://aarrtteemm.nm.ru                                            #
# Usage   : You can freely inserts this into your setup script as inline text  #
#           or include file with the help of !include directive.               #
#           Please don't remove this header.                                   #
################################################################################
# High Point Aficio FAX MF -- JCH 30 September 2005
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "Protocol" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "Version" 0x1
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "HostName" ""
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "IPAddress" "221.21.21.26"
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "HWAddress" ""
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "PortNumber" 0x238c
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "SNMP Community" "public"
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "SNMP Enabled" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-FAX1" "SNMP Index" 0x1
# High Point IKON CPP500 -- JCH 30 September 2005
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "Protocol" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "Version" 0x1
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "HostName" ""
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "IPAddress" "221.21.21.25"
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "HWAddress" ""
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "PortNumber" 0x238c
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "SNMP Community" "public"
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "SNMP Enabled" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-055" "SNMP Index" 0x1
# High Point (Tools) Aficio 1515MF -- JCH 30 September 2005
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "Protocol" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "Version" 0x1
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "HostName" ""
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "IPAddress" "221.21.21.28"
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "HWAddress" ""
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "PortNumber" 0x238c
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "SNMP Community" "public"
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "SNMP Enabled" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP01-C05" "SNMP Index" 0x1
# Charlotte Aficio 1013F -- JCH 4 January 2006
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "Protocol" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "Version" 0x1
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "HostName" ""
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "IPAddress" "192.168.7.25"
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "HWAddress" ""
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "PortNumber" 0x238c
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "SNMP Community" "public"
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "SNMP Enabled" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP08-01" "SNMP Index" 0x1
# Raleigh Aficio 1515MF -- JCH 4 January 2006
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "Protocol" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "Version" 0x1
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "HostName" ""
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "IPAddress" "192.168.2.25"
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "HWAddress" ""
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "PortNumber" 0x238c
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "SNMP Community" "public"
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "SNMP Enabled" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP02-01" "SNMP Index" 0x1
# Tupelo Aficio 1515MF -- JCH 21 March 2006
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "Protocol" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "Version" 0x1
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "HostName" ""
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "IPAddress" "192.168.8.25"
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "HWAddress" ""
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "PortNumber" 0x238c
WriteRegStr HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "SNMP Community" "public"
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "SNMP Enabled" 0x1
WriteRegDWORD HKEY_LOCAL_MACHINE "SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\NP06-01" "SNMP Index" 0x1
#
###############################  reg2nsis end  #################################
; NOTE: When adding a new printer I just copy-and-paste a block from above for a 
; similar printer and change the port and IP. I only ran the Reg2Nsis utility once 
; to get the initial entries.

Using the Executable

In our environment all users are basic domain users -- not Administrators or Power Users. Therefore, no one can install printers or even run this executable. To run executables, including this one, the end-user must know the current password for a domain administrator account that expires daily. This allows my end-users to install necessary applications, devices, or drivers; but, keeps me in the know since they have to request the current password from me (or another admin).

We post this executable with instructions on how to use, including getting the current password from administrators, on our intranet. The end-user can download this executable and using the "Run As..." feature of Windows re-install all network printers.

When a new device is added I edit this executable and post a comment on the intranet letting people know there is another printer on the network.

Known Problems

Occassionally, I will forget to change the port that will be used in Windows or use one already in use on another printer. Then when I try to print to the new printer it will print garbage on another printer. This is me being stupid -- not a bug with NSIS, this script, or Windows.

The fix for this is to edit the Registry deleting the errant port. I usually delete ALL the ports and let the installer recreate them. The ports are kept in the registry under:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\

Another problem is that the installer will appear to run through all the steps processing each step (not just quickly displaying the finish page) but, not actually add any printers. If you look at the registry you can see the added ports. This is a sign that the service could not be stopped and restarted. I have seen this on Windows XP machines with SP1 only. The fix is to manually restart the spooler service and re-run the installer.

To Do

1. Make installer check the user account type instructing the user to run using the "Run As..." command with an Administrator account.

Additional Resources

Information about installing printers on Windows XP: https://engineering.purdue.edu/ECN/Resources/KnowledgeBase/Docs/20040216090320 http://www.robvanderwoude.com/2kprintcontrol.html http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Newsletter~Archives+News~2005.06~Jun~-~Printer~Tips~and~Tricks.txt

REG2NSIS Utility: http://nsis.sourceforge.net/Reg2Nsis_-_convert_registry_info_into_NSIS_commands

HM NIS Editor: http://hmne.sourceforge.net/