首页 新闻 会员 周边 捐助

System.Management.ManagementException 异常

0
悬赏园豆:30 [已解决问题] 解决于 2016-09-05 14:26
 ManagementScope ms = new ManagementScope(ManagementPath.DefaultPath);
                ms.Connect();
                SelectQuery sq = new SelectQuery();
                sq.QueryString = @"SELECT * FROM Win32_Printer";

                ManagementObjectSearcher mos =
                   new ManagementObjectSearcher(ms, sq);
                ManagementObjectCollection oObjectCollection = mos.Get();

                foreach (ManagementObject printer in oObjectCollection)
                {
                    PropertyDataCollection.PropertyDataEnumerator pde = printer.Properties.GetEnumerator();
                 
                    while (pde.MoveNext())
                    {
                        if (pde.Current.Value != null)
                        {
                            listBox1.Items.Add(pde.Current.Name + "-----------------" + pde.Current.Value);
                        }
                        //显示的是 属性名 : 属性值 的形式
                    }
                    listBox1.Items.Add("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                }

之后报异常:

Shen_小沈的主页 Shen_小沈 | 初学一级 | 园豆:56
提问于:2016-08-10 17:54
< >
分享
最佳答案
0

print spooler服务没开?

收获园豆:30
Daniel Cai | 专家六级 |园豆:10424 | 2016-08-11 10:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册