C# 列印機(jī)(打印機(jī))方法一
創(chuàng)新互聯(lián)是一家企業(yè)級(jí)云計(jì)算解決方案提供商,超15年IDC數(shù)據(jù)中心運(yùn)營(yíng)經(jīng)驗(yàn)。主營(yíng)GPU顯卡服務(wù)器,站群服務(wù)器,成都服務(wù)器托管,海外高防服務(wù)器,服務(wù)器機(jī)柜,動(dòng)態(tài)撥號(hào)VPS,海外云手機(jī),海外云服務(wù)器,海外服務(wù)器租用托管等。
C# 列印機(jī)(打印機(jī))方法二:
使用類(lèi):ManagementObjectCollection、ManagementObjectSearcher、ManagementObject、
Dictionary
private static ManagementObjectCollection queryCollection; private static string _classname = "SELECT * FROM Win32_Printer"; private static DictionaryGetPrinter() { Dictionary dict = new Dictionary (); ManagementObjectSearcher query = new ManagementObjectSearcher(_classname); queryCollection = query.Get(); int count = 0; foreach (ManagementObject mo in queryCollection) { string oldName = mo["Name"].ToString(); Console.WriteLine(oldName); if (IsChineseLetter(oldName, "來(lái)自")) { count++; string newName = "Printer_" + count.ToString(); Console.WriteLine("\n\r\n\r非法打印機(jī)名稱:" + oldName + "\n\r將改名為:" + newName); dict.Add(newName, mo); } } return dict; }