Announcement

Collapse
No announcement yet.

Network Printer Logon Script

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

  • Network Printer Logon Script

    I'm running a Win2008 domain, and have a User-based logon GPO referencing a VB
    script which shares several network printers, each shared from a single file
    server. This GPO applies to "Domain Users." My issue is that if I delete a the shared printer off the GPO (and server too), it remains on the client workstations, confusing the end users. What's the best way to remove an old network printer from workstations?

    Here's the current logon script:

    MapPrinter "\\DC1\HPLJ2300N"
    MapPrinter "\\DC1\DELL1710N"
    MapPrinter "\\DC1\DELL3100CN"

    Sub MapPrinter(strPrinter)
    On Error Resume Next
    Set objNetwork = CreateObject("WScript.Network")
    boolConnected = False
    intAttempts = 1
    While boolConnected = False And intAttempts <= 10
    Err.Clear
    objNetwork.AddWindowsPrinterConnection strPrinter
    If Err.Number <> 0 Then
    intAttempts = intAttempts + 1
    WScript.Sleep 2000
    Else
    boolConnected = True
    End If
    Wend
    Err.Clear
    On Error GoTo 0
    End Sub
    Last edited by biggles77; 28th August 2009, 20:55. Reason: Wrap script in CODE format.

  • #2
    Re: Network Printer Logon Script

    Google "vbscript remove network printer" and maybe you'll find the answer
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

    Comment


    • #3
      Re: Network Printer Logon Script

      If you search the Scripting Forum for Print script + Biggles77 then you should find a thread about removing printers. Rems pointed out that 2 different script code was required to remove printers installed manually and by the Add Printer Wizard.

      I don't know which script would be needed to remove the printer from the workstation but for the script Rems help me modify I ended up using both removal codes.

      If you can't find the thread post back and I will have a look for it.
      1 1 was a racehorse.
      2 2 was 1 2.
      1 1 1 1 race 1 day,
      2 2 1 1 2

      Comment


      • #4
        Re: Network Printer Logon Script

        I usually just use the built in prnmngr.vbs script to add and remove printers, cos I'm too lazy to write my own.

        http://technet.microsoft.com/en-us/l...68(WS.10).aspx
        BSc, MCSA: Server 2008, MCSE, MCSA: Messaging, MCTS
        sigpic
        Cruachan's Blog

        Comment


        • #5
          Re: Network Printer Logon Script

          A good practice for deleting mappings to a shared printer:

          first of all, Do NOT delete or rename the old shared printer(s) on the server!
          Run a logon script for a long period of time (see sample below) that delete/replace the old printer mapping if exist in the current user's profiles on his/her computer.
          After the appropriate changes on the client computer's, you can delete the old shared printer from the server.

          If you already have deleted or renamed the shared printer from the server, it is possible the old printers are not removable anymore. The user will receive an ERROR similer to:
          "Printer connection cannot be removed. You either entered a printer name that was incorrect or the specified printer is no longer connected to the server. Click help for more information." (see also: Script to remove obsolete printer in local profiles).

          _
          Originally posted by biggles77 View Post
          If you search the Scripting Forum for Print script + Biggles77 then you should find a thread about removing printers. Rems pointed out that 2 different script code was required to remove printers installed manually and by the Add Printer Wizard.

          I don't know which script would be needed to remove the printer from the workstation but for the script Rems help me modify I ended up using both removal codes.

          If you can't find the thread post back and I will have a look for it.
          Remarks about using the RemovePrinterConnection Method (used in script sample below):
          • The RemovePrinterConnection method is able to remove both Windows and MS-DOS based printer connections.

          • If the printer was connected using the AddWindowsPrinterConnection method or was added manually (using the Add Printer wizard), then strPrinter must be the printer's UNC name.
            (* the UNC name can be eighter the "\\server\sharename" or, "\\server\fullname of the printer". However when using it in the script in combination with EnumPrinterConnections then you better use only "\\server\fullname of the printer")
          • If the printer was connected using the method AddPrinterConnection then strPrinter must be the actual printer's local! name.

          Code:
          '# Delete printer mapping for the current user on this computer
          
          strPrinterName = "name of printer" '(you can use printer's fullname or, sharename)
          strPrintServer = "servername"
          strPrinter = "\\" & strPrintServer & "\" & strPrinterName
          
          Set WshNetwork = WScript.CreateObject("WScript.Network")
          
          '# Delete printer IF exist
          On Error Resume Next
          WshNetwork.RemovePrinterConnection _
             strPrinter, true, true
          If Err.number = 0 then
             wscript.sleep 100
          Else
             err.Clear
          End If
          On Error Goto 0
          \Rems
          Last edited by Rems; 3rd September 2009, 17:32.

          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

          Working...
          X