Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing paper size

Posted on 2012-03-14
11
Medium Priority
?
1,539 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
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

886 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