Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set Paper size in vbs

770 views
Skip to first unread message

Subbu

unread,
Aug 12, 2009, 2:53:01 AM8/12/09
to
Hi all,
could anyone suggest a way to set the paper size in default printer in vbs.

I have used WMInterface to do this, but it is not setting the paper
size.(below is the code)

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_PrinterConfiguration",,48)
For Each objItem in colItems
Wscript.Echo "PaperSize: " & objItem.PaperSize
objItem.PaperSize = 8
Wscript.Echo "PaperSize: " & objItem.PaperSize
Next

It is outputting paper size as 8(A3) but, it does not printout in A3.

Can anyone suggest the correct way of setting the papersize or printer
properties?

thanks


Subbu

unread,
Sep 21, 2009, 1:54:01 AM9/21/09
to

I found out the way to accomplish this in VBS. Please follow the below
procedure.

1. you need to download Windows resource kit tools. This is freely
downloadable.

http://www.microsoft.com/Downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

Have a look at the help file also, in Allprograms-->windows resource kit
tools->Windows resource kit tools help.html

2. One of the tools in this took kit is, Setprinter.exe, spooler
configuration tool

3. Then I used the following code in VBS to achieve this.
Dim Wshshell, setpnra3, myprinter

Set Wshshell= CreateObject("WScript.Shell")
myprinter = "printer name"
setpnra3 = "setprinter " &_
"""" & myprinter & """" & " 2 " & """" & "pdevmode=dmpapersize=8" & """"
' size = 8 for A3, size 9 for A4 etc.

intRC = WshShell.Run(setpnra3, 0, TRUE)

if intRC <> 0 then
WScript.Echo "Error returned from Setting the Printer " & intRC
WScript.Quit
End If

4. Setprinter.exe can set printer settings to different levels. I have
used level "2" which has most of the printer settings, in pDevmode.
Remember, this sets "myprinter" to this new settings.

5. For the remote printers, if the access is denied, then you can not set
using this command. Work around to this is, Install the Remote pritner
locally, to a new local port( there is a procedure in Microsoft web site) and
then change the settings to this local printer. I have done this way, it
works fine.

6. Using this setprinter, you can set most of the printer settings(this is
not application based, will change the printer settings globally).
The following can be set:- in pdevmode
dmorientation = 1 (P) or 2 (L)
dmpapersize=9(a4), 8(a3)etc
dmcopies=1
dmdefaultsource=7
dmprintquality=600
dmcolor=1monochrome 2 color
dmduplex=1no.2 yes
dmyresolution=600
dmTToption=2 (True type fonts)
dmcollate=1 on 2 off
dmbitsperpel =4
dmICMmethod =1
dmICMintent=3
dmMediatype=1 plain

Hope this helps. If you have any issues, I will be glad to help, If I know.

regards

asdf

unread,
Dec 6, 2009, 4:10:29 AM12/6/09
to
Is seems 85 % of a paper worth a publication item.

Please shorten / refine it a little.

Then go through the pain to provide an alternative scripting language.

E.g. javascript.

----------------------------------------------

"Subbu" <Su...@discussions.microsoft.com> wrote in message
news:4FDA2E39-8752-4094...@microsoft.com...

gallus

unread,
Jan 11, 2010, 10:52:01 AM1/11/10
to
Hello,

i was very happy to find that good explanation. it works finw for the most
of my settings. but when i want to change "nup" (number of virtual pages on
physical page), i got the message of success but when i look into the printer
settings nothing is changed..? do you know why? i checked every level (0-9 )
and tried it with many different printers...

thanky and greats
gallus

0 new messages