VB.Net and BitLocker Drive Encryption Status

~OSD~ 2,176 Reputation points
2021-02-08T20:26:47.007+00:00

Hi,

Is it possible to get the status of the Bit Locker Drive for the "C:\" volume using VB.Net?

Currently I am able to get the status using manage-bde -status and following PowerShell as well:
$bitlockerVolume = Get-BitLockerVolume -MountPoint "C:"
$statusBitlocker = $bitlockerVolume.ProtectionStatus
if ($statusBitlocker -eq "On")
{
With VB.Net, I would like to test it when form1 loads. If C drive is encrypted show the dialog box 1 else show form2, possible in vb.net?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
0 comments No comments
{count} votes

Accepted answer
  1. ~OSD~ 2,176 Reputation points
    2021-02-12T13:50:34.193+00:00

    Hi,

    Atleast some progress, now I am able to have some results with help of following code:
    But I would like to check ONLY if C:\ drive is encrypted then show a message box. Otherwise /IF not encrypted, show form2.

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Try
                Me.RichTextBox1.Clear()
                Dim searcher As New ManagementObjectSearcher("root\cimv2\Security\MicrosoftVolumeEncryption", "SELECT * FROM Win32_EncryptableVolume")
                For Each queryObj As ManagementObject In searcher.Get()
                    '
                    queryObj("DriveLetter").ToString.ToUpper()
                    queryObj("ProtectionStatus").ToString.ToUpper()
                    Dim drvLtr = "C:"
                    Dim prtStatus = "1"
                    '
                    If queryObj("DriveLetter").ToString.ToUpper.Contains(drvLtr.ToUpper) AndAlso queryObj("ProtectionStatus").ToString.ToUpper.Contains(prtStatus.ToUpper) Then
                        MessageBox.Show(queryObj("DriveLetter").ToString & "Drive is Encrypted.") 'Concludes C:\ is encrypted
                    Else 'Otherwise assume C:\ is not encrypted.
                        MessageBox.Show(queryObj("DriveLetter").ToString & "Drive is NOT Accessible.")
                    End If
                    '
                Next
            Catch err As ManagementException
                Me.Text = "An error occurred while querying for WMI data: " & err.Message
            End Try
        End Sub
    

    But it seems like all drives are being evaluated and false results generated in messagebox.
    Any thought to limit it to scan for C:\ drive ONLY?

    Code Credits: how-to-get-the-result-of-a-getproperties-method-of-a-wmi-class-in-vbnet-using


2 additional answers

Sort by: Most helpful
  1. Castorix31 84,471 Reputation points
    2021-02-08T20:42:12.567+00:00

    You can use WMI
    Win32_EncryptableVolume class

    1 person found this answer helpful.
    0 comments No comments

  2. ~OSD~ 2,176 Reputation points
    2021-02-12T10:28:54.14+00:00

    Which NameSpace?

    67402-image.png

    Win32_EncryptableVolume isn't available?
    ![67385-image.png][2]

    Someone have an example? [2]: /api/attachments/67385-image.png?platform=QnA


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.