问题描述
有没有一种简单的方法来枚举在.NET中所有可见的网络打印机?目前,我展示PrintDialog类,以允许用户选择一个打印机。这问题是,本地打印机的显示,以及(连同XPS文档写入等等)。如果我可以枚举网络打印机我自己,我可以证明只有那些打印机的自定义对话框。
Is there a straightforward way to enumerate all visible network printers in .NET? Currently, I'm showing the PrintDialog to allow the user to select a printer. The problem with that is, local printers are displayed as well (along with XPS Document Writer and the like). If I can enumerate network printers myself, I can show a custom dialog with just those printers.
谢谢!
推荐答案
发现这个code <一个href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=148&AspxAutoDetectCookieSupport=1">here
private void btnGetPrinters_Click(object sender, EventArgs e)
{
// Use the ObjectQuery to get the list of configured printers
System.Management.ObjectQuery oquery =
new System.Management.ObjectQuery("SELECT * FROM Win32_Printer");
System.Management.ManagementObjectSearcher mosearcher =
new System.Management.ManagementObjectSearcher(oquery);
System.Management.ManagementObjectCollection moc = mosearcher.Get();
foreach (ManagementObject mo in moc)
{
System.Management.PropertyDataCollection pdc = mo.Properties;
foreach (System.Management.PropertyData pd in pdc)
{
if ((bool)mo["Network"])
{
cmbPrinters.Items.Add(mo[pd.Name]);
}
}
}
}
更新:
这个API函数可以枚举所有的网络资源,包括服务器,工作站,打印机,共享,远程目录等。
"This API function can enumerate all network resources, including servers, workstations, printers, shares, remote directories etc."
<一个href="http://www.planet-source-$c$c.com/vb/scripts/Show$c$c.asp?txt$c$cId=741&lngWId=10">http://www.planet-source-$c$c.com/vb/scripts/Show$c$c.asp?txt$c$cId=741&lngWId=10
这篇关于有没有一个.NET的方式来枚举所有可用的网络打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!