Search this blog

Tuesday, June 2, 2009

Get Printer Details thru C# code

The Following Code displays all the properties of printer available in location system.

You will need to add System.Managment as a reference, To access Windows Management Instrumentation (WMI) which contains the infrastructure for management data and operations on Windows-based operating systems


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Management;

namespace Get_Printer

{

class Program

{

static void Main(string[] args)

{

string PriterQuery = "SELECT * from Win32_Printer";

ManagementObjectSearcher PrintSearcher = new ManagementObjectSearcher(PriterQuery);

ManagementObjectCollection PrinterCollection = PrintSearcher.Get();

foreach (ManagementObject printer in PrinterCollection)

{

foreach (PropertyData property in printer.Properties)

{

Console.WriteLine(string.Format("{0}: {1}", property.Name, property.Value));

}

}

Console.ReadLine();

}

}

}

No comments:

Post a Comment