473,405 Members | 2,415 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,405 software developers and data experts.

InstalledPrinters and Windows Server 2003 R2

I am using VB 2005 to get the printers that have been installed on a Windows
Server 2003 R2 box. I would like to write these printers into a table in SQL
Server. The problem is when I run the code using:
System.Drawing.Printing.PrinterSettings.InstalledP rinters and count and
item no printers are found. Printers are installed on the server and when I
run the same code on a Win XP box all installed printers are listed. Anyone
have any idea why the 2003 R2 box does not return the installed printers?
Any help would be greatly appreciated.
Marc
Jul 27 '08 #1
3 1546
Hi

I found that InstalledPrinters had problems when one or more printers had
different permissions to the others
I had to fall back on the EnumPrinters API. Maybe make sure that the user
running the code has the same permissions on all the printers?

Hope this helps,
Duncan
"Marc" <Ma**@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.com...
>I am using VB 2005 to get the printers that have been installed on a
Windows
Server 2003 R2 box. I would like to write these printers into a table in
SQL
Server. The problem is when I run the code using:
System.Drawing.Printing.PrinterSettings.InstalledP rinters and count and
item no printers are found. Printers are installed on the server and when
I
run the same code on a Win XP box all installed printers are listed.
Anyone
have any idea why the 2003 R2 box does not return the installed printers?
Any help would be greatly appreciated.
Marc
Jul 27 '08 #2
Thanks for your help Duncan. I decided to try what you have suggested using
the EnumPrinters API but I am having problems getting this API to work on the
Server 2003 R2 box. It works fine on XP. When the following code gets to
the EnumPrinters line it just stops and does not return an error. Am I using
the wrong lib for 2003 R2?

Private Declare Function EnumPrinters Lib "winspool.drv" Alias
"EnumPrintersA" (ByVal flags As Integer, ByVal name As String, ByVal Level As
Integer, ByRef pPrinterEnum As Integer, ByVal cdBuf As Integer, ByRef
pcbNeeded As Integer, ByRef pcReturned As Integer) As Integer

Private Structure PRINTER_INFO_4
Dim pPrinterName As String
Dim pServerName As String
Dim Attributes As Integer
End Structure

Dim PrinterEnum() As PRINTER_INFO_4, FNLoop As Integer = 0,
PRINTER_ENUM_LOCAL = &H2, pPrinterEnum() As Integer, cdBuf As Integer =
10000, pcbNeeded As Integer, pcReturned As Integer, ReturnValue As Integer
ReDim pPrinterEnum(0 To cdBuf / 4)

ReturnValue = EnumPrinters(PRINTER_ENUM_LOCAL, "", 4, pPrinterEnum(0),
cdBuf, pcbNeeded, pcReturned)

Thanks,
Marc
"Duncan Jones" wrote:
Hi

I found that InstalledPrinters had problems when one or more printers had
different permissions to the others
I had to fall back on the EnumPrinters API. Maybe make sure that the user
running the code has the same permissions on all the printers?

Hope this helps,
Duncan
"Marc" <Ma**@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.com...
I am using VB 2005 to get the printers that have been installed on a
Windows
Server 2003 R2 box. I would like to write these printers into a table in
SQL
Server. The problem is when I run the code using:
System.Drawing.Printing.PrinterSettings.InstalledP rinters and count and
item no printers are found. Printers are installed on the server and when
I
run the same code on a Win XP box all installed printers are listed.
Anyone
have any idea why the 2003 R2 box does not return the installed printers?
Any help would be greatly appreciated.
Marc
Jul 28 '08 #3
I can't see anything wrong with what you have there - however just in case
it is of use, my code is as follows:-

#Region "EnumPrinters"
<DllImport("winspool.drv", EntryPoint:="EnumPrinters", _
SetLastError:=True, CharSet:=CharSet.Auto, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)_
Public Function EnumPrinters(<InAttribute()ByVal Flags As
EnumPrinterFlags, _
<InAttribute()ByVal Name As String, _
<InAttribute()ByVal Level As Int32, _
<OutAttribute()ByVal lpBuf As IntPtr, _
<InAttribute()ByVal cbBuf As Int32, _
<OutAttribute()ByRef pcbNeeded As Int32,
_
<OutAttribute()ByRef pcbReturned As
Int32) As Boolean

End Function

<DllImport("winspool.drv", EntryPoint:="EnumPrinters", _
SetLastError:=True, CharSet:=CharSet.Auto, _
ExactSpelling:=False, _
CallingConvention:=CallingConvention.StdCall)_
Public Function EnumPrinters(<InAttribute()ByVal Flags As
EnumPrinterFlags, _
<InAttribute()ByVal Name As IntPtr, _
<InAttribute()ByVal Level As Int32, _
<OutAttribute()ByVal lpBuf As IntPtr, _
<InAttribute()ByVal cbBuf As Int32, _
<OutAttribute()ByRef pcbNeeded As Int32, _
<OutAttribute()ByRef pcbReturned As Int32) As
Boolean

End Function

#End Region

and is used thus:-
Public Sub New()
Dim pcbNeeded As Int32 '\\ Holds the requires size of the output
buffer (in bytes)
Dim pcReturned As Int32 '\\ Holds the returned size of the output
buffer
Dim pPrinters As IntPtr
Dim pcbProvided As Int32 = 0

If Not EnumPrinters(EnumPrinterFlags.PRINTER_ENUM_NAME,
String.Empty, 1, pPrinters, 0, pcbNeeded, pcReturned) Then
If pcbNeeded 0 Then
pPrinters = Marshal.AllocHGlobal(pcbNeeded)
pcbProvided = pcbNeeded
If Not EnumPrinters(EnumPrinterFlags.PRINTER_ENUM_NAME,
String.Empty, 1, pPrinters, pcbProvided, pcbNeeded, pcReturned) Then
Throw New Win32Exception
End If
End If
End If

If pcReturned 0 Then
'\\ Get all the monitors for the given server
Dim ptNext As IntPtr = pPrinters
While pcReturned 0
Dim pi1 As New PRINTER_INFO_1
Marshal.PtrToStructure(ptNext, pi1)
If Not pi1.pName Is Nothing Then
Me.Add(New PrinterInformation(pi1.pName,
PrinterAccessRights.PRINTER_ACCESS_USE, False)) ', pi2.pLocation,
pi2.pComment, pi2.pServerName, 1))
End If
ptNext = New IntPtr(ptNext.ToInt32 +
Marshal.SizeOf(GetType(PRINTER_INFO_1)))
pcReturned -= 1
End While
End If

'\\ Free the allocated buffer memory
If pPrinters.ToInt32 0 Then
Marshal.FreeHGlobal(pPrinters)
End If

End Sub

(The full code is in CodePlex : http://www.codeplex.com/PrintQueueWatch in
case I have missed anything in this cut-and-paste)

Hope this helps,
Duncan

"Marc" <Ma**@discussions.microsoft.comwrote in message
news:30**********************************@microsof t.com...
Thanks for your help Duncan. I decided to try what you have suggested
using
the EnumPrinters API but I am having problems getting this API to work on
the
Server 2003 R2 box. It works fine on XP. When the following code gets to
the EnumPrinters line it just stops and does not return an error. Am I
using
the wrong lib for 2003 R2?

Private Declare Function EnumPrinters Lib "winspool.drv" Alias
"EnumPrintersA" (ByVal flags As Integer, ByVal name As String, ByVal Level
As
Integer, ByRef pPrinterEnum As Integer, ByVal cdBuf As Integer, ByRef
pcbNeeded As Integer, ByRef pcReturned As Integer) As Integer

Private Structure PRINTER_INFO_4
Dim pPrinterName As String
Dim pServerName As String
Dim Attributes As Integer
End Structure

Dim PrinterEnum() As PRINTER_INFO_4, FNLoop As Integer = 0,
PRINTER_ENUM_LOCAL = &H2, pPrinterEnum() As Integer, cdBuf As Integer =
10000, pcbNeeded As Integer, pcReturned As Integer, ReturnValue As Integer
ReDim pPrinterEnum(0 To cdBuf / 4)

ReturnValue = EnumPrinters(PRINTER_ENUM_LOCAL, "", 4, pPrinterEnum(0),
cdBuf, pcbNeeded, pcReturned)

Thanks,
Marc
"Duncan Jones" wrote:
>Hi

I found that InstalledPrinters had problems when one or more printers had
different permissions to the others
I had to fall back on the EnumPrinters API. Maybe make sure that the
user
running the code has the same permissions on all the printers?

Hope this helps,
Duncan
"Marc" <Ma**@discussions.microsoft.comwrote in message
news:CB**********************************@microso ft.com...
>I am using VB 2005 to get the printers that have been installed on a
Windows
Server 2003 R2 box. I would like to write these printers into a table
in
SQL
Server. The problem is when I run the code using:
System.Drawing.Printing.PrinterSettings.InstalledP rinters and count
and
item no printers are found. Printers are installed on the server and
when
I
run the same code on a Win XP box all installed printers are listed.
Anyone
have any idea why the 2003 R2 box does not return the installed
printers?
Any help would be greatly appreciated.
Marc
Jul 28 '08 #4

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

Similar topics

6
by: Nathan Sokalski | last post by:
I want to set up SQL Server on Windows XP Pro so that I can use the database capabilities of ASP and IIS. I am probably using some incorrect settings, but I am not sure what they are. Here is what...
11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
2
by: Vaap | last post by:
I did lot of googling to see if I can solve the SQL server not found problem while trying to run ASP.Net community starter kit from an XP machine to Windows 2003 server hosting SQL server 2000...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
0
by: Martin Moser | last post by:
I've recently deployed my ASP.NET Application to a Win 2003 Server. In my application I am reading the installed printers from the InstalledPrinters Property. On my local machine I have no...
0
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". ...
2
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.)...
7
by: =?Utf-8?B?RWRkaWU=?= | last post by:
We have an odd situation with some of our single-threaded CPU-bound C++ programs. They run between 2 and 4 times faster on Windows XP than on windows Server 2003 on the same Xeon hyperthreading...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.