Solved

Changing paper size

Posted on 2012-03-14
11
1,460 Views
Last Modified: 2012-03-19
I'm running the following on Windows Server 2008 and I'm gettign an error message

Dim Wshshell, setprnwide132, myprinter

Set Wshshell= CreateObject("WScript.Shell")
myprinter = "\\costarprint01\u155c1-CostarDocuments"
setprnwide132 = "setprinter " & """" & myprinter & """" & " 2 " & """" & "pdevmode=dmpapersize=119" & """"

' size = 8 for A3, size 9 for A4 etc.

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

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

Line 9
The system cannot find the file specified

Any idea ?

Thanks
0
Comment
Question by:Bianchi928
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 37722864
Hi, I assume that's because it can't find setprinter.exe.  You'll need to make sure setprinter.exe is in your %path% environments variable paths.  Usually just the system32 folder (or if it's a 32 bit exe, C:\Windows\SysWow64).

Rob.
0
 

Author Comment

by:Bianchi928
ID: 37722885
Okay I've copied setprinter in c:\scripts on the server and modified the code

Dim Wshshell, setprnwide132, myprinter

Set Wshshell= CreateObject("WScript.Shell")
myprinter = "\\costarprint01\u208c2-CostarDocuments"
setprnwide132 = "c:\scripts\setprinter " & """" & myprinter & """" & " 2 " & """" & "pdevmode=dmpapersize=119" & """"

' size = 8 for A3, size 9 for A4 etc.

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

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

It doesn't coem with any erro, but doesn't do any change to the paper size.
I'm running it with admin login
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37722890
If you change
intRC = WshShell.Run(setprnwide132, 0, TRUE)

to
intRC = WshShell.Run("cmd /k " & setprnwide132, 1, True)

do you see any errors during the command execution?

Rob.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Bianchi928
ID: 37722937
Did that and it came with a dos script saying

Set printer on '\\costarprint01\u226c1-CostarDocuments' succeeded.


But after 2 mins comes up with an error box saying


Error returned from Setting the Printer  -1073741510
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 37722977
I think that error just means the command prompt was closed by the user.  Instead of closing the cmomand prompt with the X, type Exit at the prompt and see if that helps.

If that *does* help without error, change cmd /k to cmd /c and it should work.

Rob.
0
 

Author Comment

by:Bianchi928
ID: 37723015
Forgot to mention that it still didn't change the paper size. What I really want to change is:

Right click the printer, select printer properties, preferences , papersize

NExt

Click Advanced, Printing defaults, advanced, paper size

I have nearly 600 printers to do....

Cheers
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37723041
Above this:
intRC = WshShell.Run("cmd /k " & setprnwide132, 1, True)

put this
InputBox "About to run:", "Command", setprnwide132

and then when that comes up, copy and paste that command directly to a command prompt and see if it works.  You'll need to get that working first...

Rob.
0
 

Author Comment

by:Bianchi928
ID: 37723146
That's the result
=================

C:\Users\Administrator.RETAIL>c:\scripts\setprinter "\\costarprint01\u226c3-Cost
arDocuments" 2 "pdevmode=dmpapersize=119"

Set printer on '\\costarprint01\u226c3-CostarDocuments' succeeded.

C:\Users\Administrator.RETAIL>

==================
Still no change to the paper size
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37723286
So looking through the examples here:
http://www.windowsitpro.com/article/tips/jsi-tip-9675-setprinter-exe-is-a-command-line-tool-to-set-configurations-or-states-of-local-or-remote-printers-

one of them is this (which does it for all local printers):
SetPrinter "" 2 "pdevmode=dmPaperSize=9, dmPaperLength=2970, dmPaperWidth=2100, dmFormName=A4"

so maybe you need to specify more details about the paper size to match your 119 paper size setting.

Also, since it seems to set the "current user" properties, I assume this will only change the "Printing Preferences" settings, and not the "Printing Defaults".

Regards,

Rob.
0
 

Author Closing Comment

by:Bianchi928
ID: 37736582
Got me on the right path with all the tips . Stopping the spooler while running the script got
it to work fine.

Thanks
Cheers
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37739907
Nice find!  I wouldn't have thought to stop the spooler, make the change, then restart it.  Thanks for letting me know.

Rob.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question