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?
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With