Advertisement
Combreal

checkIfdiskIsEncrypted.cpp

Jul 10th, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <shlobj.h>
  2. #pragma comment(lib, "shell32.lib")
  3. #pragma comment(lib, "propsys.lib")
  4. #include <iostream>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <string>
  8. #include <vector>
  9. #include <windows.h>
  10. using namespace std;
  11.  
  12. wchar_t* convertCharArrayToLPCWSTR(const char* charArray)
  13. {
  14.     wchar_t* wString = new wchar_t[4096];
  15.     MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 4096);
  16.     return wString;
  17. }
  18.  
  19. bool getDriveEncryptionStatus(LPCWSTR parsingName)
  20. {
  21.     IShellItem2* drive = NULL;
  22.     HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
  23.     hr = SHCreateItemFromParsingName(parsingName, NULL, IID_PPV_ARGS(&drive));
  24.     if (SUCCEEDED(hr))
  25.     {
  26.         PROPERTYKEY pKey;
  27.         hr = PSGetPropertyKeyFromName(L"System.Volume.BitLockerProtection", &pKey);
  28.         if (SUCCEEDED(hr))
  29.         {
  30.             PROPVARIANT prop;
  31.             PropVariantInit(&prop);
  32.             hr = drive->GetProperty(pKey, &prop);
  33.             if (SUCCEEDED(hr))
  34.             {
  35.                 int status = prop.intVal;
  36.                 drive->Release();
  37.                 if (status == 1 || status == 3 || status == 5)
  38.                 {
  39.                     return true;
  40.                 }
  41.                 else
  42.                 {
  43.                     return false;
  44.                 }
  45.             }
  46.         }
  47.     }
  48.     if (drive)
  49.     {
  50.         drive->Release();
  51.     }
  52.     return false;
  53. }
  54.  
  55. int main(void)
  56. {
  57.     cout << "Is disk C: encrypted : " << getDriveEncryptionStatus(convertCharArrayToLPCWSTR("C:")) << endl;
  58.     cout << "Is disk D: encrypted : " << getDriveEncryptionStatus(convertCharArrayToLPCWSTR("D:")) << endl;
  59.     cout << "Is disk G: encrypted : " << getDriveEncryptionStatus(convertCharArrayToLPCWSTR("G:")) << endl;
  60.     system("pause");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement