CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Is Printer Online

    I've come across a very wierd issue with Vista..

    If my USB receipt printer is not Plugged in when a print job is sent, the job is sent out into the unknown ... and lost forever .... with out any sort of error....

    A little testing and playing around i found that if i manually set the "Use Printer Offline" Check .. all print jobs are queued, and wait for the printer to come back online.. If i clear the Check while the printer is still not available, Again all the jobs are sent out into the unknown...

    NOW .... The decision is to check if the Printer is Available, and if not to prompt the user to make it available or cancel the print ...

    However digging through all the printer object's i'm still to find the correct property's to check this..

    Help !!! where do i check if a specified printer is available... (IE. Plugged in and switched on)..

    Thanks

    Gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Is Printer Online

    Maybe you can use a WMI object like this guy:
    http://bytes.com/forum/thread347497.html
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Is Printer Online

    Great find Hairy!

    You could also use the OpenPrinter API along with the PRINTER_INFO_2 structure to determine if a printer is available or not

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Is Printer Online

    Thanks..

    However this returns does not realy return correct info, Acctualy I get strange results with it..

    Quote Originally Posted by Results from Codesnip
    Send To OneNote 2007: waiting (idle)
    Microsoft XPS Document Writer: waiting (idle)
    EPSON TM-T88IV Receipt: unknown state
    \\MARTIN\HP DeskJet 840C/841C/842C/843C: waiting (idle)
    \\RICHARD\HP LaserJet 5: waiting (idle)
    \\SYNCFIREWALL1\Brother MFC9600/9870 Series: waiting (idle)
    I have 3 printers setup according to what network i'm attached to ..
    Brother = Office Network
    HP LaserJet = Home Network
    HP DeskJet = Clients Network

    And the Epson is the USB One. (above result = USB cable out)..

    However, of the three printers that are connected to 3 Very different Networks, it shows that all three are available to print too.. With the reciept printer i cant take the chance that the receipt printer might be networked (two (or more) units sharing a Printer), and this code snip Fails when it comes to Networked printers..

    Surprisingly this code snip is Found 19 times in google, on different forums, even on a thread asking about networked printer status..

    I need to be able to get info like what the control panel has IE..


    Here you can see that 3 printer objects are "Ready", One is "Not Avail" , and two are essentially unknown ..


    After plugging in the USB printer is becomes ready..

    I'm still looking into the WMI code to see if i can find something else that will return correct results, however WMI.PrinterStatus is not quite good enough..

    Thanks

    Gremmy..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: Is Printer Online

    I think Hannes' call of using the API could be a good avenue for you:
    http://www.codeproject.com/KB/printi...atchvbnet.aspx
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Is Printer Online

    Have you tried the Api I suggested ¿

    The following is a list of APIs Structures and constants needed :
    APIs :

    Code:
    OpenPrinter
    FindFirstPrinterChangeNotification
    FindNextPrinterChangeNotification
    Structures :
    Code:
    PRINTER_NOTIFY_INFO 
    PRINTER_NOTIFY_INFO_2
    Constants :
    Code:
        JOB_NOTIFY_FIELD_PRINTER_NAME = &H0 
        JOB_NOTIFY_FIELD_MACHINE_NAME = &H1 
        JOB_NOTIFY_FIELD_PORT_NAME = &H2 
        JOB_NOTIFY_FIELD_USER_NAME = &H3 
        JOB_NOTIFY_FIELD_NOTIFY_NAME = &H4 
        JOB_NOTIFY_FIELD_DATATYPE = &H5 
        JOB_NOTIFY_FIELD_PRINT_PROCESSOR = &H6 
        JOB_NOTIFY_FIELD_PARAMETERS = &H7 
        JOB_NOTIFY_FIELD_DRIVER_NAME = &H8 
        JOB_NOTIFY_FIELD_DEVMODE = &H9 
        JOB_NOTIFY_FIELD_STATUS = &HA 
        JOB_NOTIFY_FIELD_STATUS_STRING = &HB 
        JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR = &HC 
        JOB_NOTIFY_FIELD_DOCUMENT = &HD 
        JOB_NOTIFY_FIELD_PRIORITY = &HE 
        JOB_NOTIFY_FIELD_POSITION = &HF 
        JOB_NOTIFY_FIELD_SUBMITTED = &H10 
        JOB_NOTIFY_FIELD_START_TIME = &H11 
        JOB_NOTIFY_FIELD_UNTIL_TIME = &H12 
        JOB_NOTIFY_FIELD_TIME = &H13 
        JOB_NOTIFY_FIELD_TOTAL_PAGES = &H14 
        JOB_NOTIFY_FIELD_PAGES_PRINTED = &H15 
        JOB_NOTIFY_FIELD_TOTAL_BYTES = &H16 
        JOB_NOTIFY_FIELD_BYTES_PRINTED = &H17
    
        PRINTER_CHANGE_ADD_FORM = &H10000 
        PRINTER_CHANGE_SET_FORM = &H20000 
        PRINTER_CHANGE_DELETE_FORM = &H40000 
        PRINTER_CHANGE_FORM = &H70000 
        PRINTER_CHANGE_PORT = &H700000 
        PRINTER_CHANGE_JOB = &HFF00 
        PRINTER_CHANGE_PRINTER = &HFF 
        PRINTER_CHANGE_PRINT_PROCESSOR = &H7000000 
        PRINTER_CHANGE_PRINTER_DRIVER = &H70000000
        PRINTER_CHANGE_ADD_PORT = &H100000 
        PRINTER_CHANGE_CONFIGURE_PORT = &H200000 
        PRINTER_CHANGE_DELETE_PORT = &H400000 
        PRINTER_CHANGE_ADD_JOB = &H100 
        PRINTER_CHANGE_SET_JOB = &H200 
        PRINTER_CHANGE_DELETE_JOB = &H400 
        PRINTER_CHANGE_WRITE_JOB = &H800 
        PRINTER_CHANGE_ADD_PRINTER = &H1 
        PRINTER_CHANGE_SET_PRINTER = &H2 
        PRINTER_CHANGE_DELETE_PRINTER = &H4 
        PRINTER_CHANGE_FAILED_CONNECTION_PRINTER = &H8 
        PRINTER_CHANGE_ADD_PRINT_PROCESSOR = &H1000000 
        PRINTER_CHANGE_DELETE_PRINT_PROCESSOR = &H4000000
        PRINTER_CHANGE_ADD_PRINTER_DRIVER = &H10000000 
        PRINTER_CHANGE_SET_PRINTER_DRIVER = &H20000000 
        PRINTER_CHANGE_DELETE_PRINTER_DRIVER = &H40000000
    
        PRINTER_NOTIFY_FIELD_SERVER_NAME = &H0
        PRINTER_NOTIFY_FIELD_PRINTER_NAME = &H1
        PRINTER_NOTIFY_FIELD_SHARE_NAME = &H2
        PRINTER_NOTIFY_FIELD_PORT_NAME = &H3
        PRINTER_NOTIFY_FIELD_DRIVER_NAME = &H4
        PRINTER_NOTIFY_FIELD_COMMENT = &H5
        PRINTER_NOTIFY_FIELD_LOCATION = &H6
        PRINTER_NOTIFY_FIELD_DEVMODE = &H7
        PRINTER_NOTIFY_FIELD_SEPFILE = &H8
        PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR = &H9
        PRINTER_NOTIFY_FIELD_PARAMETERS = &HA
        PRINTER_NOTIFY_FIELD_DATATYPE = &HB
        PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR = &HC
        PRINTER_NOTIFY_FIELD_ATTRIBUTES = &HD
        PRINTER_NOTIFY_FIELD_PRIORITY = &HE
        PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY = &HF
        PRINTER_NOTIFY_FIELD_START_TIME = &H10
        PRINTER_NOTIFY_FIELD_UNTIL_TIME = &H11
        PRINTER_NOTIFY_FIELD_STATUS = &H12
        PRINTER_NOTIFY_FIELD_STATUS_STRING = &H13
        PRINTER_NOTIFY_FIELD_CJOBS = &H14
        PRINTER_NOTIFY_FIELD_AVERAGE_PPM = &H15
        PRINTER_NOTIFY_FIELD_TOTAL_PAGES = &H16
        PRINTER_NOTIFY_FIELD_PAGES_PRINTED = &H17
        PRINTER_NOTIFY_FIELD_TOTAL_BYTES = &H18
        PRINTER_NOTIFY_FIELD_BYTES_PRINTED = &H19
        PRINTER_NOTIFY_FIELD_OBJECT_GUID = &H1A
    I googled ( just for the sake of googling ) for OpenPrinter :
    http://www.google.co.uk/search?hl=en...r+vb.net&meta=

    Then, for FindFirstPrinterChangeNotification :
    http://www.google.co.uk/search?hl=en...G=Search&meta=

    Then, for FindNextPrinterChangeNotification :
    http://www.google.co.uk/search?hl=en...G=Search&meta=

    I eventually run into this article :
    http://www.codeproject.com/KB/printi...atchvbnet.aspx

    I hope it helps

    EDIT: I Didn't see your latest reply Hairy, I was so busy typing
    Last edited by HanneSThEGreaT; November 19th, 2008 at 09:30 AM.

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Is Printer Online

    Two quick comments/observations:

    1) There are definately issues with any networked printer, and even after years of searching I have not found any approach that is universally reliable.

    2) Even if you can detect with 100% reliability the ability of a printer to accept a print job, this does NOT mean that a (usable) printout will be generated. The best you can get is a "probability".

    For critical items (eg reciepts), this has caused me to generate a sub-system that does pre-printer queuing and caching. This was definately non-trivial as it requires a means of storing the information necessary to generate the prinout, but the benfits were amazing.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Is Printer Online

    Thanks guy's ...

    I got my work set out for me, lots of reading to do too...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  9. #9
    Join Date
    Jun 2017
    Posts
    1

    Re: Is Printer Online

    Hi, did you solved this problem. i'am faced with same thing. Is it possible to get printer status connect at usb01 port?!

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Is Printer Online

    Quote Originally Posted by zorans@srbrail.rs View Post
    Hi, did you solved this problem. i'am faced with same thing. Is it possible to get printer status connect at usb01 port?!
    This thread is over 9 years old.... rather ask a new question by starting a new thread.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured