Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if drive is BitLocker encrypted without admin privilege?

For my purpose all I need to know is drive's BitLocker encryption status by its DOS path. Something like this:

enum DriveEncryptionStatus{
    Unprotected,
    Protected,
    Unknown
};

DriveEncryptionStatus = GetDriveBitlockerEncryptionStatus(L"C:\\");

I was able to find the Win32_EncryptableVolume class that unfortunately comes with this caveat:

To use the Win32_EncryptableVolume methods, the following conditions must be met: You must have administrator privileges.

Any idea how to do this without running as an administrator?

like image 930
c00000fd Avatar asked Dec 11 '22 05:12

c00000fd


1 Answers

The BitLocker status is available to any ordinary user in the shell. Windows obtains the status using the Windows Property System in the Win32 API to check the undocumented shell property System.Volume.BitLockerProtection. Your program will also be able to check this property without elevation.

If the value of this property is 1, 3, or 5, BitLocker is enabled on the drive. Any other value is considered off.

You can use the Win32 API to check this shell property. As a courtesy, I have ported my managed implementation from my other answer to a similar question.

#include <shlobj.h>
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "propsys.lib")

DriveEncryptionStatus getDriveEncryptionStatus(LPCWSTR parsingName)
{
    IShellItem2 *drive = NULL;
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    hr = SHCreateItemFromParsingName(parsingName, NULL, IID_PPV_ARGS(&drive));
    if (SUCCEEDED(hr)) {
        PROPERTYKEY pKey;
        hr = PSGetPropertyKeyFromName(L"System.Volume.BitLockerProtection", &pKey);
        if (SUCCEEDED(hr)) {
            PROPVARIANT prop;
            PropVariantInit(&prop);
            hr = drive->GetProperty(pKey, &prop);
            if (SUCCEEDED(hr)) {
                int status = prop.intVal;

                drive->Release();

                if (status == 1 || status == 3 || status == 5)
                    return DriveEncryptionStatus::Protected;
                else
                    return DriveEncryptionStatus::Unprotected;
            }
        }
    }

    if (drive)
        drive->Release();

    return DriveEncryptionStatus::Unknown;
}

int main()
{
    DriveEncryptionStatus status = getDriveEncryptionStatus(L"C:");
    return 0;
}
like image 117
slypete Avatar answered Jan 18 '23 22:01

slypete