Skip navigation


Currently Being Moderated

Check if a USB Device is Connected to the System - Windows Registry

VERSION 6  Click to view document history
Created on: Sep 14, 2009 2:58 AM by John.P - Last Modified:  Oct 14, 2016 3:52 AM by John.P


This code allows you to check if any USB device is connected to the system.



There are no native LabVIEW functions to do this and the VI needed to be able to monitor for ANY USB device, be that a flash memory stick, a keyboard, a web camera.


The information needed is all stored in the Windows Registry so as well as being a useful VI this is also an example of accessing the registry.


The main issue with this is different USB devices are stored in different registry keys.  For example all the devices that appear as storage devices are under the usbSTOR key, HCI devices such as the keyboard appear under the usbehci key etc.


The next issue is that if you have never plugged any device of a certain type into your system, the key will simply not exist.  This code accounts for both issues.  It allows us to add registry keys to search, and will handle any errors generated by keys not being found.



LabVIEW 8.0 (or compatible)


Steps to Implement or Execute Code

Identify the device you wish to monitor for:

1. Plug it into the system.

2. Bring up the Windows Device Manager and locate the USB device.

3. Under the details tab Note down the device instance ID, this varies from device to device but the last part after the final "\" is usually sufficient.

4. Bring up the windows registry (regedit in the run menu).

5. Navigate to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services.

6. Locate the device ID in one of the USB registry keys ( device must be connected,  might be easier to search for it).

7. Note down the subkey (folder) the device is stored in.  By default the VI uses USBSTOR, usbccgp, usbehci, usbaudio.

8. If the device falls under one of these subkeys you are ready to go.  If not add the sub key to the paths in the VI.


Enter the Device ID into the VI and run it, the VI will check if the device is present and return a boolean.  The VI is setup ready as a sub VI.


Additional Information or References

USB Device Detect.png



Saved in 8.0, will open correctly in any later version.

I would be very pleased with feedback, if anybody has a better method of achieving this I would be interested in hearing.

All ideas are welcome providing they only use code that is free to distribute.





**This document has been updated to mee the current required format for the NI Code Exchange. **

Comments (12)