Welcome, Guest

by Nitin on Tuesday, 18 May 2010
c# code to talk to a printer


public partial class Form1 : Form
       
{
                 
public Form1()
               
{
                       
InitializeComponent();
               
}

                 
private void btnDetect_Click(object sender, EventArgs e)
               
{
                       
string printerName = "CUSTOM VKP80 II"; // this is my printer name
                        memoPrintDetail
.Clear();  //memoPrintDetail is richTextBox to show my complete printer status later on

                        memoPrintDetail
.AppendText("Printer Name : " + printerName + "n");

                       
ManagementScope scope = new ManagementScope(@"rootcimv2");
                        scope
.Connect();

                       
// Select All Printers from my computer
                       
ManagementObjectSearcher searcher = new
                                         
ManagementObjectSearcher("SELECT * FROM Win32_Printer");
                       
ManagementObjectCollection collection = searcher.Get();

                       
foreach (ManagementObject printer in collection)
                       
{
                               
if (printer["Name"].ToString() == printerName)
                               
{
                                       
if (printer["WorkOffline"].ToString().ToLower().Equals("true")) // This code is working
                                       
{
                                                memoPrintDetail
.AppendText("Status : Offlinen");// This code is working
                                               
return;
                                       
}
                                       
else
                                       
{
                                                memoPrintDetail
.AppendText("Status : Onlinen");// This code is working
                                       
}                                      
                                       
MessageBox.Show(printer["ExtendedDetectedErrorState"].ToString()); // Always show "0" value
                                       
MessageBox.Show(printer["DetectedErrorState"].ToString()); // Always show "0" value
                               
}
                       
}
               
}
       
}



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering