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