I am trying to create a lightweight application that will check certain security settings on a machine. Currently, I have everything except for the current encryption status. I was lead towards the WMI creator which seems to be the safest bet (all be it a little slow) However, I am getting the error below:
"foreach statement cannot operate on variables of type 'ComplianceGuide.ManagementObjectCollection' because 'ComplianceGuide.ManagementObjectCollection' does not contain a public definition for 'GetEnumerator'
Where do i go to add the definition? C# is so confusing sometimes. A video tutorial would be AWESOME.
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2\\Security\\MicrosoftVolumeEncryption",
"SELECT * FROM Win32_EncryptableVolume");
foreach (System.Management.ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_EncryptableVolume instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("ProtectionStatus: {0}", queryObj["ProtectionStatus"]);
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}