Click here to Skip to main content
15,887,892 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Now I'm using code below. But this code notifies me only when I plug in or out USB printer. But I need to get notified when printing occurs on USB printer. I am using c# and .netfx4.5.

Please help me, any suggestion would be highly appreciated!

Regards, Orgil.D

What I have tried:

<pre>using LibUsbDotNet.DeviceNotify;
//...
public static IDeviceNotifier UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();

    private static void Main(string[] args)
    {
        // Hook the device notifier event
        UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;

        // Exit on and key pressed.
        Console.Clear();            
        Console.WriteLine();
        Console.WriteLine("Waiting for system level device events..");
        Console.Write("[Press any key to exit]");

        while (!Console.KeyAvailable)
            Application.DoEvents();

        UsbDeviceNotifier.Enabled = false;  // Disable the device notifier

        // Unhook the device notifier event
        UsbDeviceNotifier.OnDeviceNotify -= OnDeviceNotifyEvent;
    }

    private static void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
    {
        // A Device system-level event has occured

        Console.SetCursorPosition(0,Console.CursorTop);

        Console.WriteLine(e.ToString()); // Dump the event info to output.

        Console.WriteLine();
        Console.Write("[Press any key to exit]");
    }
Posted
Updated 28-Aug-17 1:10am
v2

1 solution

You have to monitor the Windows print jobs and check if your USB printer is the output device.

Some links which might be helpful:
Monitor jobs in a printer queue (.NET)[^]
A simple approach for controlling print jobs using WMI[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900