public static void WriteObject(IPortableDeviceKeyCollection collection) { uint num = 0; collection.GetCount(ref num); for (uint index = 0; index < num; index++) { PropertyKey key = new PropertyKey(); collection.GetAt(index, ref key); //EnumExtentions.GetEnumFromAttrKey<TEnum>(key); //Trace.WriteLine($"##### {((PropVariant)val).ToString()}"); } }
/// <summary> /// 获取总容量和可用容量 /// </summary> /// <param name="storageId"></param> /// <param name="freeSpace"></param> /// <param name="storageCapacity"></param> public void GetStorageCapacityAnFreeSpace(string storageId, out ulong freeSpace, out ulong storageCapacity) { IPortableDeviceKeyCollection keyCollection = (IPortableDeviceKeyCollection) new PortableDeviceTypesLib.PortableDeviceKeyCollection(); keyCollection.Add(ref pKey.WPD_STORAGE_FREE_SPACE_IN_BYTES); keyCollection.Add(ref pKey.WPD_STORAGE_CAPACITY); IPortableDeviceValues deviceValues; deviceProperties.GetValues(storageId, keyCollection, out deviceValues); deviceValues.GetUnsignedLargeIntegerValue(ref pKey.WPD_STORAGE_FREE_SPACE_IN_BYTES, out freeSpace); deviceValues.GetUnsignedLargeIntegerValue(ref pKey.WPD_STORAGE_CAPACITY, out storageCapacity); }