Reputation: 3667
I am trying to build an application in Visual Studio via Visual Basic and am pulling information of the current machine. Basically, what I want to do is pull the encryption status of Bitlocker in Visual Basic that outputs if the C: Drive is Bitlocked or is not Bitlocked.
I have looked around for something that completes this on the internet, but everything I see has something to do with WMI. It also appears that WMI needs to be installed on each machine you will be utilizing it on. I just want to be able to go to machine after machine run the file and have all my information outputted in the form. My code for pulling everything right now is as follows:
Public Class ComputerInformation
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBoxComputerName.Text = Environment.MachineName
TextBoxOSVersion.Text = System.Environment.OSVersion.ToString
TextBoxOSFullName.Text = My.Computer.Info.OSFullName
TextBoxCurrentUser.Text = System.Environment.UserName
TextBox64Bit.Text = System.Environment.Is64BitOperatingSystem
TextBoxSystemDirectory.Text = System.Environment.SystemDirectory
TextBoxDomain.Text = System.Environment.UserDomainName
' CHECK BITLOCKER STATUS HERE.
End Sub
End Class
Some help and maybe an explanation would be greatly appreciated! Thank you!
Upvotes: 5
Views: 3279
Reputation: 35
As Hans Passant stated above, use the WMI Code Creator utility.
You can select Win32_EncryptableVolume
from the classes combobox when you chose the namespace root\CIMV2\Security\MicrosoftVolumeEncryption
.
You could use something like this to determine if BitLocker is active/available:
IShellProperty prop = ShellObject.FromParsingName("C:").Properties.GetProperty("System.Volume.BitLockerProtection");
int? bitLockerProtectionStatus = (prop as ShellProperty<int?>).Value;
if (bitLockerProtectionStatus.HasValue && (bitLockerProtectionStatus == 1 || bitLockerProtectionStatus == 3 || bitLockerProtectionStatus == 5))
Console.WriteLine("ON");
else
Console.WriteLine("OFF");
Note that this is C# code, but easily convertible.
Upvotes: 1
Reputation: 941208
Yes, you query this by using the Win32_EncryptableVolume WMI class. The ProtectionStatus
property tells you whether encryption is turned on. WMI does not have to be installed. However, the Win32_EncryptableVolume class will only be available if Bitlocker is present on the machine.
To get started, first download the WMI Code Creator utility. It lets you play with WMI queries and will automatically generate the VB.NET code you need and test it. In the menu, use Code Language and pick "Visual Basic.NET". Select Win32_EncyptableVolume from the Classes combobox and select the ProtectionStatus property. Click "Execute Code" to test it. Copy/paste the generated source code into your program. Also check the code on a machine that doesn't have Bitlocker available, you'll need to catch the exception you get so you know Bitlocker isn't present at all.
Upvotes: 8