Trying to make a printer default on a remote PC using DOS batch file

已答复 Trying to make a printer default on a remote PC using DOS batch file

  • Wednesday, May 16, 2012 3:48 AM
     
     

    I am trying to install printers remotely using the following DOS command

    rundll32 printui.dll PrintUIEntry /ga /n\\print_Server Name\Printer_Name /c\\Computer_name

    in the same batch file I am trying to make the installed printer default for all user profiles (XP Pro)

    I have been using the follwing DOS command:

    rundll32 printui.dll PrintUIEntry /y /n\\print_server_name\Printer_Name /c\\Computer_Name

    then using the DOS SC command to stop and start the remote print spooler

    can someone please help as the printer is installing but not setting as default printer

All Replies

  • Thursday, May 17, 2012 5:56 AM
    Moderator
     
     Answered

    Hi,


    I'd like to confirm what is the OS version?


    I'd like to suggest to use Printer Server and Group Policy to achieve the target.


    Deploy printers by using Group Policy
    http://technet.microsoft.com/en-us/library/cc722179(v=WS.10).aspx


    In addition, if there is any windows 2008/vista and later, we can use GPP to deploy the printer:


    Printers Extension
    http://technet.microsoft.com/en-us/library/cc731562


    Hope this helps!


    Best regards
    Elytis Cheng


    Elytis Cheng

    TechNet Community Support

  • Thursday, May 17, 2012 8:14 PM
     
     

    Thanks for answering,

    The print server is Windows server 2003 SP2, the enviroment is as follows Windows 7 x86, Windows7 x64, Windows XP Pro SP3,

    there are 76 printer objects and just under 1000 computers/laptops.

    This is a rual  WAN Hospital environment in New Zealand

    Pieter


    • Edited by Pieter Boks Thursday, May 17, 2012 9:52 PM
    •  
  • Friday, May 18, 2012 12:00 AM
    Answerer
     
     Answered

    The use of the /ga flag is to add the printer during the next user logon.  I think the spooler will also do this on a spooler restart.  I suspect the printer is not added until you have restarted the spooler and thus can't set the default.  I suggest placing the spooler restart before the setdefault call as well as a sleep for at least 120 seconds.  60 seconds for the spooler to finalize initialization and 60 seconds to download driver and add connection.

    I'm assuming the server name difference is a typo in the message.

    rundll32 printui.dll PrintUIEntry /ga /n\\print_Server Name\Printer_Name /c\\Computer_name

    rundll32 printui.dll PrintUIEntry /y /n\\print_server_name\Printer_Name /c\\Computer_Name


    Alan Morris Windows Printing Team

  • Friday, May 18, 2012 1:21 AM
     
     Answered Has Code

    In vbscript it could be easy to deal with too.

    How to Add a Default Printer Using a Visual Basic Script

    or

    http://www.computerperformance.co.uk/Logon/LogonScript_Printer_Bonus.htm#Example_1_-_Set_Default_Printer_Script

    It would be like that (pasted from above website);

    Option Explicit
    Dim objNetwork, strUNCPrinter
    strUNCPrinter = "\\LittleServer\HP LaserJet 2420"
    Set objNetwork = CreateObject("WScript.Network") 
    objNetwork.AddWindowsPrinterConnection strUNCPrinter
    ' Here is where we set the default printer to strUNCPrinter
    objNetwork.SetDefaultPrinter strUNCPrinter
    WScript.Quit


    MCP | MCTS 70-236: Exchange Server 2007, Configuring


  • Sunday, May 20, 2012 8:49 PM
     
     Answered

    Thanks for the answers Yagmoth555 and Alan, I appreciate the time and effort of both of you, below is the batch file I have come up with.

    echo

    rundll32 printui.dll printUIEntry /ga /n\\PS1\WICTDBW1

    sleep 5

    net stop spooler

    sleep 5

    net start spooler

    sleep 5

    rundll32 printui.dll printUIEntry /y /n\\PS1\WICTDBW1

    sleep 5

    net stop spooler

    sleep 5

    net start spooler

    sleep 5

    exit


    • Edited by Pieter Boks Sunday, May 20, 2012 11:53 PM
    • Marked As Answer by Pieter Boks Wednesday, May 23, 2012 11:20 PM
    •  
  • Wednesday, May 23, 2012 11:22 PM
     
     Answered

    Thanks for the help guys, the bachfile is now going through change control.

    With thanks

    Pieter

    • Marked As Answer by Pieter Boks Thursday, May 24, 2012 1:32 AM
    •