1

I'm currently working on a installer kind of program. It has a system check page where I check if all the requerments are met or not. One requirement is the availability of BitLocker.

Currently I check for BitLocker by trying to create an instance of Win32_EncryptableVolume and then check if an exception is thrown or not. But I wonder if there is a more elegant way.

My method currently looks basicaly like this:

public static bool IsBitlockerAvaliable()
{
    try
    {
        var path = new ManagementPath
        {
            NamespacePath = @"\ROOT\CIMV2\Security\MicrosoftVolumeEncryption",
            ClassName = "Win32_EncryptableVolume"
        };
        using (var wmi_class = new ManagementClass(path))
        {
            foreach (var o in wmi_class.GetInstances())
            {
                var vol = (ManagementObject) o;
                if (vol == null)
                    throw new Exception("Vol is null");
                Debug.WriteLine(vol);
            }
        }

        return true;
    }
    catch (ManagementException e)
    {
        // No Admin rights is a different issue
        if (e.ErrorCode == ManagementStatus.AccessDenied)
        {
            throw new AccessViolationException();
        }

        return false;
    }
    catch (Exception e)
    {
        return false;
    }
}
Takiro
  • 460
  • 5
  • 22
  • Does this answer the question? https://stackoverflow.com/questions/41308245/detect-bitlocker-programmatically-from-c-sharp-without-admin – Syntax Error Oct 25 '19 at 12:03
  • @SyntaxError From what I see, the linked question/answer is about if a drive is encrypted/protecrted or not, not about if BitLocker is even installed. I'm just wondering if there is a more elegant way to find out if BitLocker is installed before I even attempt to encrypt a drive. – Takiro Oct 25 '19 at 12:06
  • You can guarantee the existence of a binary if you package your binary with its dependencies. – Kieran Devlin Oct 25 '19 at 13:45

0 Answers0