syntax for EnumPrinters printer object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U3RlcGhhbmllIERvaGVydHk=?=

    syntax for EnumPrinters printer object

    Hello World,

    I am trying to get all the shared printers for a remote Windows 2003 server
    using the EnumPrinters function and keep getting an error returned that
    corresponds to the message: "The filename, directory name, or volume label
    syntax is incorrect". I've tried hard-coding a value of a valid server in the
    form \\hcr591plotpa0 01 (and tried it without the \\) but it doesn't seem to
    make a difference.

    My code looks like this:

    ---------------------

    Public Const PRINTER_LEVEL_1 = &H1
    Public Const PRINTER_ENUM_SH ARED = &H20
    Public Const PRINTER_ENUM_NA ME = &H8

    <DllImport("win spool.drv", EntryPoint:="En umPrintersA", _
    SetLastError:=T rue, CharSet:=CharSe t.Unicode)Publi c Shared Function _
    EnumPrinters(By Val flags As Int32, ByVal pName As String, ByVal Level _
    As Int32, ByVal pPrinterEnum As IntPtr, ByVal cbBuf As Int32, ByRef _
    pcbNeeded As Int32, ByRef pcReturned As Int32) As Int32
    End Function

    Public Sub getServerPrinte rs()
    Dim pcbNeeded As Int32 = 0
    Dim pcReturned As Int32 = 0
    Dim outC As IntPtr = IntPtr.Zero
    Dim flag As Int32= PRINTER_ENUM_NA ME Or PRINTER_ENUM_SH ARED
    Dim selectedItem As Object
    Dim server As String

    selectedItem = "\\" & CmB_Servers.Sel ectedItem
    server = selectedItem.To String()
    If Not EnumPrinters(fl ag, server, PRINTER_LEVEL_1 , outC, 0,
    pcbNeeded, pcReturned) Then
    Dim errorMessage As String = New
    Win32Exception( Err.LastDllErro r).Message
    MsgBox(errorMes sage)
    End If
    .....
    End Sub


    -------


    Any ideas what is wrong with the machine name I'm sending?

    Thanks,
    Stephanie
  • Herfried K. Wagner [MVP]

    #2
    Re: syntax for EnumPrinters printer object

    "Stephanie Doherty" <StephanieDoher ty@discussions. microsoft.comsc hrieb:
    I am trying to get all the shared printers for a remote Windows 2003
    server
    using the EnumPrinters function and keep getting an error returned that
    corresponds to the message: "The filename, directory name, or volume label
    syntax is incorrect". I've tried hard-coding a value of a valid server in
    the
    form \\hcr591plotpa0 01 (and tried it without the \\) but it doesn't seem
    to
    make a difference.
    >
    My code looks like this:
    >
    ---------------------
    >
    Public Const PRINTER_LEVEL_1 = &H1
    Public Const PRINTER_ENUM_SH ARED = &H20
    Public Const PRINTER_ENUM_NA ME = &H8
    >
    <DllImport("win spool.drv", EntryPoint:="En umPrintersA", _
    SetLastError:=T rue, CharSet:=CharSe t.Unicode)Publi c Shared Function _
    EnumPrinters(By Val flags As Int32, ByVal pName As String, ByVal Level _
    As Int32, ByVal pPrinterEnum As IntPtr, ByVal cbBuf As Int32, ByRef _
    pcbNeeded As Int32, ByRef pcReturned As Int32) As Int32
    End Function
    >
    Public Sub getServerPrinte rs()
    Dim pcbNeeded As Int32 = 0
    Dim pcReturned As Int32 = 0
    Dim outC As IntPtr = IntPtr.Zero
    Dim flag As Int32= PRINTER_ENUM_NA ME Or PRINTER_ENUM_SH ARED
    Dim selectedItem As Object
    Dim server As String
    >
    selectedItem = "\\" & CmB_Servers.Sel ectedItem
    server = selectedItem.To String()
    If Not EnumPrinters(fl ag, server, PRINTER_LEVEL_1 , outC, 0,
    pcbNeeded, pcReturned) Then
    Dim errorMessage As String = New
    Win32Exception( Err.LastDllErro r).Message
    MsgBox(errorMes sage)
    End If
    ....
    End Sub
    'EnumPrintersA' is the ANSI version of the function, but you are specifying
    the Unicode character set.

    In addition, you do not specify a valid buffer in the 'pPrinterEnum'
    parameter. Note that the 'cbBuf' parameter should contain the length of the
    buffer pointed to by 'pPrinterEnum'.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    Working...