Unfortunately, that technique won't work. The Win32_PrinterConfiguration
properties are read-only. You can set the PaperSize value because you're not
dealing with the PrinterConfiguration itself, but with a cached value
collection.
For WMI classes which _do_ have writable properties, you can use WMI's
Put_() method to write a modified instance back to the repository. Of
course, in this example, it will fail. If you do this:
For Each objItem in colItems
Wscript.Echo "PaperSize: " & objItem.PaperSize
objItem.PaperSize = 8
objItem.Put_()
Wscript.Echo "PaperSize: " & objItem.PaperSize
Next
The Put_ call will throw the error "SWbemObjectEx: Provider is not capable
of the attempted operation".
================
Approaches to setting the paper size
This is a problem that people have asked about repeatedly over the years,
and there's never been a simple out-of-box solution. I'm not totally aware
of the reasons, but I suspect its due to the fact that this is theoretically
a WMI-ish problem, but the core WMI infrastructure has never supported
general control over printer configuration details; that in turn is likely
due to the limited and inconsistent exposure of properties by printer OEMs
as a whole.
You have three options I can think of to get the results you need. Follow up
on what you can and we'll see if we can help.
(1) Use your CAD pacakge's capabilities
You didn't mention the name of the software package you use, but since it
supports VBScript it's apparently designed to be automated, and may expose
details for available printers internally. Could you tell us what it is, and
possibly post a link to the manufacturer's website?
This is a good option as a solution, since CAD is one problem domain where
printer sheet size control is important.
(2) Direct registry edit from script
A second option is finding out where the printer configuration data is
stored in the registry and in what format, and then modifying it directly.
There are general printer configuration details stored under , but its also
common for graphics applications such as art and CAD packages to set
specific configurations in their own software keys in the registry (possibly
under HKCU\Software\<appname> somewhere).
If your application does _not_ do this, things get complicated - too
complicated to be a good idea in my opinion; I suggest skipping to (3).
(3) Custom component
There are components that can manipulate printer settings directly for you.
Lee Peedin (a REXX guru who occasionally hangs out with us here) has one
such object that may be useful; it's PrinterObject2, which can be found on
his page here:
http://pragmaticlee.safedataisp.net/
Post by SubbuHi all,
could anyone suggest a way to set the paper size in default printer in vbs.
This is not for MSoffice printing, but a 3rd party ECAD software, which
supports 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