Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dynamic Network Printer Discovery and Administration via jcifs.samba.org.

Reply
Thread Tools

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

 
 
Rob@Bedford
Guest
Posts: n/a
 
      04-21-2006
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;USRASS@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[i].getType() == SmbFile.TYPE_WORKGROUP ||
kids[i].getType() == SmbFile.TYPE_SERVER)
searchForPrinters(kids[i], printers);
else if (kids[i].getType() == SmbFile.TYPE_PRINTER) {
printers.put(kids[i], 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

 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      04-21-2006
Rob@Bedford wrote:
> 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/...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
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
 
 
 
Rob@Bedford
Guest
Posts: n/a
 
      04-24-2006
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.

 
Reply With Quote
 
Rob@Bedford
Guest
Posts: n/a
 
      04-26-2006
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.

 
Reply With Quote
 
brunasti brunasti is offline
Junior Member
Join Date: Dec 2007
Posts: 1
 
      12-06-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interesting Discovery: Changing volume via "break out box knob" does not prevent the screen saver from becoming active. Skybuck Flying Windows 64bit 0 01-03-2008 09:08 AM
How do you get feed discovery to work? I go to web pages I know has feeds, but the feed discovery button is disabled. Help! Tim Bryant Computer Support 1 02-13-2007 05:01 AM
Network printer: printer server vs direct network connection? alamoaudio@gmail.com Computer Support 3 09-20-2005 12:24 AM
dynamic discovery ??? Chris ASP .Net 0 11-12-2004 06:00 PM
lost use of network printer connceted via wireless network after p =?Utf-8?B?Ul9DX0Jyb3duX0py?= Wireless Networking 0 11-05-2004 08:34 PM



Advertisments