## Subscribe

Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

# Set default printer from a script

by on August 9, 2007 · 17 comments

in Windows

.

I helped do some IT work at an Insurance company over the weekend. A friend of mine is an IT manager there. I will take any chance I can to poke around a real life corporate network (Instead of playing around with a farm of Virtual Machines)…so it was worth the extra work.

One of the problems they had was a dead printer. We needed to move a group of users to an alternate one and needed an easy way to set the default printer without knowing all the passwords to everyone’s account.

After a quick search I came up with this VB Script:

Set WSHNetwork = CreateObject(“WScript.Network”)
WSHNetwork.SetDefaultPrinter “[PRINTER_NAME]”

We updated the script so [PRINTER_NAME] was the name of the printer we wanted as our default. To find the correct name, simply open the Printers and Faxes icon in the control panel.

Use the exact words you see under the printer. So for example, if I wanted to set the Laserjet 4500 as my default, the script would look like this:

Set WSHNetwork = CreateObject(“WScript.Network”)
WSHNetwork.SetDefaultPrinter “HP Color LaserJet 4500”

Then I saved the script to a network shared and named it update.vbs (Share name was \\serverdc\printer)

In the users logon script I added this line:

cscript.exe \\serverdc\printer\update.vbs

Now when the users login they will have the new printer as their default.

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

1 cypherx January 22, 2010 at 9:11 am

Help!

Microsoft (R) Windows Script Host Version 5.8

c:\defprinter.vbs(1, 31) Microsoft VBScript compilation error: Invalid character

Windows 7 Professional x64.

Set WSHNetwork = CreateObject(“WScript.Network”)
WSHNetwork.SetDefaultPrinter “IT-PRINTER”

2 Steve Wiseman January 27, 2010 at 3:56 pm

This is from the blogging software we use here. You will need to erase the quotes and re-write them yourself…the quotes in the blog are a special kind that are not recognized by the script engine.

3 Adam February 16, 2010 at 10:58 am

Microsoft (R) Windows Script Host Version 5.7

c:\dp2.vbs(2, 1) Microsoft VBScript runtime error: Object required: ‘WSHNetork’

Help!

Thank You

4 Steve Wiseman February 16, 2010 at 11:04 am

You have a typo WSHNetork should be WSHNetwork

5 Steve K. June 22, 2010 at 12:53 pm

There’s some other items to consider for that network printer. This should be the full blown script if you were to have users in a multi-server environment. I don’t see success in using that script for a multi-server environment.

Batch Script
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~
@ECHO OFF
::Replace CompanyName With your company’s real name
TITLE COMPANYNAME LOGON SCRIPT
:: echo off will hide the actions of the logon scripts
ECHO. PERFORMING OTHER ACTIONS
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~
You can remove all of the lines that use ::, they are just notes for anyone using the script.

~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~
Set WSHNetwork = CreateObject(“WScript.Network”)
WSHNetwork.SetDefaultPrinter “\\serverdc\HP Color LaserJet 4500”
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~

Store them in this location:
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~
\\ServerDC\netlogon
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~
The local drive location on the domain controller is C:\Windows \ Sysvol \ Sysvol \ Domain.com \ Scripts

Group Policy Deployment
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~
User Configuration \ Windows Settings \ Scripts (Logon/Logoff) \ Logon
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~ ~~~~~~~

Obviously replace serverdc with your own real Domain Controller in your business throughout all of the steps here.

6 Steve K. June 22, 2010 at 12:55 pm

I’m sorry, objNetwork should be WSHNetwork, I don’t normally use WSH network but I was trying to make it as close to your script as possible.

7 Steve Wiseman June 22, 2010 at 1:36 pm

Thanks for the post. Really appreciated. I have updated your code so it has WSHNetwork for the objects.

8 Trev August 11, 2010 at 8:53 am

Can you advise on the syntax for Windows 7 due to the UAC restrictions my Pre-Win 7 script doesnt work. any thought on getting this to run as admin with out hard coding the admin user s password??

9 Trev August 12, 2010 at 4:03 am

After some additional research I have noted that you can not disable the UAC on the fly
I will have to look at getting the script run as ADMIN some how.
PS: my script takes a 3 digit entry and uses that to create the 2 and 3 octect of an IP to generate the ip addy of the printer.
The driver make and model is pre defined in the script so it looks in the printer repository fromt eh printer driver. if it cant find it it downloads the driver from the F&P server and begins the install… names the printer and logs the event inc. time dates and signed on user.

10 Johan M September 11, 2010 at 3:47 am

I reduced the logon script to just this line:

When I run the script (Win 2008 R2), I get a Syntax error 800A03EA, first line, 9th character.
Any ideas?
Do I have to include the “.local”?

11 Karthik September 13, 2011 at 3:58 pm

i am using this script, but it is unable to set it to default. The printer name is as follows :K2Printer2Backup on http://abc.def.abdc.edu:631
code as follows:
Set WSHNetwork = CreateObject(“Wscript.Network”)
WSHNetwork.SetDefaultPrinter “\\K2Printer2Backup on http://abc.def.abdc.edu:631

12 Zunair March 8, 2012 at 11:57 am

Get the printer name from here…
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\Devices

Set WSHNetwork = CreateObject(“WScript.Network”)
WSHNetwork.SetDefaultPrinter “[Printer Name]”

13 Zunair March 8, 2012 at 12:08 pm

also after copying the code make sure you replace quotes with quotes in notepad…

Note: The code here has unicode quotes… when you copy the code from here it copies bad characters.

14 Rob June 21, 2012 at 6:44 am

Zunair = STAR MAN!!!

Thanks!

15 Sainaveen July 10, 2013 at 8:18 pm

i want a script to check the default printer on multiple servers and save the log in text file.
Can you make it for me…Please

16 Steve Wiseman July 12, 2013 at 11:00 am

Hi Sainaveen,

This would be your vbs script:

 strComputer = "."

 Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\cimv2") Set colPrinters = objWMIService.ExecQuery _ ("Select * From Win32_Printer Where Default = TRUE") 

For Each objPrinter in colPrinters Wscript.Echo objPrinter.ShareName Next 

Then you could run it like this in a logon script:

cscript.exe \\server\share\def_printer.vbs >> \\server\share\printer_list.txt

Steve

17 Twister December 18, 2013 at 4:26 am

Hi

i need a script what set the printer settings to “Print Monocrome”
and that on all Printers on a PC
can you help me ?

I use WIndows XP an d IWndows 7 PC´s

Thx

Category Links - Windows Forum - Exchange Forum