I needed to find a way to set the default printer via a Deployment Console job. I have found a few different ways of doing it. The first is a vbs script: Set WSHNetwork = CreateObject("WScript.Network") WSHNetwork.SetDefaultPrinter "[PRINTER_NAME]" For more info check out this web site: http://www.intelliadmin.com/blog/2007/08/set-default-printer-from-script.html The second can be used in the command prompt: start /W RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "[Printer_Name]" For more information check out this web site: http://www.robvanderwoude.com/2kprintcontrol.php You can even enter in the server location for a printer, it needs to be in this format: \\Path\Printer_Name This script works well and most importantly it does the job.
This vbs does the same thing as your bat. You need to make som changes in the script if the registry key is not located in HKEY_LOCAL_MACHINE and the value is not a string value. The Hey, Scripting Guy! Archive have been very useful for me. It makes learning vbs so much easier.
HKEY_LOCAL_MACHINE = &H80000002 strComputer = "."Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")strKeyPath = "SOFTWARE\Test"ValueName = "Printer"objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, ValueName, strDefaultPrinterSet objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colPrinters = objWMIService.ExecQuery _("Select * From Win32_Printer Where Local = TRUE")Set objNetwork = CreateObject("WScript.Network")objNetwork.AddWindowsPrinterConnection strDefaultPrinterobjNetwork.SetDefaultPrinter strDefaultPrinter
I have done something similar. I use the script below in GPO. GPO -> User Configuration -> Windows Settings -> Scripts (Logon/Logoff) -> Logon. In the "Add a Script" dialog, type DefaulPrinter.vbs in "Script Name" and type \\server\printer in "Script Parameters".
' DefaultPrinter.vbs ' --- Start Script --- On Error Resume NextstrComputer = "."strDefaultPrinter = Wscript.Arguments.Item(0)Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colPrinters = objWMIService.ExecQuery _ ("Select * From Win32_Printer Where Local = TRUE")Set objNetwork = CreateObject("WScript.Network")objNetwork.AddWindowsPrinterConnection strDefaultPrinterobjNetwork.SetDefaultPrinter strDefaultPrinter' --- End Script ---