Axxess
Axxess

Reputation: 532

Win32_EncryptableVolume to get bitlocker status in C#

In c# I'm using the following code the get the status of BitLocker. When i run the script is says: Management Exception was unhandled. Any ideas?

ManagementClass objectSearcher;
            List<string> BitLocker = new List<string>();

            objectSearcher = new ManagementClass("Win32_EncryptableVolume");
            foreach (var item in objectSearcher.GetInstances())
            {
                try
                {
                 BitLocker.Add(item["DeviceID"].ToString());
                 BitLocker.Add(item["ProtectionStatus"].ToString());

                }
                catch
                {
                    BitLocker.Add("Error, could not retrieve data. \n");
                }

            }

Image1

Upvotes: 2

Views: 3859

Answers (1)

Saigework
Saigework

Reputation: 111

I believe you need to set a path and scope first, for example:

var path = new ManagementPath(@"\ROOT\CIMV2\Security\MicrosoftVolumeEncryption") { ClassName = "Win32_EncryptableVolume" };
var scope = new ManagementScope(path);
path.Server = Environment.MachineName;
var objectSearcher = new ManagementClass(scope, path, new ObjectGetOptions());

Upvotes: 4

Related Questions