Announcement

Collapse
No announcement yet.

bat file or script to install multiple printers

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

  • bat file or script to install multiple printers

    Im looking for a bat command to install multiple printers to laptops. It would need to run and add about 3 printers over tcp/ip. Just need a jump start on how to start off this bat command to it all in. the ptiners are all the same model and will have close ip range.

  • #2
    I don't think you can do it using a .bat or a .cmd you will have to script it in VB or powerscript..

    Comment


    • #3
      i think VB would work best for my issue. I dont really have much info on how to use VB though =/

      Comment


      • #4
        This might be overwhelming but I learned VBS by reading the Windows 2000 Scripting Guide which is now available for free in Technet:https://technet.microsoft.com/en-us/.../ee692931.aspx
        Regards,
        Jeremy

        Network Consultant/Engineer
        Baltimore - Washington area and beyond
        www.gma-cpa.com

        Comment


        • #5
          This one that I stole from a colleague and Rems helped to modify it for my situation some time ago. Obviously more printers than you want but I couldn't be stuffed editing it, sorry.

          It initially removes any printers already installed and then adds the one(s) you want and then sets one as the Default. Runs with a .vbs extension.

          Code:
          '---------------------------------------------------------------------------------
          'Project Name: Printer set
          'Aim: Install Printers then set default printer based on machine name
          'Date: 090824
          'Rev: 2.31
          
          '----------------------------------------------------------------------------------
          On Error Resume Next
          '-----------------------------------------------------------------------------------
          
          'create object
          Set WshNetwork = CreateObject("WScript.Network")
          
          '-----------------------------------------------------------------------------------
          '1 remove existing printers added manually
          Set clrPrinters = WshNetwork.EnumPrinterConnections
          For j = 0 to clrPrinters.Count -1 Step 2
              WshNetwork.RemovePrinterConnection clrPrinters.Item(j+1), true, true
          Next
          
          '2 remove printers added by add printer wizard
          strComputer = "."
          Set objWMIService = GetObject( _
              "winmgmts://" & strComputer & "\root\cimv2")
          Set colInstalledPrinters =  objWMIService.ExecQuery _
              ("Select * from Win32_Printer")
          For Each objPrinter in colInstalledPrinters
               objPrinter.Delete_
          Next
          
          'install all Curriculum network printers
          
          'Room 9
          PrinterPath = "\\server\curric1"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Computer Lab
          PrinterPath = "\\server\curric2"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 11 - 12
          PrinterPath = "\\server\curric3"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 3 - 4
          PrinterPath = "\\server\curric4"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 1 - 2
          PrinterPath = "\\server\curric5"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 5 - 6
          PrinterPath = "\\server\curric6"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 20 - 21
          PrinterPath = "\\server\curric7"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 13 - 14
          PrinterPath = "\\server\curric8"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 15 - 16
          PrinterPath = "\\server\curric9"
          PrinterDriver = "Lexmark T522"
          WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Room 17 - 18
          'PrinterPath = "\\server\curric10"
          'PrinterDriver = "Lexmark T522"
          'WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          'Computer Lab - Colour
          'PrinterPath = "\\server\curric11"
          'PrinterDriver = "Lexmark C710"
          'WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
          
          
          'Following line is for testing
          'Msgbox "Adding printers complete"
          
          '---------------------------------------------------------------------------------
          'get room number from computer name
          
          ComputerName = WSHNetwork.ComputerName
          Mystring = Left(Computername, 6)
          
          'the following two lines are for testing purpose
          'Msgbox "Computer name is" + Computername
          'Msgbox "Strip Number is" + Mystring
          '---------------------------------------------------------------------------------
          
          'set default printer based on room number
          
          'rem Select Case Mystring
          
          'Classroom and Lab machines
          
          'get room number from computer name
          
          ComputerName = UCase(WSHNetwork.ComputerName)
          
          ' note, because of UCase(), the Computer name string is in uppercase
          ' so the Roomsnn must also be fully in upper-case, else there is no match.
          
          'set default printer based on room number
          '  Classroom and Lab machines
          Select Case Left(ComputerName, 6)
          
          Case "COMLAB"
             WshNetwork.SetDefaultPrinter "\\server\curric2"
          
          Case "ROOM01", "ROOM02"
             WshNetwork.SetDefaultPrinter "\\server\curric5"
          
          Case "ROOM03", "ROOM04"
             WshNetwork.SetDefaultPrinter "\\server\curric4"
          
          Case "ROOM05", "ROOM06"
             WshNetwork.SetDefaultPrinter "\\server\curric6"
          
          Case "ROOM08", "ROOM09"
             WshNetwork.SetDefaultPrinter "\\server\curric1"
          
          Case "ROOM11", "ROOM12", "ROOM13", "ROOM14"
             WshNetwork.SetDefaultPrinter "\\server\curric3"
            
          'Case "ROOM13", "ROOM14"
          '   WshNetwork.SetDefaultPrinter "\\server\curric8"
          
          Case "ROOM15", "ROOM16", "ROOM17", "ROOM18"
             WshNetwork.SetDefaultPrinter "\\server\curric9"
            
          'Case "ROOM17", "ROOM18"
          '   WshNetwork.SetDefaultPrinter "\\server\curric10"
          
          ' Unlikely to be activated since Curric 2 is the default Lab Printer - Mono
          'Case "COMLAB"
          '   WshNetwork.SetDefaultPrinter "\\server\curric11"
          
          ' <...>
          End Select
          Last edited by biggles77; 2nd July 2015, 05:17.
          1 1 was a racehorse.
          2 2 was 1 2.
          1 1 1 1 race 1 day,
          2 2 1 1 2

          Comment


          • #6
            Originally posted by biggles77 View Post
            This one that I stole from a colleague and Rems helped to modify it for my situation some time ago. Obviously more printers than you want but I couldn't be stuffed editing it, sorry.

            It initially removes any printers already installed and then adds the one(s) you want and then sets one as the Default. Runs with a .vbs extension.

            Code:
            '---------------------------------------------------------------------------------
            'Project Name: Printer set
            'Aim: Install Printers then set default printer based on machine name
            'Date: 090824
            'Rev: 2.31
            
            '----------------------------------------------------------------------------------
            On Error Resume Next
            '-----------------------------------------------------------------------------------
            
            'create object
            Set WshNetwork = CreateObject("WScript.Network")
            
            '-----------------------------------------------------------------------------------
            '1 remove existing printers added manually
            Set clrPrinters = WshNetwork.EnumPrinterConnections
            For j = 0 to clrPrinters.Count -1 Step 2
            WshNetwork.RemovePrinterConnection clrPrinters.Item(j+1), true, true
            Next
            
            '2 remove printers added by add printer wizard
            strComputer = "."
            Set objWMIService = GetObject( _
            "winmgmts://" & strComputer & "\root\cimv2")
            Set colInstalledPrinters = objWMIService.ExecQuery _
            ("Select * from Win32_Printer")
            For Each objPrinter in colInstalledPrinters
            objPrinter.Delete_
            Next
            
            'install all Curriculum network printers
            
            'Room 9
            PrinterPath = "\\server\curric1"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Computer Lab
            PrinterPath = "\\server\curric2"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 11 - 12
            PrinterPath = "\\server\curric3"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 3 - 4
            PrinterPath = "\\server\curric4"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 1 - 2
            PrinterPath = "\\server\curric5"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 5 - 6
            PrinterPath = "\\server\curric6"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 20 - 21
            PrinterPath = "\\server\curric7"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 13 - 14
            PrinterPath = "\\server\curric8"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 15 - 16
            PrinterPath = "\\server\curric9"
            PrinterDriver = "Lexmark T522"
            WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Room 17 - 18
            'PrinterPath = "\\server\curric10"
            'PrinterDriver = "Lexmark T522"
            'WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            'Computer Lab - Colour
            'PrinterPath = "\\server\curric11"
            'PrinterDriver = "Lexmark C710"
            'WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
            
            
            'Following line is for testing
            'Msgbox "Adding printers complete"
            
            '---------------------------------------------------------------------------------
            'get room number from computer name
            
            ComputerName = WSHNetwork.ComputerName
            Mystring = Left(Computername, 6)
            
            'the following two lines are for testing purpose
            'Msgbox "Computer name is" + Computername
            'Msgbox "Strip Number is" + Mystring
            '---------------------------------------------------------------------------------
            
            'set default printer based on room number
            
            'rem Select Case Mystring
            
            'Classroom and Lab machines
            
            'get room number from computer name
            
            ComputerName = UCase(WSHNetwork.ComputerName)
            
            ' note, because of UCase(), the Computer name string is in uppercase
            ' so the Roomsnn must also be fully in upper-case, else there is no match.
            
            'set default printer based on room number
            ' Classroom and Lab machines
            Select Case Left(ComputerName, 6)
            
            Case "COMLAB"
            WshNetwork.SetDefaultPrinter "\\server\curric2"
            
            Case "ROOM01", "ROOM02"
            WshNetwork.SetDefaultPrinter "\\server\curric5"
            
            Case "ROOM03", "ROOM04"
            WshNetwork.SetDefaultPrinter "\\server\curric4"
            
            Case "ROOM05", "ROOM06"
            WshNetwork.SetDefaultPrinter "\\server\curric6"
            
            Case "ROOM08", "ROOM09"
            WshNetwork.SetDefaultPrinter "\\server\curric1"
            
            Case "ROOM11", "ROOM12", "ROOM13", "ROOM14"
            WshNetwork.SetDefaultPrinter "\\server\curric3"
            
            'Case "ROOM13", "ROOM14"
            ' WshNetwork.SetDefaultPrinter "\\server\curric8"
            
            Case "ROOM15", "ROOM16", "ROOM17", "ROOM18"
            WshNetwork.SetDefaultPrinter "\\server\curric9"
            
            'Case "ROOM17", "ROOM18"
            ' WshNetwork.SetDefaultPrinter "\\server\curric10"
            
            ' Unlikely to be activated since Curric 2 is the default Lab Printer - Mono
            'Case "COMLAB"
            ' WshNetwork.SetDefaultPrinter "\\server\curric11"
            
            ' <...>
            End Select


            can you help me out breaking this down? the printers i need to install are all IP printers. Where would i edit the script to add this printer..

            The script would be on a flash drive with a folder on it with the driver as well.

            Room 21 printer

            ip - 10.1.77.21

            where would i edit this in?

            Comment


            • #7
              Code:
              'Printer 1
              PrinterPath = "\\10.1.77.21\printersharename"
              PrinterDriver = "Whatever the Print Driver is called when installed"
              WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
              Why are you installing via "sneaker net" instead of using the network?
              Maybe you could tell us a little about your Network setup?
              1 1 was a racehorse.
              2 2 was 1 2.
              1 1 1 1 race 1 day,
              2 2 1 1 2

              Comment


              • #8
                Why not use GPP?

                http://blogs.technet.com/b/grouppoli...t-printer.aspx

                Comment

                Working...
                X