Setting up network printer in Windows 7

Page 2 of 3 FirstFirst 123 LastLast

  1. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #11

    I wrote this script (VBScript) a long time ago for adding a printer to Windows XP machines. I tested it and it works on Windows 7. I tweaked it a bit to take the bare minimum input. The biggest problem with it is that you have to know the EXACT name of the driver or the script will fail. If you know all this information and know it well then the script will help you add 2 or 3 printers quickly.

    Example use:

    Printer Name: HP LaserJet 4500N
    Printer Driver Name: HP LaserJet 4500 series PCL6
    Port Name: 192.168.1.200

    You must have the Printer Driver Name exactly correct or it will fail. If the IP address is wrong or the computer cannot access the IP address this script will fail.

    Please NOTE there is no error checking.

    If you have the printer shared off a server there is a much better way of doing this and I have a different script for that let me know.

    Here it is: (Copy and paste in Notepad, save as "AddPrinter.vbs") or Download below.

    Code:
    ' Add Local Printer v2.1
    ' Programmed by WindowsStar - Copyright (c) 2008-2010
    ' ---------------------------------------------------
    On Error Resume Next
    Set WShNetwork = CreateObject("WScript.Network")
    Set WShShell = WScript.CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objEnv = WshShell.Environment("Process")
    Title = "Printer Name"
    Message = "Name of Printer." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strPrinter = InputBox(Message, Title)
    If strPrinter = "" Then Wscript.quit
    Title = "Printer Driver Name"
    Message = "Printer Driver Name." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strDriverName = InputBox(Message, Title)
    If strDriverName = "" Then Wscript.quit
    Title = "Port Name"
    Message = "Enter the port you want to use." & vbLF & vbLF & "Enter and IP address (i.e. 192.168.1.1)" & vbLF &  "OR Enter LPT1: for parallel printing." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strPort = InputBox(Message, Title)
    If strPort = "" Then Wscript.quit
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
    objPrinter.DriverName = strDriverName
    objPrinter.PortName   = strPort
    objPrinter.DeviceID   = strPrinter
    objPrinter.Location = ""
    objPrinter.Network = False
    objPrinter.Shared = False
    objPrinter.ShareName = ""
    objPrinter.Put_
    WshShell.Popup "          Done!",5,"Script Message"
    Setting up network printer in Windows 7 Attached Files
      My Computer


  2. Posts : 20
    Windows 7
    Thread Starter
       #12

    WindowsStar said:
    I wrote this script (VBScript) a long time ago for adding a printer to Windows XP machines. I tested it and it works on Windows 7. I tweaked it a bit to take the bare minimum input. The biggest problem with it is that you have to know the EXACT name of the driver or the script will fail. If you know all this information and know it well then the script will help you add 2 or 3 printers quickly.

    Example use:

    Printer Name: HP LaserJet 4500N
    Printer Driver Name: HP LaserJet 4500 series PCL6
    Port Name: 192.168.1.200

    You must have the Printer Driver Name exactly correct or it will fail. If the IP address is wrong or the computer cannot access the IP address this script will fail.

    Please NOTE there is no error checking.

    If you have the printer shared off a server there is a much better way of doing this and I have a different script for that let me know.

    Here it is: (Copy and paste in Notepad, save as "AddPrinter.vbs") or Download below.

    Code:
    ' Add Local Printer v2.1
    ' Programmed by WindowsStar - Copyright (c) 2008-2010
    ' ---------------------------------------------------
    On Error Resume Next
    Set WShNetwork = CreateObject("WScript.Network")
    Set WShShell = WScript.CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objEnv = WshShell.Environment("Process")
    Title = "Printer Name"
    Message = "Name of Printer." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strPrinter = InputBox(Message, Title)
    If strPrinter = "" Then Wscript.quit
    Title = "Printer Driver Name"
    Message = "Printer Driver Name." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strDriverName = InputBox(Message, Title)
    If strDriverName = "" Then Wscript.quit
    Title = "Port Name"
    Message = "Enter the port you want to use." & vbLF & vbLF & "Enter and IP address (i.e. 192.168.1.1)" & vbLF &  "OR Enter LPT1: for parallel printing." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strPort = InputBox(Message, Title)
    If strPort = "" Then Wscript.quit
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
    objPrinter.DriverName = strDriverName
    objPrinter.PortName   = strPort
    objPrinter.DeviceID   = strPrinter
    objPrinter.Location = ""
    objPrinter.Network = False
    objPrinter.Shared = False
    objPrinter.ShareName = ""
    objPrinter.Put_
    WshShell.Popup "          Done!",5,"Script Message"
    Thanks for the help. I figured it out though. All you have to do is run this command first.

    Cscript %windir%/System32/Printing_Admin_Scripts/en-US/Prnport.vbs -a -r IP_10.2.3.4 -h 10.2.3.4

    rundll32 printui.dll,PrintUIEntry /if /b "Test Printer" /f %windir%\inf\ntprint.inf /r "IP_10.2.3.4" /m "HP Laserjet 4100 Series PCL6"

    The first script just adds the port to Windows 7/Vista the second creates the printer. Running the first script wasn't needed in XP.

    Thanks for your help.
      My Computer


  3. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #13

    IYIaster said:
    WindowsStar said:
    I wrote this script (VBScript) a long time ago for adding a printer to Windows XP machines. I tested it and it works on Windows 7. I tweaked it a bit to take the bare minimum input. The biggest problem with it is that you have to know the EXACT name of the driver or the script will fail. If you know all this information and know it well then the script will help you add 2 or 3 printers quickly.

    Example use:

    Printer Name: HP LaserJet 4500N
    Printer Driver Name: HP LaserJet 4500 series PCL6
    Port Name: 192.168.1.200

    You must have the Printer Driver Name exactly correct or it will fail. If the IP address is wrong or the computer cannot access the IP address this script will fail.

    Please NOTE there is no error checking.

    If you have the printer shared off a server there is a much better way of doing this and I have a different script for that let me know.

    Here it is: (Copy and paste in Notepad, save as "AddPrinter.vbs") or Download below.

    Code:
    ' Add Local Printer v2.1
    ' Programmed by WindowsStar - Copyright (c) 2008-2010
    ' ---------------------------------------------------
    On Error Resume Next
    Set WShNetwork = CreateObject("WScript.Network")
    Set WShShell = WScript.CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objEnv = WshShell.Environment("Process")
    Title = "Printer Name"
    Message = "Name of Printer." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strPrinter = InputBox(Message, Title)
    If strPrinter = "" Then Wscript.quit
    Title = "Printer Driver Name"
    Message = "Printer Driver Name." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strDriverName = InputBox(Message, Title)
    If strDriverName = "" Then Wscript.quit
    Title = "Port Name"
    Message = "Enter the port you want to use." & vbLF & vbLF & "Enter and IP address (i.e. 192.168.1.1)" & vbLF &  "OR Enter LPT1: for parallel printing." & vbLF & vbLF & "Leave blank or press cancel to quit."
    strPort = InputBox(Message, Title)
    If strPort = "" Then Wscript.quit
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
    objPrinter.DriverName = strDriverName
    objPrinter.PortName   = strPort
    objPrinter.DeviceID   = strPrinter
    objPrinter.Location = ""
    objPrinter.Network = False
    objPrinter.Shared = False
    objPrinter.ShareName = ""
    objPrinter.Put_
    WshShell.Popup "          Done!",5,"Script Message"
    Thanks for the help. I figured it out though. All you have to do is run this command first.

    Cscript %windir%/System32/Printing_Admin_Scripts/en-US/Prnport.vbs -a -r IP_10.2.3.4 -h 10.2.3.4

    rundll32 printui.dll,PrintUIEntry /if /b "Test Printer" /f %windir%\inf\ntprint.inf /r "IP_10.2.3.4" /m "HP Laserjet 4100 Series PCL6"

    The first script just adds the port to Windows 7/Vista the second creates the printer. Running the first script wasn't needed in XP.

    Thanks for your help.
    Yup I have done it that way too. Glad you have something that works. Enjoy!
      My Computer


  4. Posts : 8,870
    Windows 7 Ult, Windows 8.1 Pro,
       #14
      My Computer


  5. Posts : 8
    W7 32
       #15

    WindowsStar thats a nice vbs script, but it appears to be a one-off approach. I run a network with over 50 WAN sites in our XP workstation environment, and have developed a looping prnport.vbs/printui.dll machine startup script run via GPO that is easily customizeable to install anywhere from one to dozens of printers at each site.

    But it doesn't want to work in W7. please help

    Code:
     
    Here's the script:
    ::==============================================
    ::Written by Matt Lieblong Copyright 2009-2010
    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION 
    SET P1=%AestheticNameOfPrinter
    SET PIP1=%1x.x.x.x
    SET PNAME1=%"TOSHIBA eS452/453Series PCL6"
    SET PDRIVER1=%"\\LocalSitePCname\PRINTERDRIVERS\352-353-452-453\eB4ox2.inf"
     
    SET P2=%AestheticNameOfPrinter2
    SET PIP2=%1x.x.x.x
    SET PNAME2=%"TOSHIBA e-STUDIO Series Fax"
    SET PDRIVER2=%"\\LocalSitePCname\PRINTERDRIVERS\ALLMODELSLANFAX\eS4cfx2k.inf"
     
    SET P3=%AestheticNameOfPrinter3
    SET PIP3=%1x.x.x.x
    SET PNAME3=%"TOSHIBA eS452/453Series PCL6"
    SET PDRIVER3=%"\\LocalSitePCname\PRINTERDRIVERS\352-353-452-453\eB4ox2.inf"
     
    FOR %%N IN (1 2 3) DO (
    SET P=!P%%N%!
    FIND | REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\!P!"
    IF ERRORLEVEL 1 (
    SET PIP=!PIP%%N%!
    SET PNAME=!PNAME%%N%!
    SET PDRIVER=!PDRIVER%%N%!
    ECHO !P!
    ECHO !PIP!
    ECHO !PNAME!
    ECHO !PDRIVER!
    cscript.exe c:\windows\system32\prnport.vbs -a -r !P! -h !PIP! -o raw -n 9100
    rundll32 printui.dll PrintUIEntry /if /b !P! /f !PDRIVER! /r !P! /m !PNAME! /z 
    )
    )
    ::END OF SCRIPT, AFTER CUSTOMIZING FOR A SITE, DELETE EVERYTHING PAST THIS LINE
    ::THE FOLLOWING IS LOCAL PRINTER VARIABLE TEMPLATE INFO
    ::DEFINE A MASTER DRIVER FOLDER, FROM WHICH TO COPY THE VARIOUS MODEL'S INFO
    ::TO A PRINTER VARIABLE DECLARATION ABOVE (THIS JUST SPEEDS UP WRITING MULTIPLE
    ::SCRIPTS). ONCE SCRIPT IS WRITTEN, DELETE THIS PARAGRAPH AND EVERYTHING BELOW, 
    ::NAME FILE AS PRNSITENAME.BAT OR SIMILAR TO BE SAVED IN DOMAIN sysvol OR policy 
    ::FOLDERS.
     
    ::202-203-232-233-282-283
    :: TOSHIBA eS282/283Series PCL6
    :: \PRINTERDRIVERS\202-203-232-233-282-283\eB2ox2.inf
    ::
    ::352-353-452-453
    ::TOSHIBA eS452/453Series PCL6
    ::\PRINTERDRIVERS\352-353-452-453\eB4ox2.inf
    ::
    ::520-523-600-603-720-723-850-853
    :: TOSHIBA eS850/853Series PCL6
    :: \PRINTERDRIVERS\520-523-600-603-720-723-850-853\eB8mx2.inf
    ::
    ::205-255-305-355-455
    ::TOSHIBA e-STUDIO455Series PCL6
    :: \PRINTERDRIVERS\205-255-305-355-455\eS4px2.inf
    ::
    ::ALLMODELSLANFAX (for all toshiba models' print-to-fax feature)
    :: TOSHIBA e-STUDIO Series Fax
    :: \PRINTERDRIVERS\ALLMODELSLANFAX\eS4cfx2k.inf
    ::
    ::Dell1710n
    :: Dell Laser Printer 1710n
    :: \PRINTERDRIVERS\Dell1710n\DKAAY2DA.inf
    ::
    ::Dell1720dn
    :: Dell Laser Printer 1720dn
    :: \PRINTERDRIVERS\Dell1720dn\c.inf (yes the file is named c.inf)
    ::
    ::Dell2330dn
    :: Dell 2330d Laser Printer
    :: \PRINTERDRIVERS\Dell2330dn\DKACHL40.inf
    ::
    ::Dell2335dn
    :: Dell 2335dn MFP
    ::\PRINTERDRIVERS\Dell2335dn\sdf1m.inf
    ::
    ::Dell3130c
    :: Dell 3130cn Color Laser PCL6
    :: \PRINTERDRIVERS\Dell3130c\dlxbmzi.inf
    ::
    ::Lexmark T630-T632
    :: Lexmark T630
    :: OR
    :: Lexmark T632
    :: \PRINTERDRIVERS\LexmarkT630-T632\lmaaga40.inf
    ::
    ::HP OfficeJet Pro L7700
    :: HP Officejet Pro L7700 Series BT
    ::
    ::
    ::TEMPLATE TO MACHINE INSTALL A LOCALLY SHARED PRINTER ON ANOTHER MACHINE
    ::SO FAR TESTS REQUIRE NO INSTALL CHECK, AS IT WILL NOT INSTALL DUPLICATES
    ::IF ALREADY INSTALLED...
    ::LOCAL SHARE OF HP4 PRINTER INSTALL on computer [computername] used by [users name]:
    :: RUNDLL32 PRINTUI.DLL PrintUIEntry /ga /in /n\\computername\printersharename
    ::TO DELETE A LOCALLY INSTALLED PRINTER (WHICH IS WHAT THE ABOVE SCRIPT INSTALLS)
    :: RUNDLL32 PRINTUI.DLL PrintUIEntry /dl /n "printername" /q
     
    ::NOTES ON USING THIS SCRIPT:
    ::THIS SCRIPT IS IDEAL FOR AUTOMATICALLY INSTALLING PRINTERS ACROSS VARIOUS WAN SITES
    ::USING GP/GPO FEATURES. USEFUL FOR THOSE WHO HAVE NUMEROUS WAN SITES, BUT NOT PRINT
    ::SERVERS AT ALL WAN SITES, ESPECIALLY WITH SLOW CONNECTIONS TO A CENTRAL HUB OR MAIN
    ::PRINT SERVER. TO USE THIS SCRIPT, YOU MUST USE/SETUP THE FOLLOWING:
    ::
    ::1. ACTIVE DIRECTORY/GROUP POLICY FUNCTIONALITY
    ::2. AD ORGANIZATIONAL UNIT FOR EACH WAN SITE, WITH ALL RESPECTIVE PC'S ASSIGNED WITHIN
    ::3. GPO FOR EACH SITE, WITH ONLY ONE SETTING: ASSIGN MACHINE STARTUP SCRIPT WITH 
    :: RESPECTIVE WAN SITE'S UNIQUE SCRIPT LISTED
    ::4. GPO TO ENABLE THE "UNSIGNED DRIVER INSTALLATION BEHAVIOR" TO "SILENTLY SUCCEED", 
    :: THIS GPO IS MOST SIMPLY ASSIGNED TO THE OU CONTAINING ALL WAN OU'S, OR COULD
    :: BE INCORPORATED INTO EACH WAN SITE'S STARTUP SCRIPT GPO.
    ::5. FOR SITUATIONS WITH SLOW LINKS BETWEEN WAN SITES AND CENTRAL HUB FILESERVERS, 
    :: CREATE A "PRINTERDRIVER" SHARE ON ONE COMPUTER AT EACH WAN SITE, FROM WHICH
    :: TO SERVE THE INF-BASED LOCAL PRINTER INSTALLATIONS. THIS SPEEDS UP DRIVER
    :: DOWNLOADS SIGNIFICANTLY, AND HAS LITTLE EFFECT ON SHARING PC OVERALL.
    ::
    ::I WROTE THIS AS I COULD FIND NOTHING SIMILAR ELSEWHERE. IT'S ALL IN BATCH, IT'S QUITE
    ::RUDIMENTARY, HOWEVER IN MY CASE, I WAS ABLE TO WRITE AND DEPLOY THIS TO ~70 WAN SITES, 
    ::WITHIN A WEEK USING THIS SCRIPT. MUCH EASIER AND FASTER IN THE LONG RUN THAN RUNNING
    ::A PRINT SERVER, IT CREATES IP PORTS AND LOCALLY INSTALLS NETWORK PRINTERS. PRINTERS CAN
    ::BE INSTALLED, MODIFIED, AND DELETED ALL WITHIN THE SCRIPT. THE INSTALL LOOP CONTAINS
    ::A REGISTRY CHECK TO DETERMINE IF A PRINTER HAS BEEN INSTALLED ALREADY AT THE REGISTRY
    ::LEVEL. INITIAL INSTALL TAKES A FEW SECONDS PLUS TIME TO COPY/DOWNLOAD THE DRIVER FROM 
    ::YOUR LOCAL PRINTERDRIVER SHARE, PER PRINTER INSTALL. OVER A COMMON 10/100 SWITCH IT 
    ::TAKES ABOUT 5-10 SECONDS FOR LARGER (7MB) MFP PRINTER DRIVERS.
    ::
    ::IF YOU ESTIMATE 5 MINUTES PER INSTALL, THIS ENABLED ME TO INSTALL ALL NETWORK OR SHARED
    ::PRINTERS AT OVER 70 WAN SITES WITH ABOUT 1 WEEKS WORTH OF WORK. EQUIVALENT TO SEVERAL
    ::MONTHS TIME IF PERFORMING MANUAL INSTALLS OF SAME PRINTERS.
      My Computer


  6. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #16

    @MattLieblong

    Are your all Windows XP machines 32bit? Are all your Windows 7 Machines 32bit? Are all your drivers universal?? Meaning the print drivers work for XP and 7??
      My Computer


  7. Posts : 8,870
    Windows 7 Ult, Windows 8.1 Pro,
       #17

    MattLieblong said:
    WindowsStar thats a nice vbs script, but it appears to be a one-off approach. I run a network with over 50 WAN sites in our XP workstation environment, and have developed a looping prnport.vbs/printui.dll machine startup script run via GPO that is easily customizeable to install anywhere from one to dozens of printers at each site.

    But it doesn't want to work in W7. please help
    Maybe the directions for setting up a printer via GPO will help.

    Deploying Printers by Using Group Policy

    There are also some settings to enable printer set up via GPO starting about a third of the way down this Technet page that might interest you.

    http://social.technet.microsoft.com/...d-566985522673

    Towards the bottom of the page you see tricks like this...
    Try to deploy your printers directly via the printserver - server manager - select printserver - printers
    right click on the printer -- select "Deploy with Group Policy"
    - click on browse --> find the desired policy
    - select if you want to deploy the printer "per computer" or "per user" and click "add"
    after that - gpupdate on the client - and voilą the printers are listed....
      My Computer


  8. Posts : 8
    W7 32
       #18

    Yes the drivers are all the manufacturer drivers for both XP & W7.

    The script I posted was the original script that I ran for all 32bit XP machines. I have toyed around with modifying for the different location of the prnport.vbs as in...

    cscript.exe c:\windows\system32\Printing_Admin_Scripts\en-US\prnport.vbs -a -r !P! -h !PIP! -o raw -n 9100

    but that is still problematic. I either get 0x00000035 or 0x000006be errors.

    I actually get the original XP script to work partially on a 32bit W7 machine if i copy the contents of c:\windows\system32\Printing_Admin_Scripts\en-US to the c:\windows\system32 folder where they used to be on XP.

    Can anyone explain the difference in W7 regarding these scripts?
      My Computer


  9. Posts : 8
    W7 32
       #19

    To address other possible questions...

    I decided NOT to use a print server due to the fact that we have 70 sites across a state, many of which operate on fractional frame relay (SLOW!) WAN links, also eliminating a centralized print server eliminates printing failures if the WAN link goes down, which happens more than I wish.

    I have that script run at every startup to verify all office printers are installed per office at a machine level, so all names are identical, simpler to identify for users. it does a registry check to verify the printers are installed with the exact name i give.

    the script is kind of messy, but very logical for a batch script. And spaghetti code or not, at my large offices i can deploy multiple new printer installs across all machines by only updating the script in a few minutes, and forcing restarts of the machines in groups so as not to traffic jam the request of the drivers.

    I put a local open file share on 1 pc at each site that serves as the local printerdriver share. this speeds up the printui.dll /if install significantly, even over 10/100 switch is only a few seconds.

    we don't have resources to put a server/printserver at each location, and honestly, if we did that would be more of a headache than managing 70 of these scripts. i only have to change these scripts when a printer changes.
      My Computer


  10. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #20

    @MattLieblong

    How do you deploy the scripts? Are the scripts on each machine? or are they stored somewhere? Is the registry key to tell you if they get a certain printer or to tell you which printers they get?
      My Computer


 
Page 2 of 3 FirstFirst 123 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:29.
Find Us