none
Deploying network printer using script RRS feed

  • Question

  • Hi all,

    I was wondering whether you could help. Basically I am wanting to deploy a network printer using a script as part of the logon script settings for users in Group Policy, however it comes up with an error each time I log on to a PC saying there is an error on line 4 character 1. Below is my script for deploying a network printer.

    strPrinter="<UNC path of printer>"
    Set WshNetwork = CreateObject("WScript.Network")
    Set WshShell = CreateObject("WScript.Shell")
    WshNetwork.AddWindowsPrinterConnection strPrinter
    WshNetwork.SetDefaultPrinter strPrinter
    REM MsgBox strPrinter & " Printer connected and set as the default printer"
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    PrinterPath = "<UNC path of printer>"
    On Error Resume Next
    WshNetwork.RemovePrinterConnection PrinterPath, true, true
    If Err.Number = 0 Then
    REM MsgBox PrinterPath & " Printer Removed"
    REM MsgBox "Default printer is now " & strPrinter
    End If
    On Error Goto 0 

    Any pointers as to where I am going wrong is much appreciated. 

    Kind regards,

    RocknRollTim
    Monday, February 19, 2018 2:45 PM

Answers

  • Please use Group Policy preferences to deploy printers.  This has not been done in logon scripts since WS2003r2 and is not considered a reliable way to manage printers.

    \_(ツ)_/

    • Marked as answer by RocknRollTim Monday, February 19, 2018 3:30 PM
    Monday, February 19, 2018 2:55 PM

All replies

  • Please use Group Policy preferences to deploy printers.  This has not been done in logon scripts since WS2003r2 and is not considered a reliable way to manage printers.

    \_(ツ)_/

    • Marked as answer by RocknRollTim Monday, February 19, 2018 3:30 PM
    Monday, February 19, 2018 2:55 PM
  • Hi jrv,

    That explains why it does not work with PCs above Windows XP and 2003. Thank you for responding to my forum thread and will consider the use of Group Policy preferences instead.

    Regards,

    RocknRollTim 

    Monday, February 19, 2018 3:30 PM
  • The Print Manager optional feature can manage the GP policies necessary for computer deployment.

    Keep in mind that in newer versions of Windows the login scripts can be delayed for as much as 5 minutes after the login shows a usable desktop.

    GP applies once and doesn't need to reapply except if you make changes to the policy.

    If you decide to rearrange printers or migrate a spool server the Print Management console and its utilities can make this painless.


    \_(ツ)_/

    Monday, February 19, 2018 3:45 PM
  • Hi jrv,

    Sorry for the delay in getting back to you and totally agree with you. I have re-written the script as it had numerous errors when running the script on a single test PC. Below is the current script coding I have used to rectify the problem.

    On Error Resume Next
    Set wshNet = CreateObject("WScript.Network")
    Set wshPrn = wshNet.EnumPrinterConnections
    For x = 0 To wshPrn.Count - 1 Step 2
        If Left(wshPrn.Item(x+1),2) = "\\" Then wshNet.RemovePrinterConnection wshPrn.Item(x+1),True,True
    Next

    wshnet.AddWindowsPrinterConnection "<UNC path of printer>"
    wshnet.SetDefaultPrinter "<UNC path of printer>"

    Also as well as applying the script to a GPO, I had to apply the relevant security filtering as well as applying the GPO to the relevant OU which was the user OU in our case, this included applying the relevant computer objects to the delegation list as the GPO would not successfully apply to the PCs we wanted the printer applying to.

    Regards,

    RocknRollTim

    Wednesday, March 14, 2018 2:03 PM