locked
Use WMI to Associate win32_SerialPort device with win32_LogicalDrive mapping RRS feed

  • Question

  • Hi,

    My c# application requires to flash a micro-controller, which has been configured as a removable device and is connectable by means of a Virtual Com Port.

    So, I need to recognise the volume label of the mapped drive and perform the flash using a simple file copy.

    The problem is that some of the micro-controllers produce slightly different volume labels making it difficult to identify all possible cases via string comparison.
    I know how to retrieve drive info for removable devices using DriveInfo.GetDrives(). This gives me the drive letter and the volume label

    removableDriveList = (List<RemovableDrive>)DriveInfo.GetDrives()
            .Where(d => d.DriveType == DriveType.Removable)
            .Select(s => new RemovableDrive
                {
                    Drive = s.Name,
                    Label = s.VolumeLabel
                }).ToList();
     I know how to detect the com port and recognisable description of the development boards using WMI to query Win32_SerialPorts.
    ManagementObjectCollection collection;
    using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort"))
            collection = searcher.Get();
    
    var removableDevices = from ManagementObject x in collection
        where x.Properties["Name"].Value.ToString().Contains("MyManufacturer")
        select x;
        portName = (String)(removableDevices.First().GetPropertyValue("DeviceID"));
    

    However, I can't associate the virtual com port with the drive mapping. I want to be able to say, this device with ID COM7, manufacturer "MyManufacturer", matches drive mapping "I:\My_Microcontroller".

    I noticed (from device manager properties) that they both have the same container ID and are derived from the same usb controller, however I don't know how to access the this information from each child using WMI. Is this possible?

    Thanks


    • Edited by Marcpolo Sunday, April 5, 2015 11:11 AM
    • Moved by Fred Bao Monday, April 6, 2015 9:34 AM Desktop SDK Related
    Sunday, April 5, 2015 10:35 AM

All replies

  • Hello Marcpolo,

    I move it to the desktop forum since it is more related with Windows Management Instrumentation development.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Fred Bao Monday, April 6, 2015 9:36 AM
    Monday, April 6, 2015 9:32 AM