1 Reply Latest reply on Jul 1, 2010 6:04 AM by zman

    Installing a Printer

    Apprentice

      Hey Guys

       

      I may be being a complete numpty.  I want to create two jobs

      1) to install a printer

      2) to remove the same printer as 1

       

      The printer is shared off a server (lets say printsvr to be bleak) and is a mfd (call it mfd1)

       

      As an admin i can install the printer by browsing to the server and selecting to mfd (\\printsvr\mfd1)

      I have also created a vb script that does it, and a vb script to remove.

       

      But how do you push it out for it to run on clients machines!  What type of distribution package do i need to push out this script to run on my client machines!

       

      Thanks

       

      Dave H

        • 1. Re: Installing a Printer
          zman Master

          Here is how I did it. I used the Autoitscript below that will both add and delete printers based on an INI file. Just change the $inilocation variable.  Update the ini located below with the printers you want to add or delete. Create a distribution package and just ensure that on the Accounts - Select current user account.  If you don't want to use the script below just create a distribution package for you vbscripts and ensure that you choose Accounts - Select current user account. Printers are user based so they can be setup easily running as local system account. The reason I wrote the script I wanted something flexible (one script, with a control file) it is kind of rough since it is very old but works. I would probably change it now to accept the ini file as a command line option.

           

           

          Source

          #NoTrayIcon
          #include <Array.au3>
          
          AutoItSetOption("TrayIconHide", 1)
          
          Dim $oMyError
          Dim $HexNumber
          Dim $IniLocation = "\\servername\printers.ini"
          
          $UNCpathdel =IniReadSection ( $IniLocation, "DELETE" )
          If @error Then
              MsgBox(4096, "", "Error occurred, Can't Read INI file.",10)
              Exit (110)
          EndIf
          $UNCpathadd =IniReadSection ( $IniLocation, "ADD" )
          If @error Then
              MsgBox(4096, "", "Error occurred, Can't Read INI file.",10)
              Exit (110)
          EndIf
          
          $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler
          $Printers = ObjCreate("WScript.Network")
          
          ProgressOn("Deleting Printers", "Deleting Printers...Please Be Patient", "")
          For $i = 1 To $UNCpathdel[0][0] step 1
              If $i = 0 Then
                  ProgressSet(1 , @CRLF & $UNCpathdel[$i][1])
              EndIf
                  ProgressSet( $i * 100/UBound($UNCpathdel)-1, @CRLF & $UNCpathdel[$i][1])
                  $Printers.RemovePrinterConnection ($UNCpathdel[$i][1], True, True)
          Next
          ProgressSet(100 , "Done", "Complete")
          sleep(2000)
          ProgressOff()
          
          ProgressOn("Adding Printers", "Adding Printers...Please Be Patient", "")
          For $i = 1 To $UNCpathadd[0][0] step 1
              If $i = 0 Then
          
          
                  ProgressSet(1 , @CRLF & $UNCpathadd[$i][1])
              EndIf
          
          
              ProgressSet( $i * 100/UBound($UNCpathadd)-1, @CRLF & $UNCpathadd[$i][1])
              $Printers.AddWindowsPrinterConnection ($UNCpathadd[$i][1], True, True)
          Next
          ProgressSet(100 , "Done", "Complete")
          sleep(2000)
          ProgressOff()
          
          
          ; This is my custom error handler
          Func MyErrFunc()
             $HexNumber=hex($oMyError.number,8)
             ;Msgbox(0,"","We intercepted a COM Error !" & @CRLF & "Number is: " & $HexNumber & @CRLF & "Windescription is: " & $oMyError.windescription )
             SetError(1) ; something to check for when this function returns
          Endfunc
           
          

           

           

          INI File

           

          [ADD]
          PRINTER=\\PQ-1\PRT1
          PRINTER=\\PQ-2\PRT2
          PRINTER=\\PQ-3\PRT3 
          
          [DELETE]
          PRINTER=\\PQ-1\PRT4
          PRINTER=\\PQ-2\PRT5
          PRINTER=\\PQ-3\PRT6 
          
          
          
          

          Selfish Plug for My ERs
          Core Synchronization - OSD !
          http://community.landesk.com/support/message/42401

           

          Updated Inventory Attributes
          http://community.landesk.com/support/message/46430

           

          Cumlative Patch List for LANDesk Products
          http://community.landesk.com/support/message/47289

           

          Integrate a Console Extender into the Console
          http://community.landesk.com/support/message/47374