Default Printer

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
Dave

Default Printer

Post by Dave » Sat Apr 19, 2003 3:23 am

I was trying to find the way to change the default printer and to verify that the default printer is indeed a correct one (one of many network printers in NT and in XP environment).

Have not been able to figure it out, so I would like to ask for help.

P.S. I found this, but it does not work because 'sp' won't display the printer windows in XP, and in NT, 'Send>DefaultPrinter' will only send the first character . . .

Set/Change the Default Printer
From: Marcus Tettmar [email protected]
Date: 22/08/00
//Enter the name of the printer you want to be
//the default on the next line
Let>DefaultPrinter=HP DeskJet 690C
Press CTRL
Press Esc
Release CTRL
Send>sp
WaitWindowOpen>Printers
Send>DefaultPrinter
Press ALT
Send>ff
Release ALT
WaitReady>0
CloseWindow>Printers

Dave

To the Mjtnet Support!

Post by Dave » Mon Apr 21, 2003 11:56 pm

I am still looking for a way to change the default printer, especially in XP.
Anyone has an idea?
Thanks

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Apr 22, 2003 6:55 am

Hi,

This script demonstrates how to do it programatically with VBScript. This script displays a list of printers and asks you to enter the printer number which it then sets as the default. Note the SetDefaultPrinter method which takes the printer number.


VBSTART

Sub DefaultPrinter

Dim Text, Title, i, j, tmp, printer
Dim Network, oDevices

' Create a new Network object to access Network properties
Set Network = CreateObject("WScript.Network")

' Read all printers
Set oDevices = Network.EnumPrinterConnections

Text = "Available printers" & vbCRLF
For i = 0 To oDevices.Count-1 Step 2
j = i
Text = Text & (i / 2) & vbTab
Text = Text & oDevices(i) & vbTab & oDevices(i+1) & vbCRLF
Next

' Show all available printers and allow a user selection
tmp = InputBox (Text,"Set default printer",0)

printer = oDevices(tmp * 2) ' select printer name

' Set the default printer
Network.SetDefaultPrinter printer

MsgBox "Set Default printer to " & printer, _
vbOkonly + vbInformation, Title

Set Network = Nothing

End Sub

VBEND

VBRun>DefaultPrinter
MJT Net Support
[email protected]

Dave1

Post by Dave1 » Wed Sep 03, 2003 12:38 am

That was a great script. Thanks.
The script, when run, prompt for manual selection.
However, I wish to be able to switch to another printer AUTOMATICALLY.
I tried by adding at the end of the script

WaitWindowOpen>Set Default printer
Send Character/Text>3
Press Enter
Press Enter


But of course that is not the right thing to do.
Please help.
Thanks

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Sep 03, 2003 10:01 am

Just change the following line:

tmp = InputBox (Text,"Set default printer",0)

To:

tmp = printer_number

set to whichever printer you want to be the default.
MJT Net Support
[email protected]

Dave1

Post by Dave1 » Wed Sep 03, 2003 10:53 pm

I'm gratefull.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts