syntax for EnumPrinters printer object


S

Stephanie Doherty

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 \\hcr591plotpa001 (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_SHARED = &H20
Public Const PRINTER_ENUM_NAME = &H8

<DllImport("winspool.drv", EntryPoint:="EnumPrintersA", _
SetLastError:=True, CharSet:=CharSet.Unicode)> Public Shared Function _
EnumPrinters(ByVal 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 getServerPrinters()
Dim pcbNeeded As Int32 = 0
Dim pcReturned As Int32 = 0
Dim outC As IntPtr = IntPtr.Zero
Dim flag As Int32= PRINTER_ENUM_NAME Or PRINTER_ENUM_SHARED
Dim selectedItem As Object
Dim server As String

selectedItem = "\\" & CmB_Servers.SelectedItem
server = selectedItem.ToString()
If Not EnumPrinters(flag, server, PRINTER_LEVEL_1, outC, 0,
pcbNeeded, pcReturned) Then
Dim errorMessage As String = New
Win32Exception(Err.LastDllError).Message
MsgBox(errorMessage)
End If
.....
End Sub


-------


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

Thanks,
Stephanie
 
Ad

Advertisements

H

Herfried K. Wagner [MVP]

Stephanie Doherty said:
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 \\hcr591plotpa001 (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_SHARED = &H20
Public Const PRINTER_ENUM_NAME = &H8

<DllImport("winspool.drv", EntryPoint:="EnumPrintersA", _
SetLastError:=True, CharSet:=CharSet.Unicode)> Public Shared Function _
EnumPrinters(ByVal 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 getServerPrinters()
Dim pcbNeeded As Int32 = 0
Dim pcReturned As Int32 = 0
Dim outC As IntPtr = IntPtr.Zero
Dim flag As Int32= PRINTER_ENUM_NAME Or PRINTER_ENUM_SHARED
Dim selectedItem As Object
Dim server As String

selectedItem = "\\" & CmB_Servers.SelectedItem
server = selectedItem.ToString()
If Not EnumPrinters(flag, server, PRINTER_LEVEL_1, outC, 0,
pcbNeeded, pcReturned) Then
Dim errorMessage As String = New
Win32Exception(Err.LastDllError).Message
MsgBox(errorMessage)
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'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top