473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 \\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
Mar 25 '08 #1
1 2992
"Stephanie Doherty" <St**************@discussions.microsoft.comschrieb :
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'.

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

Mar 26 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrick Herb | last post by:
Hello, I'm trying to print the content of a RichTextBox from my VB 6 app. What I want is that the CommonDialog shows up, the user selects a printer and the content of the RichTextBox prints to...
5
by: Tom Berry | last post by:
We currently are trying our first transformation from VB6 to VB.Net. Of course, the Printer object is gone, but I'm having trouble finding the replacement syntax necessary to perform similar...
3
by: Jason | last post by:
Hi, I am new to windows api programming and I wanted to create a little utility program for myself in c using the mini gw compiler. I bought petzold's book, programming windows 5th edition. I...
0
by: Abubakar | last post by:
Hi Am having trouble in solving some problems. Thses ar (1). how can i call Readprinter API fuction using C#.Net or VB.Ne (2). Am writting a program that will enumerate the printers installed in...
2
by: Patrick Blackman | last post by:
Need c# example of the API EnumPrinters function.
3
by: Steve Armstrong | last post by:
I use the following code and can get all the correct printer information back for Printer_Info_1. However, when I try the same code for Printer_Info_2 or 5 I get a System.NullReferenceException....
2
by: PyongHopscotch | last post by:
Hi All I was just wondering if there was a better function/way to get information on all the printers currently installed than EnumPrinters. I only really need all the printer names but don't care...
3
by: PyongHopscotch | last post by:
Hi All I was just wondering if there was a better function/way to get information on all the printers currently installed than EnumPrinters. I only really need all the printer names but don't care...
9
by: id10t error | last post by:
Hello, I am going to be using a Symbol WT4090 to scan items. I need to printer a tag from the Zebra ql320 plus. I am trying to do this is Visual basic 2005. Does anyone know and good site to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.