Solved

Changing paper size

Posted on 2012-03-14
11
1,442 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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, f…

895 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

11 Experts available now in Live!

Get 1:1 Help Now