BitLocker狀態適用於shell中的任何普通用戶。 Windows使用Win32 API中的Windows Property System獲取狀態以檢查未記錄的shell屬性System.Volume.BitLockerProtection
。您的程序也可以在沒有提升的情況下查看此屬性。
如果此屬性的值爲1,3或5,則會在驅動器上啓用BitLocker。任何其他值都被視爲關閉。
您可以使用Win32 API來檢查此shell屬性。作爲禮節,我已經移植了我的託管實施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;
}
謝謝。我會試一試。在我做之前,你知道這些值是什麼:1到5代表什麼? – c00000fd