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") ... WshNetwork.SetDefaultPrinter(strPrinter)
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 WshNetwork.SetDefaultPrinter(strPrinter) end if Next 'WshNetwork.SetDefaultPrinter("Fax") 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 Next 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