C#显示当前计算机所有打印机名称,同时获取指定打印机的状态比如缺纸、缺墨等,并且生成记录日志和数据库,发送邮件通知当前打印出错消息,打包成exe安装文件——(二)获取服务器所有打印机

//查询按钮中代码 
ManagementScope scope = new ManagementScope(ManagementPath.DefaultPath);
            scope.Connect();
            SelectQuery oSelectQuery = new SelectQuery();
            oSelectQuery.QueryString = @"SELECT Name FROM Win32_Printer";
            ManagementObjectSearcher oObjectSearcher = new ManagementObjectSearcher(scope, @oSelectQuery);
            ManagementObjectCollection oObjectCollection = oObjectSearcher.Get();
            this.listView1.View = View.List;
            this.listView1.BeginUpdate();


            foreach (ManagementObject oItem in oObjectCollection)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = oItem["Name"].ToString() + Environment.NewLine;
                this.listView1.Items.Add(lvi);
            }


            this.listView1.EndUpdate();

点击查询按钮获取本机所有打印机名称如图所示:

你可能感兴趣的:(C#显示当前计算机所有打印机名称,同时获取指定打印机的状态比如缺纸、缺墨等,并且生成记录日志和数据库,发送邮件通知当前打印出错消息,打包成exe安装文件——(二)获取服务器所有打印机)