System.Management.ManagementException 异常
2016-08-10 来自:莲烬重华 1 人回应
 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("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                }

之后报异常:

2016-08-11 来自:小妹咔咔

print spooler服务没开?

您的回应

你还未登陆,不能回应!登陆