public static bool LockAllVolumesOrNone(List <Guid> volumeGuids) { bool success = true; int lockIndex; for (lockIndex = 0; lockIndex < volumeGuids.Count; lockIndex++) { Guid volumeGuid = volumeGuids[lockIndex]; if (WindowsVolumeManager.IsMounted(volumeGuid)) { success = WindowsVolumeManager.ExclusiveLock(volumeGuid); if (!success) { break; } } } if (!success) { // release the volumes that were locked for (int index = 0; index < lockIndex; index++) { WindowsVolumeManager.ReleaseLock(volumeGuids[lockIndex]); } } return(success); }
public static bool LockAllMountedOrNone(List <DynamicVolume> volumes) { bool success = true; int lockIndex; for (lockIndex = 0; lockIndex < volumes.Count; lockIndex++) { // NOTE: The fact that a volume does not have mount points, does not mean it is not mounted and cannot be accessed by Windows success = WindowsVolumeManager.ExclusiveLockIfMounted(volumes[lockIndex].VolumeGuid); if (!success) { break; } } if (!success) { // release the volumes that were locked for (int index = 0; index < lockIndex; index++) { WindowsVolumeManager.ReleaseLock(volumes[index].VolumeGuid); } } return(success); }
public static void UnlockBasicDiskAndVolumes(PhysicalDisk disk) { List <Partition> partitions = BasicDiskHelper.GetPartitions(disk); foreach (Partition partition in partitions) { Guid?windowsVolumeGuid = WindowsVolumeHelper.GetWindowsVolumeGuid(partition); if (windowsVolumeGuid.HasValue) { WindowsVolumeManager.ReleaseLock(windowsVolumeGuid.Value); } } disk.ReleaseLock(); }