I am trying to take this Console code and return a result in a textbox called Bitlocker. The console code seems to work just fine as long as I run in Admin. I have never tried retrieving console results and diplaying them in plain text before so Im super confused as to what I did wrong.
What i want is to retrieve the queryObj response and display it in a textbox.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System;
using System.Management;
using System.Windows.Forms;
namespace ComplianceCheck_2._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2\\Security\\MicrosoftVolumeEncryption",
"SELECT * FROM Win32_EncryptableVolume");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_EncryptableVolume instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("ProtectionStatus: {0}", queryObj["ProtectionStatus"]);
int status;
status = int.Parse(Console.ReadLine());
if (status > 0)
{
Bitlocker.Text = "True";
}
else ;
{
Bitlocker.Text = "False";
}
}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}