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("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); }
之后报异常:
print spooler服务没开?