![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How to set Paper size in vbs Hi 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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to set Paper size in vbs 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/ "Subbu" <Subbu@xxxxxx> wrote in message news:ADADDA53-2C89-43F9-9FAD-07D1B11C8BB9@xxxxxx Quote: > Hi 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 > > > |
My System Specs![]() |
| | #3 (permalink) |
| | dissing the vb printer object... Alex K. Angelopoulos wrote: Quote: > (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/ > than a wrapper for the vb printer object. As you may also know, the vb printer object is the most DIS-respected part of (classic) vb, according many comments which appear (or did appear way back when classic vb was commonly used). In my earlier naive days, I also wrote a wrapper for the printer object, usable from script. After a while using the printer object I found the same frustrations and errors (gasp!) that others had reported on. And so I followed the conventional advice, and now do all my printing by using the system api -- which works fine. I know what you're thinking -- It wasn't the printer object, it was my wrapper that caused the problems. O.K., fair enough. The only way to settle that is for you to try and use the printer object for yourself. That being said, for something simple like changing the paper size, Lee Peedin's oontrol will probably work well enough. cheers, jw |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How to set Paper size in vbs "Alex K. Angelopoulos" <alex.k.angelopoulos@xxxxxx> wrote in message news:uo4xSJyGKHA.4004@xxxxxx Quote: > 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. > (http://forums.devx.com/archive/index.php/t-65710.html). I remember setting the printer orientation in my own VB program and finding something of an object with read only properties I had to work around. Does VBScript have something similar? |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How to set Paper size in vbs Guys, Thanks for the replies so far. I found out the way to accomplish this in VBS. 1. you need to download Windows resource kit tools. This is freely downloadable. http://www.microsoft.com/Downloads/d...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 "Eric" wrote: Quote: > > "Alex K. Angelopoulos" <alex.k.angelopoulos@xxxxxx> wrote in message > news:uo4xSJyGKHA.4004@xxxxxx Quote: > > 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. > > > (http://forums.devx.com/archive/index.php/t-65710.html). > I remember setting the printer orientation in my own VB program and finding > something of an object with read only properties I had to work around. Does > VBScript have something similar? > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Paper Size Stuck In Word Pad | Vista General | |||
| Regional Settings and Paper size? | Vista General | |||
| Page Setup - Paper Size question | Software | |||
| Legal paper size | Vista print fax & scan | |||
| Paper Size doesn't change | Vista print fax & scan | |||