internal static void SetIcon(DeviceInformation deviceInterface, Action <ShellThumbnail> action)
 {
     if (deviceInterface.Properties.TryGetValue("System.Devices.Icon", out var value) && value is string path)
     {
         var iconIndex = ShellUtilities.ParseIconLocationPath(path, out var iconPath);
         if (iconPath != null)
         {
             action(new ShellThumbnail(DeviceClassFolder.NormalizeIconPath(iconPath), iconIndex));
         }
     }
 }
        // gets an icon path for a class (guid)
        private int?GetIconPath(out string filePath)
        {
            filePath = null;
            using (var key = Registry.LocalMachine.OpenSubKey(Path.Combine(@"SYSTEM\CurrentControlSet\Control\Class", ClassGuid.ToString("B")), false))
            {
                if (key == null)
                {
                    return(null);
                }

                var obj = key.GetValue("IconPath");
                if (!(obj is string path))
                {
                    path = (obj as string[])?[0];
                }
                if (string.IsNullOrWhiteSpace(path))
                {
                    return(null);
                }

                return(ShellUtilities.ParseIconLocationPath(path, out filePath));
            }
        }