public static Exception LockDataVolume(ManagementObject encryptableVolume, out int returnValueLock) { ManagementBaseObject outParams = null; int returnValue = -1; Exception ex = Util.HandleExceptions(delegate { string deviceId = BitlockerUtil.GetDeviceId(encryptableVolume); Exception ex2; if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2)) { if (ex2 != null) { throw new VolumeLockedFindException(deviceId, ex2.Message, ex2); } } else { returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Lock", null, null, out outParams); if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2) && ex2 != null) { throw new VolumeLockedFindException(deviceId, ex2.Message, ex2); } } }); returnValueLock = returnValue; Util.AssertReturnValueExceptionInconsistency(returnValueLock, "LockDataVolume", ex); return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueLock, "LockDataVolume", ex)); }
public static Exception UnlockWithNumericalPassword(ManagementObject encryptableVolume, string numericalPassword, out int returnValueUnlockWithNumericalPassword) { ManagementBaseObject outParams = null; int returnValue = -1; Exception ex = Util.HandleExceptions(delegate { string deviceId = BitlockerUtil.GetDeviceId(encryptableVolume); Exception ex2; if (!BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2)) { returnValue = 0; throw new VolumeLockedFindException(deviceId, ex2.Message, ex2); } returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "UnlockWithNumericalPassword", new string[] { "NumericalPassword" }, new object[] { numericalPassword }, out outParams); }); returnValueUnlockWithNumericalPassword = returnValue; Util.AssertReturnValueExceptionInconsistency(returnValueUnlockWithNumericalPassword, "UnlockWithNumericalPassword", ex); return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueUnlockWithNumericalPassword, "UnlockWithNumericalPassword", ex)); }