Click here to Skip to main content
15,912,932 members
Home / Discussions / C#
   

C#

 
GeneralRe: RichTextBox problem Pin
Pedram Behroozi11-Nov-08 23:29
Pedram Behroozi11-Nov-08 23:29 
GeneralRe: RichTextBox problem Pin
ScottM112-Nov-08 0:42
ScottM112-Nov-08 0:42 
QuestionAppending string to third last line in a text file Pin
sumit703411-Nov-08 18:51
sumit703411-Nov-08 18:51 
AnswerRe: Appending string to third last line in a text file Pin
J a a n s11-Nov-08 19:53
professionalJ a a n s11-Nov-08 19:53 
QuestionHow to detect printer status using C#. [modified] Pin
raja baireddy11-Nov-08 18:42
raja baireddy11-Nov-08 18:42 
AnswerRe: How to detect printer status using C#. Pin
Simon P Stevens11-Nov-08 23:45
Simon P Stevens11-Nov-08 23:45 
GeneralRe: How to detect printer status using C#. Pin
raja baireddy12-Nov-08 2:09
raja baireddy12-Nov-08 2:09 
GeneralRe: How to detect printer status using C#. Pin
raja baireddy12-Nov-08 2:16
raja baireddy12-Nov-08 2:16 
Actually to get the printer status I'm using the following code.
This code is written in c#


using System.Management;



ConnectionOptions oConn = new ConnectionOptions();
System.Management.ManagementScope oMs = new System.Management.ManagementScope(@"\root\cimv2", oConn);
System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("select PrinterState from Win32_Printer where Name = \"HP Color LaserJet 1600\"");//
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();

foreach (ManagementObject oReturn in oSearcher.Get())
{
//PrinterState returns a hex value but I use a string/int value
//
// state value
//------------------------------------------------
// Online 0
// Lid Open 4194432
// Out of paper 144
// Out of paper/Lid open 4194448
// Printing 1024
// Initializing 32768
// Manual Feed in Progress 160
// Offline 4096

string status1 = oReturn["PrinterState"].ToString();
int status = Convert.ToInt32(oReturn["PrinterState"]);

switch (status)
{
case 0:
label1.Text = "Online";
break;
case 1:
label1.Text = "Paused";
break;
case 4194432:
label1.Text = "Lid Open";
break;
case 144:
label1.Text = "Out of Paper";
break;
case 4194448:
label1.Text = "Out of Paper && Lid Open";
break;
case 1024:
label1.Text = "Printing";
break;
case 32768:
label1.Text = "Initializing";
break;
case 160:
label1.Text = "Manual Feed in Progress";
break;
case 1026:
label1.Text = "Document failed to print";
break;
case 1027:
label1.Text = "Printing paused";
break;
case 4096:
label1.Text = "Offline";
break;

default:
label1.Text = "unknown state";
break;
}


this.Refresh();

}



This code is working fine. But the problem is , if the printer is on , then it is returning value as '0'. Even i switch of the power to printer , then also it is returning 0. Here 0 means "online". I want to show the status as "off line", "no paper", "low paper". etc.


Regards,
Sekhar Reddy
GeneralRe: How to detect printer status using C#. Pin
Simon P Stevens12-Nov-08 2:50
Simon P Stevens12-Nov-08 2:50 
QuestionSine wave Pin
vinay_K11-Nov-08 18:07
vinay_K11-Nov-08 18:07 
QuestionDynamically creating calender Pin
aurosikhadas11-Nov-08 17:50
aurosikhadas11-Nov-08 17:50 
AnswerRe: Dynamically creating calender Pin
Brij11-Nov-08 18:26
mentorBrij11-Nov-08 18:26 
AnswerRe: Dynamically creating calender Pin
dan!sh 11-Nov-08 21:45
professional dan!sh 11-Nov-08 21:45 
QuestionPass Table Name Build Your Form ? Pin
Ahmed R El Bohoty11-Nov-08 17:38
Ahmed R El Bohoty11-Nov-08 17:38 
QuestionDispose or not? Pin
cocoonwls11-Nov-08 16:22
cocoonwls11-Nov-08 16:22 
AnswerRe: Dispose or not? Pin
Richard Blythe11-Nov-08 17:24
Richard Blythe11-Nov-08 17:24 
AnswerRe: Dispose or not? Pin
N a v a n e e t h11-Nov-08 17:29
N a v a n e e t h11-Nov-08 17:29 
AnswerRe: Dispose or not? Pin
Guffa11-Nov-08 23:32
Guffa11-Nov-08 23:32 
AnswerRe: Dispose or not? Pin
Scott Dorman12-Nov-08 4:21
professionalScott Dorman12-Nov-08 4:21 
AnswerRe: Dispose or not? Pin
cocoonwls17-Nov-08 17:46
cocoonwls17-Nov-08 17:46 
QuestionGenerate C# Symbols from IDE Pin
Ken Mazaika11-Nov-08 16:21
Ken Mazaika11-Nov-08 16:21 
AnswerRe: Generate C# Symbols from IDE Pin
Simon P Stevens11-Nov-08 23:32
Simon P Stevens11-Nov-08 23:32 
QuestionDatabase search engine code? Pin
Richard Blythe11-Nov-08 16:01
Richard Blythe11-Nov-08 16:01 
AnswerRe: Database search engine code? Pin
Ashfield11-Nov-08 20:59
Ashfield11-Nov-08 20:59 
QuestionAccess to the path is denied Pin
dec8211-Nov-08 15:50
dec8211-Nov-08 15:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.