none
Updating Printer Properties RRS feed

  • Question

  • Hello.

    I am writing a program that allows the IT team to update various properties for users in AD and printers from the print server. 

    Everything else is working, apart from updating some printer properties. I can read in all of the printers that are on the server into a ListView control. But I'm not sure how to go about updating some of the properties for a selected printer.

    How can I update the Location, Description and Comments of the printer? All of the IT team (including myself) have full admin access to the Print Server. I have three text boxes, one for Location (txtLocation), one for Description (txtDescription) and one for Comments (txtComments).

    Any help would be greatly appreciated.

    Cheers,
    RD

    Tuesday, May 9, 2017 5:03 PM

All replies

  • Properties are changed with SetPrinter()

    (PRINTER_INFO_2 structure for example)

    (tested on a local printer on Windows 10)

    <DllImport("winspool.drv", EntryPoint:="SetPrinterW", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
        Private Shared Function SetPrinter(ByVal hPrinter As IntPtr, ByVal Level As Integer, ByVal pPrinter As IntPtr, ByVal Command As Integer) As Boolean
        End Function

    Tuesday, May 9, 2017 8:19 PM
  • Hi WHoAI99,

    According to your description, you want to update printer properties, please refer to the code below.

        Imports System.Drawing.Printing
        Imports PrinterSettingsCLI
    
        Public Class Form1
            Dim defprintername As String
            Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
                Dim allPrinters As System.Drawing.Printing.PrinterSettings.StringCollection = System.Drawing.Printing.PrinterSettings.InstalledPrinters
                For Each eachprinterName As String In allPrinters
                    Dim eachprintersetting As Printing.PrinterSettings = New Printing.PrinterSettings()
                    eachprintersetting.PrinterName = eachprinterName
                    If eachprintersetting.IsDefaultPrinter Then
                        defprintername = eachprinterName
                        TextBox1.Text = defprintername
                        If eachprintersetting.DefaultPageSettings.Landscape Then
                            RadioLandscape.Checked = True
                        Else
                            RadioPortrait.Checked = True
                        End If
                    End If
                Next
            End Sub
    
            Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
                Dim cliprintersettings As PrinterSettingsCLI.PrinterSettings = New PrinterSettingsCLI.PrinterSettings(TextBox1.Text) 'You can pass any other printer name if you want to 
                Dim retval As Boolean = cliprintersettings.Open()
                Dim orientation As PrinterSettingsCLI.Orientation = orientation.Portrait
                If (retval = True) Then
                    If RadioLandscape.Checked Then
                        orientation = orientation.Landscape
                    Else
                        orientation = orientation.Portrait
                    End If
                    retval = cliprintersettings.SetOrientation(orientation)
                End If
                If (retval = True) Then
                    MsgBox("Successful")
                    If orientation = orientation.Portrait Then
                        RadioPortrait.Checked = True
                    Else
                        RadioLandscape.Checked = True
                    End If
                Else
                    MsgBox("UnSuccessful, may be orientation setting is not supported for this printer")
                End If
                retval = cliprintersettings.Close()
                cliprintersettings.Dispose()
                cliprintersettings = Nothing
            End Sub
        End Class

    More detailed info, please refer to:

    https://www.experts-exchange.com/questions/28898559/VB-Net-Change-Default-Printer-Settings-by-code.html

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 10, 2017 7:58 AM
    Moderator