Skip to content
⌘ NSIS Forum Archive

How to determin if a specific USB Device is currently plugged in?

3 posts

Theresias#

How to determin if a specific USB Device is currently plugged in?

During installation and prior to running DPInst which has worked fine for us I need to verify if a specific USB device is currently plugged in or not. I was looking at possible solutions and came across...

System::Call "cfgmgr32::CM_Get_Device_ID..."

The CM_Get_Device_ID function retrieves the device instance ID for a specified device instance on the local machine. (Unicode)


...but simply have no clue on how to implement this properly and/or if this would even allow me to look for a specific VID/PID. Could you give me some hints on how to do this?

Thank you very much for your assistance.
stass#
Theresias

You can use http://nsis.sourceforge.net/WMI_header

!include WMI.nsh

If you know the Hardware ID (VID: PID) USB Flash, it is possible to determine whether the connected USB flash drive.
${WMIGetInfo} root\CIMV2 Win32_USBHub PNPDeviceID callback_Function

Or to determine the connection, knowing the specific VolumeName
${WMIGetInfo} root\CIMV2 Win32_LogicalDisk VolumeName callback_Function

or use GetVolumeInformation
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.