//获取安装在本地计算机的所有打印机的状态
public static string [,] GetPrinterStatus()
{
int i = PrinterSettings.InstalledPrinters.Count,j=0;
string [,] strInfo =new string [i,2];
string printStatus = null;
ManagementObjectCollection printers = new ManagementClass("Win32_Printer").GetInstances();
foreach (ManagementObject printer in printers)
{
string printername=printer["Name"].ToString(),
printerstatus=printer["PrinterStatus"].ToString();
switch (printer["PrinterStatus"].ToString())
{
case "1": printStatus = "Other"; break;
case "2": printStatus = "Unknown"; break;
case "3": printStatus = "Idle"; break;
case "4": printStatus = "Printing"; break;
case "5": printStatus = "Warmup"; break;
case "6": printStatus = "Stopped"; break;
case "7": printStatus = "Offline"; break;
}
strInfo[j,0] = printer["Name"].ToString();
strInfo[j,1]= printStatus;
j++;
}
return strInfo;
}