First, run your Visual Studio as Administrator and try this code in a console application (run the application with debugging):
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = @"CMD.EXE";
p.StartInfo.Arguments = @"/C bcdedit";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
// parse the output
var lines = output.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Where(l => l.Length > 24);
foreach (var line in lines)
{
var key = line.Substring(0, 24).Replace(" ", string.Empty);
var value = line.Substring(24).Replace(" ", string.Empty);
Console.WriteLine(key + ":" + value);
}
Console.ReadLine();
}
However, there is a problem, If you want this to work when launching the application from outside the elevated Visual Studio, you need to configure your application to ask for elevated rights:
On your project, click add new item and select Application Manifest File.
Open app.manifest file and replace this line:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
with this one:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />