Set the default printer for all users on a Windows XP computer

A situation came up at work recently where one of our users wanted to make sure that each and every person who logged onto a particular machine would have the same printer set up as their default. Various previous attempts to do this had failed, since there doesn’t seem to be a command-line switch for globally changing the default printer in Windows XP. I floated the problem to a co-worker, who suggested putting a simple batch file in place to run on every user’s Logon. This ended up working beautifully, as follows:

  1. Create a batch file by going to My Computer, choose the root file path of the hard drive (usually C:), right-click on some empty space and select ‘New Text Document.’
  2. Next, open your new text document and type in one of the following lines:
    • If you have a networked printer, type rundll32 printui.dll,PrintUIEntry /y /n\\%printername%
    • If you have a local printer, type rundll32 printui.dll,PrintUIEntry /y /n”%localprintername%”
    • Choose ‘Save As’ in Notepad and change the type of file from Text (.txt) to ‘All Files.’ Name it something like ‘printer.bat’ (the ‘printer part is not important, the .bat part is) and save it to the C: drive.
    • Go to ‘Start,’ choose ‘Run,’ and type ‘gpedit.msc’ to launch the Management Console.
    • Under ‘User Configuration,’ ‘Windows Settings,’ you will find ‘Scripts (Logon / Logoff).’ Double-click on ‘Logon’ in the main window (to the right) and choose ‘Add’ to add a new script.
    • Browse for your batch file (should be on C:). You don’t need any additional parameters. At this point, every user that logs in will have their default printer reset to the one you want.
    • default printer, printer, windows xp, windows, printers, windows printer, default, command-line printer, printer control, global printer control, global default printer, management console, notepad, logon script, logon, user


  1. joe says:

    This is useless and doens't work. Ended up setting printer as default and then using regedit to export the following keys.


    export that and all subtrees as 1st.reg

    then save this one as 2nd.reg

    [HKEY_CURRENT_USERSoftwareMicrosoftWindows NTCurrentVersionWindows]


    then user bat file to regedit them in to user logging in

    regedit /s "path/to/1st.reg"

    regedit /s "path/to/2nd.reg"

    copy this bat file as a shortcut to the all users > startup folder.

    it works for all new and existing users logging in.

  2. Vasken says:


    Actually, it does work (in Vista too–see above comment). Based on your Neanderthal approach to netiquette, I suspect you're just too stupid to realize that the commands listed above are each one line, and you're confused by why "/n%printername%" isn't doing anything productive.

    I love your ridiculously complicated approach to solving the problem, though. God help the registry with you around…

  3. iladelf says:

    Say, Vasken, let me see if I'm understanding this right:

    If I have a printer that is located in the following location:

    Frickin Printer FolderLabRat01

    then, my batch file would look like this, no?

    rundll32 printui.dll,PrintUIEntry /y /nFrickin Printer FolderLabRat01

    Hope you can let me know if this is right. This would fix a MAJOR problem where I work right now.

  4. Vasken says:


    You can repeat the command for as many printers as you want.

    As to the first question, that's definitely the correct syntax for adding the printer…I just hope there are no actual spaces in any of your network paths like in your example (I haven't tested escaping the characters or anything). Not that it's possible to have a network path with spaces….

    • Mohammed says:

      Hello Vasken,

      I can’t seem to make it work. The printer that i want to use is on a network, on a server called Byg-Cprint2. The printer is called BYG-PHP05-PCL.
      Now as for the script, this is how it looks for me:
      rundll32 printui.dll,PrintUIEntry /y /n \\byg-cprint2\BYG-PHP05-PCL

      When i run the script om my admin profile, it just runs with no errors, but when i do it with another profile, i get an error telling me to check the printer name or something like that.
      Can you please help me.
      Thanks in advance 🙂

  5. Calvin says:

    Hi this was useful, my only question and it may be silly but how do you determine a printer name. Is there a command to get it or it is just the name displayed in the printers and faxes folder. An example would have been awesome.

  6. Marie says:

    I can't get this to work. What am I doing wrong? Here is what I have in my batch file:

    rundll32 printui.dll,PrintUIentry/y/njcwwnel045Brother

    The printer name is the computername/sharename of the printer.

    It never shows up under printers. I can manually add the printer and am an administrator on both computers.

  7. Vasken says:


    With this command, the printer doesn't show up immediately unless you log off and log back in. You can also try the following two commands in the command line or Run option: net stop spooler followed by net start spooler. That should restart the print service and show you the printer.

    The other reason it may not be working is that you need spaces between the options (i.e. /y /n) I'm not exactly sure on that one, but it's worth a shot if nothing else works.

  8. Kari says:

    Ok, so I got this to work, and it solves a MAJOR problem, so I really really appreciate this.

    There's only one problem. When anyone logs in now, they get the error message "Operation could not be completed. Either the printer name was typed incorrectly, or the specified printer has lost its connection to the service."

    But then, when the person logs in, the printer is there, and while I have to manually set it as default, at least it's installed for all users (before this script, I had to install the printer on each user account, so at least the script works to install the printer!)

    I don't mind telling people to just click past the error message, but it bugs *me*, since I'm anal like that.

    The printer installed is a local printer installed on a TCP/IP port, and it is named RCPS. The *.bat file contains:

    rundll32 printui.dll,PrintUIEntry /y /n"%RCPS%"

    Did I do something wrong? Like I said, it at least allows all users to access the printer, it just gives that error message and doesn't want to set as the default printer.

    Thanks a ton for any help–this has saved me a LOT of work! 🙂

  9. Perry Roberts says:

    Using an Apple Airport Extreme wireless and bonjour services for an 20 laptop cart-the extreme has the access as ES_PC_cart-the printer attaches to the Airport VIA USB-name is HP LaserJet P1505n – the following did not work for me:

    XXXXX/y /nES_PC_cart%HP LaserJet P1505n%

  10. Vasken says:


    Try it without the %s. They're just there to indicate the word is a placeholder.

    XXXXX/y /nES_PC_cartHP LaserJet P1505n

    If that doesn't help, you might also try renaming the printer to something without spaces.

  11. Jay says:

    Here you go. Set it, then set it to default….

    The key technique is rundll32 printui.dll,PrintUIEntry.

    1) This installs printer quietly

    rundll32 printui.dll,PrintUIEntry /in /q /nservernameprintername

    2) This deletes the networked printer from the machine being logged onto, and does so quietly.

    rundll32 printui.dll,PrintUIEntry /dn /q /nservenameprintername

    3) This Sets the default printer

    rundll32 printui.dll,PrintUIEntry /y /nservernameprintername

  12. Bill says:

    My question is similar to Kari's.

    I have used the /ga switch successfully, no problem there.

    However, when a user logs into a machine for the first time, the line "rundll32 printui.dll,PrintUIEntry /y /nservernameprintername" generates an error (I am using a bat file in the startup folder of 'all users.' If I check quickly enough, I can also see that the printer does not appear in printers and faxes at that point.

    However, it does appear after waiting a little bit longer – without doing anything. At that point, running the bat file to set the default printer works fine.

    It also works fine the NEXT time that user logs into the same computer – the printer connection is already there.

    It seems to be a timing issue that shows up during first-time logins – it is running the startup bat file before the connection to the printer is formed.

    Is there a way to delay the bat file, or the command in the bat file, until the printer connection is completed?

    Or is there a different approach for setting that printer as the default for all users for a machine that would get around this timing issue?

    • Vasken says:


      We actually ran into the same thing here with our lab computers. The only way around it we found was adding the printers via a VBscript, but that has resulted in it taking up to a minute to load the printers for each user. We're just planning to install the printers as local printers via Group Policy when we initially deploy them from now on.

  13. Bill says:

    Well, this isn't this most elegant solution, but here is what I ended up going with for now:

    First add the network printer using the /ga switch as usual.

    A shortcut in the startup folder pointing to a batch file in a local folder on root, with the properties of the shortcut set to run minimized and to "start in" %USERPROFILE% (and the icon changed to one of the pritner-like icons from shell32.dll.

    The batch file runs like this:


    @echo off

    SET /A J=0


    rundll32 printui.dll,PrintUIEntry /f "printers.txt" /q /ge

    For /F "Tokens=3 delims=" %%I In ('type printers.txt ^| find /I "PRINTERNAME"') DO If "%%I"=="PRINTERNAME" GOTO SETDEFAULTPRT

    ping -n 2 -w 1000 > nul

    SET /A J=J+1

    IF %J%==30 GOTO QUIT



    ping -n 4 -w 1000 > nul

    rundll32 printui.dll,PrintUIEntry /y /nSERVERPRINTERNAME


    If EXIST printers.txt del printers.txt


    The purpose of the pings is to delay by a second less than the -n switch value (so never use a 1, since there would be no delay.) The ping with "-n 4" that is run even after the printer does get listed is there because setting it as default STILL didn't work right away, and I was willing to live with a permanent 3-second delay. The time delay isn't exact, but is good enough for this.

    This has worked so far in the little bit of testing I have done.

  14. Noj' Ttobba says:

    It works pretty well, but I have one query. If it's an existing user than it works with no problems. But if it's a new user, it will fail with the message “Operation could not be completed. Either the printer name was typed incorrectly, or the specified printer has lost its connection to the service.” But if they sign in again it works fine. Is there any way to get rid of the initial error. Thanks for the excellent info either way.

  15. Chris says:

    Great script works great when you want the same printer on a PC for everyone who logs onto it. Nice to use things like that instead of making registry entries all the time.

    However, I have an alternate situation. I just want an initial setting for all users but allow them to change to a different default printer if they want to without worrying about logging on again and having it change back.

    Copying profile settings to the windows default user didn't seem to change that but I'll have to double check. To make the change in the registry seems to have done what I needed it to do.

    To do that, make the default printer for a user (or admin) that is logged on already and check this registry key.

    HKEY_CURRENT_USERSoftwareMicrosoftWindows NTCurrentVersionWindows

    and compare the values to:

    HKEY_USERS.DEFAULTSoftwareMicrosoftWindows NTWindows

    Most likely you will only have to copy the setting for Device for the current user directly to the .DEFAULT users Device value. Otherwise, you can export that registry key "HKEY_CURRENT_USER", change it to "HKEY_USERS.DEFAULT", and import it.

    Thanks for the great info and I hope this alternative works for others with the same situation.

  16. Chris says:

    I have to apologize for my previous post. The default printer for all users isn't set this way. It has to be changed in the Default user registry hive.

    Here is a Microsoft Link on changing the 'Initial' default printer for all users.
    Next time I'll verify before posting.

  17. Kerry says:

    I can also recommend using the built-in vbs scripts. They're super easy and work, arguabley, just as well.

    Here's how to use it:

    1. Make a batch file, like instructed above

    2. put this in it:

    CScript c:WINDOWSsystem32prnmngr.vbs -p "PRINTER NAME HERE" -t


    3. Either put the bat file in the "All UsersStartup" folder, the default user's startup folder, or make it a login script like the above suggestion.

    There certainly is more than one way to skin this cat. 🙂

  18. Teehee says:

    the syntax i used for my local printer was "rundll32 printui.dll,PrintUIEntry /y /q /n DellLaserPrinter1100". I changed the printer name to contain no spaces not sure if that matters but this works fine. Thanks for the help.

  19. Rasean says:

    I see in comments that it works for wins7. I have users moving to department A and Department B. If I put this in the local GP will it default Department A printer even when user moves to Department B?

    Should I put this in Computer Configuration instead of User Configuration?

Leave a Reply

Your email address will not be published. Required fields are marked *