Solved

Changing paper size

Posted on 2012-03-14
11
1,436 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
  • 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
 

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now