Dynamic Network Printer Discovery and Administration via jcifs.samba.org.

R

Rob@Bedford

I am working on a large-scale reporting solution. One component is to
be able to scan the network for all printers and maintain a record of
these printers. I have read many, many posts on these forums with
similar questions, most of which do not have any answers. Below is the
progress I have made so far, hopefully someone can offer some
input/insight.

1. Finding Network Printers - I used jcifs to browse the network and
find all shared devices that were printers.

Code:

private static void findAllPrinters() throws Exception {
SmbFile root = new SmbFile("smb://domain;USR:pASS@domain");
Hashtable printerHash = new Hashtable();

searchForPrinters(root, printerHash);

Enumeration keys = printerHash.keys();
System.out.println("Number of Printers Found: " +
printerHash.size());
SmbFile file = null;
while (keys.hasMoreElements()) {
file = ((SmbFile)keys.nextElement());
System.out.println("UNC: " + file.getUncPath());
}
}

private static void searchForPrinters(SmbFile root, Hashtable
printers) throws Exception {
SmbFile[] kids= null;

try {
kids = root.listFiles();
} catch (Exception e) {

}
if (kids == null)
return;

for (int i = 0; i < kids.length; i++) {
if (kids.getType() == SmbFile.TYPE_WORKGROUP ||
kids.getType() == SmbFile.TYPE_SERVER)
searchForPrinters(kids, printers);
else if (kids.getType() == SmbFile.TYPE_PRINTER) {
printers.put(kids, Boolean.TRUE);
}
}
}


By doing this I can find each printer on my network that I can find
when I use windows control panel and search for network printers.

2. I can print a test to any printer successfully.
Code:

FileOutputStream fos = new
FileOutputStream("\\\\PrintShare\\MyPrinter"); //hardcoded for test,
but taken from output of part #1 above.
PrintStream ps = new PrintStream(fos);
ps.print("\r");
ps.print("This page will be printed directly to the printer.");
ps.print("\f");
ps.close();



3. This is where i need help. Continuing on what I have already
accomplished...
A. How can I create a more complex printer reference to allow me to
control number of copies, color vs. bw, page layout, page size, obtain
details from printer such as acceptable page sizes, data types
printable, etc.
B Be able to detect printer errors and if the page has completed.


And and all input and/or collaboration is apprecaited! I feel I am
close to finding the link, but not sure where to find the missing
puzzle piece.

Thx,
Rob
 
T

Thomas Weidenfeller

Rob@Bedford said:
3. This is where i need help. Continuing on what I have already
accomplished...

You have apparently chosen to go for a Windows-only solution. So I don't
see the point to do this in Java. Using native windows services and APIs
might be a better choice. The cross-platform Java printing APIs (there
are several) are something between just horrible and madly broken.

If you want to do it in cross-platform Java,
http://java.sun.com/j2se/1.5.0/docs/guide/jps/spec/JPSTOC.fm.html and
hope that your VM comes with a print service provider which can discover
all your printers on your Windows network (or try to find a third party
print service provider implementation which works for you).

/Thomas
 
R

Rob@Bedford

The network that this solution is being designed for is a windows
network, and it will be interracting with various other java programs
(hence my design choices thus-far). I have reviewed that website and
it repeats what a lot of the various sites say...

PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor,
aset);

However this only works if the printers (network or local printers) are
installed on the system. My goal is to dynamicially sniff out the
printers on the network (in my office there are approx. 45). In
"theory" I will do this and query the printers for their various data
flavors (PDF, PS, GIF) etc. and be able to tell the users which ones
offer which and even recommend a printer.
 
R

Rob@Bedford

Am currently researching JNDI and LDAP to see if this is a possible
avenue. Will continue to update my progress in case others are doing
something similar. As always, if you have input based on above feel
free to post. :)

Thx.
 
Joined
Dec 6, 2007
Messages
1
Reaction score
0
Hallo Rob.
I have the same problem, but found no way on the net.
I too have to sent print on specific network printer that are not directly connected to my server..
Have you found a solution ?
Thnx,
Paolo
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top