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
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
Comment