Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been tasked with troubleshooting a logon script at a client site that among other things sets the default printer. The logon script is vbscript with the printer being set using

Set WshNetwork = CreateObject("WScript.Network")



The tech who set it up said it was working. The customer said it wasn't. My testng shows hat it works only intermittently. Currently I've got something like this:

WScript.Echo GetDefaultPrinter
For i = 0 to 50
    if strPrinter <> GetDefaultPrinter then
    end if

Msgbox("Called WshNetwork.SetDefaultPrinter(" & strPrinter & ")")
WScript.Echo GetDefaultPrinter

Function GetDefaultPrinter
sComputer = "."
Set oWMIService = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set colItems = oWMIService.ExecQuery("Select * from Win32_Printer",,48)
For Each oItem in colItems
If (oItem.Attributes And 2^(3-1)) = 4 Then
sDefault = oItem.Name
Exit For
End If
GetDefaultPrinter = sDefault
End Function

This lets me check the default printer before and after attempting to change it. The loop seems to have helped, but has not resolved the problem entirely. Sometimes the new printer is correctly set, sometimes I can log off and on again and it can't set the same default printer. To clarify, I am not a full time admin. Is this technique out of date? Should I be using something else to set the default printer?

Edit: Additionally, we need to remember the default printer that the user may have set or changed during their user session and then set that printer as default

share|improve this question

Since you have Server 2008 and Windows 7, you have the ability to set a default printer through Group Policy Preferences. We're using that right now to set default printers in our computer labs. It does require creating a GPO for these containers, but you can get pretty granular with them.

In the Group Policy Editor, the policy is located at...

User Configuration -> Preferences -> Control Panel Settings -> Printers

Add printers in there. One of the check-boxes is "make default printer". It really works.

share|improve this answer
This is a good answer (+1) but I didn't mention one of the requirements: We want to allow the users to choose their own default printer. So, when the user logs off, we set an attribute (Attribite Editor in the user properties in AD Users and Computers), which is then read by the login script. That is the printer that is to be set as the default. The attribute appears to be saved and is read correctly. It is then setting the printer that is failing. Thanks for the input though – rotard Aug 11 '10 at 15:44
up vote 0 down vote accepted

Rather than using the Network object, I'm running the command directly: rundll32 printui.dll,PrintUIEntry /y /n "" seems to be working just fine

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.