Deployment Solution

 View Only

Set Default Printer 

Jul 13, 2009 05:23 PM

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.

Statistics
0 Favorited
1 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Jul 16, 2009 02:27 AM

 

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, strDefaultPrinter
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 strDefaultPrinter
objNetwork.SetDefaultPrinter strDefaultPrinter

Jul 15, 2009 02:27 PM

I have my default printer name stored in a registry key.  Is there a way to create a VBS script that will query the key, set the keys value as a variable, and stick that variable into the script above?

I have done it with a BAT file:

:: delims is a TAB followed by a space
FOR /F "tokens=3 delims= " %%A IN ('REG QUERY "HKLM\Software\Path\To\Key" /v DefaultPrinterName') DO SET DefaultPrinterName=%%A
ECHO Name=%DefaultPrinterName%

ECHO Installing the Printer (%DefaultPrinterName%)...

start /W RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%DefaultPrinterName%"

Any ideas on how to do it with a VBS script?

Jul 15, 2009 10:17 AM

I believe the default printer setting is user-specific, so keep that in mind if multiple users use the machine.

Jul 14, 2009 03:55 AM

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 Next
strComputer = "."
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 strDefaultPrinter
objNetwork.SetDefaultPrinter strDefaultPrinter
' --- End Script ---

Related Entries and Links

No Related Resource entered.