Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Printer
I need to get the HP printer status, I have written this code:
 
using System;
using System.Collections;
using System.Linq;
using System.Management;
using System.Text;
 
namespace PrinterStatus
{
    class Program
    {
        private static int asd;
        private static string[] printerStatus = { "Other", "Unknown", "Idle", "Printing", "WarmUp", "Stopped Printing", "Offline" };
        private static string[] printerState = {"Paused","Error","Pending Deletion","Paper Jam","Paper Out","Manual Feed","Paper Problem", "Offline","IO Active","Busy","Printing",
            "Output Bin Full","Not Available","Waiting", "Processing","Initialization","Warming Up","Toner Low","No Toner","Page Punt", "User Intervention Required",
            "Out of Memory","Door Open","Server_Unknown","Power Save"};
 
        private static string printerName = "PDFPrt";
 
        static void lala()
        {
            string query = string.Format("SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", printerName);
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
            ManagementObjectCollection coll = searcher.Get();
 
            foreach (ManagementObject printer in coll)
            {
                foreach (PropertyData property in printer.Properties)
                {
                    if (property.Name.Equals("ExtendedPrinterStatus"))
                    {
                        if (asd != Convert.ToInt32(property.Value))
                        {
                            Console.WriteLine(">>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<");
                            Console.ReadKey(true);
                        }
                        Console.WriteLine(string.Format("{0}: {1}", property.Name, printerStatus[Convert.ToInt32(property.Value)]));
                        asd = Convert.ToInt32(property.Value);
                    }
                }
            }
 
        }
        static void Main(string[] args)
        {
            while (true)
            {
                lala();
            }
        }
    }
}
 
By the way, it's just test code Smile | :) So, I opened this program, before I open the program I have put a big file to print, but, the return information of printer is always idle. I think the correct answer is printing or busy. How I can solve this? ( maybe it's a wrong code Frown | :( )
Posted 14-Feb-13 0:29am
Edited 14-Feb-13 5:45am
v2
Comments
Mike Meinz at 14-Feb-13 9:44am
   
My Guess
My guess is that it takes the Print Spooler some time to process your big print file. Depending on the settings of your print driver, the printer may not be busy until the Print Spooler (1) is done spooling all of the print data OR (2) has completed some amount of processing on the print data. After one of those two events (depending on the printer's configuration), actual printing will begin and then the printer will be busy.
Alexandre Bencz at 14-Feb-13 10:37am
   
ok, sorry my incompetence, but, how I can make this ????? :X :(
Mike Meinz at 14-Feb-13 16:25pm
   
It looks like this is a common problem.
See this message thread.
Sergey Alexandrovich Kryukov at 14-Feb-13 13:28pm
   
I never tried that, but this is the model question showing how a question should be asked: explanation of what you want to achieve, complete but short sample code, steps to reproduce, explanation of what was expected and what's wrong.
 
Even the code incorrect from the standpoint of a working application (spin wait with repeated lala and the sloppy name of this method) is quite fine for a code sample used to reproduce the problem. I would note that such sample code is possible even for UI, all it needs is just not using the designer.
 
My 5 for the question. I'll bookmark it and will probably use to explain people how to ask question. Unfortunately, we are overwhelmed by non-questions and totally incorrect ones...
Thank you,
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100