Sign in to follow this  
Followers 0
emendelson

Default paper size of current printer?

3 posts in this topic

I'm working on a script that will use some freeware software to create a PDF file and then print it to the default printer (or a printer selected by the user). In order to do this correclty, I need to get the default page size (typically letter in North America or A4 elsewhere) of the current printer. Is this possible through WMI or the registry? I've spent a lot of time searching for the answer and haven't found it.

Alternatively, I suppose I could check whether the system is set up for North America or Europe by testing for the DOS codepage, in this registry entry:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\Nls\Codepage\OEMCP

If it yields 437, then the system is setup for North America, if not, elsewhere, but I'd prefer a more direct method, and will be grateful for any help.

Share this post


Link to post
Share on other sites



Look at WMI - Win32_Printer

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394363%28v=vs.85%29.aspx

Property: CurrentPaperType Data type: string Access type: Read-only

Type of paper the printer is using. Must be expressed in the form specified by the ISO/IEC 10175 Document Printing Application (DPA), which is summarized in Appendix C of RFC 1759 (Printer MIB).

example of use for Win32_Printer

Func GetDefaultPrinter()

    Local $result,$strComputer,$np,$colEvents
    $result = ''

    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootcimv2")

    $colEvents = $objWMIService.ExecQuery _
            ("Select * From Win32_Printer Where Default = TRUE");TRUE
    $np = 0

    For $objPrinter in $colEvents
        $result = $objPrinter.DeviceID
    Next

    Return $result
EndFunc

Share this post


Link to post
Share on other sites

Thank you for that. Unfortunately, if I replace "DeviceID" with anything that indicates paper sizes or types, I get an empty result. I've tried "CurrentPaperType" and "DefaultPaperType", and they both say nothing. Am I doing anything wrong?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0