Announcement

Collapse
No announcement yet.

Mapping Printers

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mapping Printers

    Hi guys:
    Im using this command to assing printers to users by a .bat file running on users scripts, but its a little annoying for users that each logon the .bat reinstall the printers.:

    rundll32 printui.dll,PrintUIEntry /in /q /n\\server\printer1
    rundll32 printui.dll,PrintUIEntry /in /q /n\\server\printer2

    Can i do a script to if the printer was mapping yet does not reinstall again? Thats mean verify first if the printer is installed do not continue with the script.
    Last edited by OKley; 20th September 2010, 18:56.

  • #2
    Re: Mapping Printers

    Try this: somename.vbs

    Code:
     
    Sub AddPrinter(strPrinter)
      Set WshNetwork = WScript.CreateObject("WScript.Network")
      Set oPrinters = WshNetwork.EnumPrinterConnections
      MapPrinter = True
      For i = 0 to oPrinters.Count - 1 Step 2  
        If oPrinters.Item(i+1) = strPrint Then
          MapPrinter = False
          Exit For
        End If 
      Next
      If MapPrinter = True Then
        WshNetwork.AddWindowsPrinterConnection strPrinter
      End If 
      set oprinters = Nothing
      Set WshNetwork = nothing
    End Sub
    AddPrinter("\\someprinter1")
    AddPrinter("\\someprinter2")
    Basically you replace the \\someprinter1 with the printer network share name and if it finds it the printer it is skipped otherwise it is added.

    #NOTE# This code could be more effecient, but for just a few printers it should be fine.

    If you want to get a list of the printers just run:
    Code:
     
      Set WshNetwork = WScript.CreateObject("WScript.Network")
      Set oPrinters = WshNetwork.EnumPrinterConnections
      For i = 0 to oPrinters.Count - 1 Step 2  
        wscript.echo oPrinters.Item(i+1)
      Next
      set oprinters = Nothing
      Set WshNetwork = nothing
    Hobie

    Comment


    • #3
      Re: Mapping Printers

      Note, (re-)Installing printerdriver and (re-)Mapping networkprinter are two separate events.

      see batch sample below,
      1. The optional /u switch enforce to use the existing printer driver if it's already installed.
      2. To minimize the popup-window you can use Start /MIN . This also makes that multiple printers can be connected synchronously by the batch.
      3. Furthermore, the batch will only try to add a printer connection if the printer is not mapped already for the current user.

      Code:
      :: Notes  -!!!-
      :: For this solution you must use the printer's displayname
      :: in the path instead of its sharename.
      :: And, the path should be between quotes.
      
      @echo off
      
      call:PrinterConnection "\\server\printer 1 displayname"
      call:PrinterConnection "\\server\printer 2 displayname"
      
      
      goto:EOF    + + + Subroutines + + +
      :PrinterConnection
      setlocal & Set "printer=%~1"
      Reg.exe QUERY "HKCU\Printers\Connections"|Find.exe /i "%printer:\=,%" ||(
        Start /MIN rundll32.exe printui.dll,PrintUIEntry /in /u /q /n"%printer%")
      endlocal & exit /b 0
      \Rems
      Last edited by Rems; 20th September 2010, 22:44.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Mapping Printers

        There is a similar discussion taking place in another thread. I'd post the link, but I cannot post URLs until I have 5 posts under my belt.

        Peace

        Comment


        • #5
          Re: Mapping Printers

          Originally posted by WraithForm View Post
          There is a similar discussion taking place in another thread. I'd post the link, but I cannot post URLs until I have 5 posts under my belt.

          Peace
          WraithForm,

          Just enter [thread]49223[/thread] in your post and it will be parsed to: https://www.petri.com/forums/node/50169
          Or, to make a reference to a certain post enter [post]217319[/post], this will be parsed to: https://www.petri.com/forums/node/364922

          Even nicer would be
          [B][thread=[/B]49223]"Adding Network Printers for All Users"[/thread] ==>> "Adding Network Printers for All Users"


          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: Mapping Printers

            Rems-

            Great to know! Nice work around there.

            Well will ya look at that . . . I think this will make my official 5th post!

            Peace

            Comment

            Working...
            X