+ Post New Thread
Results 1 to 12 of 12
Scripts Thread, Add Printer in Coding and Web Development; Is it possible to create a VB script to install a local TCP/IP port printer on a machine and have ...
  1. #1

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,228
    Thank Post
    13
    Thanked 230 Times in 219 Posts
    Rep Power
    68

    Add Printer

    Is it possible to create a VB script to install a local TCP/IP port printer on a machine and have it pop up asking for the IP when its installing it?

    I have say 10 models of printers all over the place and what I want to do is create a script for each model with reference to where the drivers are and then just enter the IP when I run this script, is this possible?

  2. #2

    Join Date
    Jul 2007
    Posts
    102
    Thank Post
    5
    Thanked 18 Times in 15 Posts
    Rep Power
    18
    Here is a script I use

    (This bit all on one line)

    rundll32 printui.dll,PrintUIEntry /ga /c\\computername /n\\servername\printername



    sc \\computername stop spooler

    sc \\computername start spooler



    Change the computer name, server name and printer name. You can add as many as you like as long as there is a gap between each "start spooler" command.



    To remove a printer just change ga to gd in the script. This will add or delete the printer for all users.

  3. #3

    Join Date
    Jul 2007
    Posts
    102
    Thank Post
    5
    Thanked 18 Times in 15 Posts
    Rep Power
    18
    Just re-read your post, probably not what you are after but is good for network printer deployment.

  4. #4

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,228
    Thank Post
    13
    Thanked 230 Times in 219 Posts
    Rep Power
    68
    Sorry not what I'm after.

  5. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,803
    Thank Post
    3,311
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365
    Sent email and pm @MatthewL - Just wondering would Group Policy Preferences not be an option ( not sure what Server OS'es you are using / have ) ??

    Link that I can find ( Printer Manager as maybe a 2nd option ) - http://technet.microsoft.com/en-gb/l...=ws.10%29.aspx
    Last edited by mac_shinobi; 10th April 2013 at 11:09 AM.

  6. #6

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,228
    Thank Post
    13
    Thanked 230 Times in 219 Posts
    Rep Power
    68
    It would be but we don't have access to that and machines are generally still XP. It is not my network so literally have a login with local admin rights.

  7. #7
    bainer's Avatar
    Join Date
    Apr 2013
    Location
    West Yorkshire
    Posts
    8
    Thank Post
    0
    Thanked 3 Times in 3 Posts
    Rep Power
    0

    Add a local printer and prompt for a printer port IP

    Something like this is a start. Enjoy

    Dim strIP
    strIP = InputBox ("Enter TCP/IP Printer Port IP Address")
    CreatePort(strIP)

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
    objPrinter.DriverName = "HP LaserJet 4250 PCL6"
    objPrinter.PortName   = "IP_" & strIP
    objPrinter.DeviceID   = "Printer Name"
    objPrinter.Location = "Location"
    objPrinter.Put_

    Function CreatePort(pName)
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set objNewPort = objWMIService.Get _
        ("Win32_TCPIPPrinterPort").SpawnInstance_
    objNewPort.Name = "IP_" & pName
    objNewPort.Protocol = 1
    objNewPort.HostAddress = pName
    objNewPort.PortNumber = "9100"
    objNewPort.SNMPEnabled = False
    objNewPort.Put_
    EndFunction

  8. Thanks to bainer from:

    mac_shinobi (23rd April 2013)

  9. #8

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,228
    Thank Post
    13
    Thanked 230 Times in 219 Posts
    Rep Power
    68
    Exactly what I am after but what happens if it is a printer which the client doesn't have the drivers on and they are in the folder?

    I suppose the way of doing it is add the drivers and then add printer but I was hoping for a one stop script. mac_shinobi has given me a script which I am have not had chance to try yet but what you have put bainer is what I am after except that the drivers are not part of Windows.

  10. #9
    bainer's Avatar
    Join Date
    Apr 2013
    Location
    West Yorkshire
    Posts
    8
    Thank Post
    0
    Thanked 3 Times in 3 Posts
    Rep Power
    0
    You're right, you need to get the driver installed first, are you wanting this in the same script? Just that this would require a lot of editing each time you use a new driver. What might be a good option was to build a driver catalogue. This could just be a text or csv on a file share. The script would build an array of installed drivers on the client and compare the list with the central catalogue. If one is missing on the client, the driver could be installed, then the printer added.
    Does this sound like the kind of thing your looking for?

  11. #10

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,228
    Thank Post
    13
    Thanked 230 Times in 219 Posts
    Rep Power
    68
    I am more after just a single click prompt for IP address and it installs it. Don't mind having a script for each model as it will save me lots of time.

    I have got a script but I haven't had time to test it yet, this was given to me by another user on here. It's one of those things I am doing in my space time.

  12. #11


    Join Date
    Sep 2009
    Posts
    577
    Thank Post
    13
    Thanked 55 Times in 34 Posts
    Rep Power
    224
    Would Printer Migrator not be a better alternative?

    I use it all the time as it saves me so much hassle. The drivers and ports are contained within a cab file and you can install the printers in less than a minute. If you want more info let me know.

  13. #12

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,228
    Thank Post
    13
    Thanked 230 Times in 219 Posts
    Rep Power
    68
    Never thought of that, might have a look at that.

SHARE:
+ Post New Thread

Similar Threads

  1. hta - add printer
    By mac_shinobi in forum Scripts
    Replies: 14
    Last Post: 31st May 2010, 09:50 PM
  2. Add printer driver without *.INF file to server 2003
    By shafeek in forum Windows Server 2000/2003
    Replies: 2
    Last Post: 29th March 2010, 01:03 PM
  3. Disable Add Printer on 10.6 or WGM
    By 10101010 in forum Mac
    Replies: 1
    Last Post: 18th February 2010, 06:37 PM
  4. Network printing - easy way for users to add printers
    By Kevin_Beaumont in forum How do you do....it?
    Replies: 14
    Last Post: 9th December 2008, 01:05 PM
  5. Add printer script not workling
    By mark in forum Windows
    Replies: 6
    Last Post: 15th September 2005, 10:07 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •