Run the program on a usb hardware plugin

Is there a way to detect when a particular device is connected to the USB port, what I would like to do is when I connect my laptop to my dock, it launches several applications to take into account my keyboard, mouse and monitors. In particular, I have a problem with some software for my closing media player closing the G15 keyboard.

Hopefully in .NET, but if any suggestions are not appreciated.

+1
source share
2 answers

Try using SharpUSBLib . This is the C # shell around the libusb project.

( - ). , , , USB.

  foreach (Bus bus in Bus.Busses)
        {
            Console.WriteLine(bus);
            foreach (Descriptor descriptor in bus.Descriptors)
            {
                Console.WriteLine("\t" + descriptor);
                try
                {
                    using (Device device = descriptor.OpenDevice())
                    {
                        Console.WriteLine("\t\t     Product: " + device.Product);
                        Console.WriteLine("\t\tManufacturer: " + device.Manufacturer);
                        Console.WriteLine();
                    }
                }
                catch (UsbException e)
                {
                    Console.WriteLine("Got Exception : " + e);
                }
            }
        }
+2

Source: https://habr.com/ru/post/1706788/


All Articles