如何获得它没有安装在我的系统从网络打印机? [英] How to get Printers from Network which is not installed in my system?

查看:128
本文介绍了如何获得它没有安装在我的系统从网络打印机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要搜索多少打印机在网络中可用。我已经安装了打印机性能检查,它给了我这是安装在我的系统上的打印机列表中。

I want to search how many printers are available in network. I have checked with Installed printer property and it gives me those printer list which are installed on my system.

我有我的网络的地方,因为它在我的系统安装在列表展示的唯一一个在两个以上的打印机。

I have more than two printers in my network where only one showing in list because it installed on my System.

如何从网络谁的驱动程序没有安装我的系统上或没有连接到我的系统的所有打印机列表中。

How to get all printer list from Network who's drivers are not installed on my system or not connected to my system.

推荐答案

我知道这个职位是很老,但我一直在用同样的问题作斗争

I know this post is quite old, but I've been battling with the same issue.

我最终设法解决它,我希望下面的代码可以帮助别人:

I eventually managed to solve it and I hope the code below helps someone:

        using(var ds = new DirectorySearcher())
        {
            ds.SearchRoot = new DirectoryEntry("");
            ds.Filter = "(|(&(objectCategory=printQueue)(name=*)))";

            ds.PropertiesToLoad.Add("printername");
            ds.PropertiesToLoad.Add("portname");
            ds.PropertiesToLoad.Add("servername");
            ds.PropertiesToLoad.Add("cn");
            ds.PropertiesToLoad.Add("name");
            ds.PropertiesToLoad.Add("printsharename");
            ds.ReferralChasing = ReferralChasingOption.None;
            ds.Sort = new SortOption("name", SortDirection.Descending);

            using(var src = ds.FindAll())
            {
                foreach(SearchResult sr in src)
                {
                    Console.WriteLine("------------------------------------");
                    Console.WriteLine(sr.GetDirectoryEntry().Name);
                    foreach (DictionaryEntry p in sr.Properties)
                    {
                        var propName = p.Key;
                        var propCollection = (ResultPropertyValueCollection)p.Value;
                        var propValue = propCollection.Count > 0 ? propCollection[0] : "";
                        Console.WriteLine(propName);
                        Console.WriteLine(propValue);
                    }
                    Console.WriteLine("------------------------------------");                        

                }

            }

        }

如果您想返回所有属性,看看有什么可用然后只需注释掉ds.PropertiesToLoad线,这将使你的完整列表。

If you want to return all the properties to see what's available then just comment out the ds.PropertiesToLoad lines and that will give you the full list.

这篇关于如何获得它没有安装在我的系统从网络打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆