Client machines default printer name

Posted by Nishithraj under Regular Expressions on 3/3/2010 | Views : 10321 | Status : [Member] | Replies : 3
How do we get Client machines default printer name?

I know this is possible through the activeX object of javascript. But it's not advicible to use because it may be disabled at any time. Is there any other way in javascript or .NET?

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan



Responses

Posted by: Sagarp on: 3/3/2010 [Member] Bronze

Up
0
Down
public bool PrinterExists(string printerName)

{
bool retValue = false;
string searchQuery = "SELECT * FROM Win32_Printer";
// Select Printers from WMI Object Collections
ManagementObjectSearcher searchPrinters =
new ManagementObjectSearcher(searchQuery);

ManagementObjectCollection printerCollection = searchPrinters.Get();
//Checking for the printerName in the PrinterCollection
foreach(ManagementObject printer in printerCollection)
{
if ((printer.Properties["Name"].Value.ToString().ToLower().Equals(printerName.ToString().ToLower())))
{
retValue = true;
}

}
if (!retValue)
{
//Error Log
}
printerCollection.Dispose();
return retValue;

}


Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 3/3/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Hey Sagarp,

This is really crazy. Well, ManagementObject will only work for the server side when you do like this. The Client printers are not accessible through this way.

To Nishithraj,

Actually the problem is, you only have html and Javascript in the browser to work with the client. Because of security measures implimented in most of the browsers, you cant have access to devices directly.
There is no interface that invokes this. If there is a way, many of the sites would have been doing that.

Yes you are right, ActiveX / browser Addins are not good to work with. Its just because, no one will install your plugin to work with your site, if it is unavoidable. That means, you will be losing lots of your visitors.

Rather I recommend to go with Normal window.Print()
You might also use Silverlight or client end objects, but these are also not capable to invoke print, if the browser settings is modified with Full Trust to them. (And it totally dependent on the User)

:)

www.abhisheksur.com

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gttejas on: 3/18/2010 [Member] Starter

Up
0
Down
Hi,

I don't get your purpose to get client machine's printer.

if you want to print using it you can use following javascript.


function printdoc()
{

window.print();

};

Please mark this as ans. if it solve your query.




Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response