C # method 2 of the printer:
Usage class: ManagementObjectCollection, ManagementObjectSearcher, ManagementObject, Dictionary
Private static ManagementObjectCollection queryCollection;
Private static string _ classname = "SELECT * FROM Win32_Printer ";
Private static Dictionary <string, ManagementObject> GetPrinter ()
{
Dictionary <string, ManagementObject> dict = new Dictionary <string, ManagementObject> ();
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, ""))
{
Count ++;
String newName = "Printer _" + count. ToString ();
Console. WriteLine ("\ n \ r illegal printer name:" + oldName + "\ n \ r will be renamed to:" + newName );
Dict. Add (newName, mo );
}
}
Return dict;
}
Author: "The Soul of Wolf"