Information on catching and retrieving information about USB drives is complete (flash drives external drives).

For the definition of a flash drive I use this code:

foreach (ManagementObject drive in new ManagementObjectSearcher( "select DeviceID, Model from Win32_DiskDrive where InterfaceType='USB'").Get()) { // associate physical disks with partitions ManagementObject partition = new ManagementObjectSearcher(String.Format( "associators of {{Win32_DiskDrive.DeviceID='{0}'}} where AssocClass = Win32_DiskDriveToDiskPartition", drive["DeviceID"])).First(); if (partition != null) { // associate partitions with logical disks (drive letter volumes) ManagementObject logical = new ManagementObjectSearcher(String.Format( "associators of {{Win32_DiskPartition.DeviceID='{0}'}} where AssocClass = Win32_LogicalDiskToPartition", partition["DeviceID"])).First(); if (logical != null) { // finally find the logical disk entry to determine the volume name ManagementObject volume = new ManagementObjectSearcher(String.Format( "select FreeSpace, Size, VolumeName from Win32_LogicalDisk where Name='{0}'", logical["Name"])).First(); UsbDisk disk = new UsbDisk(logical["Name"].ToString()); disk.Model = drive["Model"].ToString(); disk.Volume = volume["VolumeName"].ToString(); disk.FreeSpace = (ulong)volume["FreeSpace"]; disk.Size = (ulong)volume["Size"]; disks.Add(disk); } } } 

The bottom line is that first he finds a disk in which the connection interface is = USB, then he already takes the letter of this partition and begins operations with the partition. As a result, the name of the partition, the letter, the place on the flash drive / disk is displayed, and the model ID there can be displayed all this, it’s clear how.

Now the question is: How to determine the connected portable / portable device? For example fotik or phone via USB? After all, you can also drop data on them and transfer them from there? The problem is that this is a portable device as a camera or mobile does not create a separate partition of the file system

I tried through Win32_USBHub, but there is no such parameter that would unite all portable devices.

    1 answer 1

     On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set wmiEvent = objWMIService.ExecNotificationQuery _ ("Select * from __InstanceOperationEvent within 1 where TargetInstance ISA 'Win32_PnPEntity'") Do Set objReceivedEvent = wmiEvent.NextEvent 'Wscript.Echo "Ожидаем события ..."& objReceivedEvent.TargetInstance.Description sdevid = objReceivedEvent.TargetInstance.DeviceId replacesdevid = replace(sdevid,"\","%") if left(sdevid,4) = "USB\" then 'Делаем что надо else end if if left(sdevid,4) = "HID\" then 'Делаем что надо else 'И т.д. Делаем что надо с остальными end if Loop