Personal computing discussed

Moderators: SecretSquirrel, just brew it!

 
steelcity_ballin
Gerbilus Supremus
Topic Author
Posts: 11971
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Win32_PrinterConfiguration

Tue Jun 09, 2009 8:00 am

Any pros here ever deal with this class? I can use it to query all my printers on the network from, say, VB.Net with no problem. But according to MS documentation its properties are readonly. I wrote a small program that will fill a dropdown with a few printers on the computer, then upon selected the printer, it will tell you it's properties such as if it is color or monochrome only, what it's current orientation is, etc.

The orientation is what I want to set programmatically, and it seems it sort of works. If I write out what the orientation is before anythign is set, it returns a "1" which is portrait. If I set it, and write it out again, it returns a "2" for landscape. However, if I go into my printer settings for that printer, it's still showing portrait, and it still prints portrait from my code.

 Try
            Dim objWMIService = GetObject("winmgmts:\\.\root\cimv2")
            Dim colPrinters = objWMIService.ExecQuery("Select * from Win32_PrinterConfiguration") ' where Name = '\\\\SERVER\\PRINTER_NAME'")
            For Each objPrinter In colPrinters
                objPrinter.PageSettings.Landscape = True
                MsgBox(objPrinter.orientation)
            Next
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | Asus 970GTX | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W | Asus ROG Swift Gsync 27"
 
SecretSquirrel
Minister of Gerbil Affairs
Posts: 2159
Joined: Tue Jan 01, 2002 7:00 pm
Location: The Colony, TX (Dallas suburb)
Contact:

Re: Win32_PrinterConfiguration

Tue Jun 09, 2009 6:06 pm

I expect that it is only setting the orientation property for that instance of the object. If you printed something with the "objPrinter" after changing the orientation, I expect it would be honored. However, it is not changing the printer default settings.

--SS
 
steelcity_ballin
Gerbilus Supremus
Topic Author
Posts: 11971
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Win32_PrinterConfiguration

Thu Jun 11, 2009 11:09 am

Well I believe you are correct, and I found a better solution. The PrintDocument object provides support for things of this nature, and actually has a fairly clean implementation. The difficulty then is "how do I tell the browser to print using the PrintDocument object?" Well I haven't gotten it working just yet but I believe that by using the graphics namespace I can draw the contents of the browser and then call that to print. Should work.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | Asus 970GTX | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W | Asus ROG Swift Gsync 27"

Who is online

Users browsing this forum: No registered users and 2 guests