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

StackOverflow

Sponsored Links

Leave A Reply

Comments

Ed (Aug 15, 2008)

Can you show example?!

Mike McGillivry (Aug 20, 2008)

Hey just thought i would mention this works with Vista as well. Thanks for the info!

joe (Aug 27, 2008)

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

[HKEY_CURRENT_USERPrinters]

export that and all subtrees as 1st.reg

then save this one as 2nd.reg

[HKEY_CURRENT_USERSoftwareMicrosoftWindows NTCurrentVersionWindows]

"Device"="….."

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.

Vasken (Aug 28, 2008)

@joe,

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…

iladelf (Aug 29, 2008)

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.

iladelf (Sep 02, 2008)

So, can this be used for multiple printers?

Vasken (Sep 13, 2008)

@iladelf,

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….

Calvin (Oct 29, 2008)

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.

Marie (Nov 17, 2008)

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.

Vasken (Nov 17, 2008)

@Marie,

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.

Kari (Jan 29, 2009)

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! :-)

Perry Roberts (Feb 06, 2009)

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%

Vasken (Feb 07, 2009)

@Perry,

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.

Jay (Mar 18, 2009)

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

Jan Endre (Apr 06, 2009)

Works with Windows 7.0/Vista etc..

PERFECT

Bill (Apr 24, 2009)

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 (Apr 24, 2009)

@Bill,

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.

Bill (Apr 30, 2009)

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

:CHECKFORPRT

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 127.0.0.1 -n 2 -w 1000 > nul

SET /A J=J+1

IF %J%==30 GOTO QUIT

GOTO CHECKFORPRT

:SETDEFAULTPRT

ping 127.0.0.1 -n 4 -w 1000 > nul

rundll32 printui.dll,PrintUIEntry /y /nSERVERPRINTERNAME

:QUIT

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.

Noj' Ttobba (Feb 08, 2010)

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.

Chris (May 13, 2010)

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.

Chris (May 13, 2010)

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.
http://support.microsoft.com/kb/307016
Next time I'll verify before posting.

Vasken (May 14, 2010)

No problem. Thanks for double-checking and the followup comment. Hopefully this will help other readers in the same boat.

Kerry (Jul 28, 2010)

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

http://technet.microsoft.com/en-us/library/cc7258

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

exit

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. :)

Teehee (Jul 29, 2010)

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.

Where’d I leave that note? » Blog Archive » howto script windows default printer (Oct 16, 2010)

[...] Thanks to Gerry Lieberwirth’s post. and a post over at neverblog.net [...]

Jason (Nov 16, 2010)

This worked great, Vasken. Can't believe nobody in my IT org knew about this. Thanks!

Sam (Nov 29, 2010)

Kerry, Your script works perfectly! Thanks.

shrikrushna (Feb 15, 2012)

i have done right way but not successful

Sharjeel (Mar 02, 2012)

Works great, thanks! :)

Marina (Apr 18, 2012)

Thank you. Answer is direct. No hidden agenda’s. Very useful.

Rasean (Feb 08, 2013)

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?