public static Exception ValidateAndEncryptEmptyWin7Volume(ManagementObject encryptableVolume, bool fipsCompliant, out int returnValueEncrypt) { int returnValue = -1; returnValueEncrypt = -1; if (encryptableVolume == null) { return(new EncryptableVolumeArgNullException("ValidateAndEncryptEmptyWin7Volume")); } string deviceID = encryptableVolume.GetPropertyValue("DeviceId").ToString(); if (Util.IsOperatingSystemWin8OrHigher()) { return(new FullVolumeEncryptionOnWin8ServerException(deviceID)); } Exception ex = Util.HandleExceptions(delegate { Exception ex = null; if (!BitlockerUtil.IsVolumeEmpty(deviceID, out ex)) { Util.ThrowIfNotNull(ex); throw new FullVolumeEncryptionAttemptOnANonEmptyVolumeException(deviceID); } string mountPoint; string eventXML; bool flag = BitlockerUtil.DoesVolumeHaveBadBlocks(deviceID, out mountPoint, out ex, out eventXML); if (flag) { throw new Win7EmptyVolumeNotStartedDueToPreviousFailureBadBlocksException(deviceID, mountPoint, eventXML); } if (!fipsCompliant) { ex = BitlockerUtil.AddNumericalPassword(encryptableVolume, "563563-218372-416746-433752-541937-608069-594110-446754", out returnValue); Util.ThrowIfNotNull(ex); } ex = BitlockerUtil.AddCertificateBasedKeyProtectors(encryptableVolume, out returnValue); Util.ThrowIfNotNull(ex); ex = BitlockerUtil.Encrypt(encryptableVolume, false, out returnValue); Util.ThrowIfNotNull(ex); BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out returnValue, out ex); Util.ThrowIfNotNull(ex); if (bitlockerConversionState != BitlockerUtil.BitlockerConversionState.EncryptionInProgress) { throw new Win7EmptyVolumeNotEncryptingAfterStartingEncryptionException(deviceID, bitlockerConversionState.ToString()); } }); returnValueEncrypt = returnValue; return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueEncrypt, "ValidateAndEncryptEmptyWin7Volume", ex)); }
public static bool IsEncryptionPausedDueToBadBlocks(string deviceId, out Exception ex, out string mountPoint, out string eventXML) { mountPoint = null; eventXML = null; ManagementObject encryptableVolume = BitlockerUtil.GetEncryptableVolume(deviceId, out ex); if (encryptableVolume == null) { return(false); } bool flag = BitlockerUtil.IsVolumeEncryptionPaused(encryptableVolume, out ex); if (!flag) { return(flag); } return(BitlockerUtil.DoesVolumeHaveBadBlocks(deviceId, out mountPoint, out ex, out eventXML)); }