2vision2
2vision2

Reputation: 5023

Trigger an exe once My device is connected via USB

Once my embedded device is connected to USB port of my PC, it should trigger an exe as an event. How can I achieve this??

Should I create a service to keep monitoring the USB connector bus or is there any default API's available in Windows to achieve this??

thanks.

Upvotes: 2

Views: 2331

Answers (3)

MSalters
MSalters

Reputation: 179819

The easiest solution is probably a trivial UMDF driver. That's basically a small COM component called when your device is connected.

Upvotes: 0

Christopher
Christopher

Reputation: 8992

A simple exe which is started on connect is not possible. But you can write a service or user mode application which listens for device arrival events. WM_DEVICECHANGE is sent to all (registered) applications with a device interface guid which represents which device is plugged in. You can then use this id with the setupapi to see if its your device.

On receiving that event, you can then start your executable.

Upvotes: 3

erikxiv
erikxiv

Reputation: 4075

Depending on your version of Windows it might be possible with a workaround using a AutoRun.inf file in the root folder of a USB drive. For security reasons this is by default turned off, and in Windows 7 not allowed at all.

To achieve the same effect in a more robust way, you need to create a service that monitors whether your device is connected or not (e.g. iTunesHelper that monitors for connected Apple devices).

Upvotes: 2

Related Questions