I'd like to run the following shell command in a C# program:
uwfmgr overlay get-availablespace
One simple solution would be call a cmd process like this:
var ps = new ProcessStartInfo("cmd")
{
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
FileName = "cmd.exe",
Arguments = "/user:Administrator /c uwfmgr overlay get-availablespace"
};
using (Process p = Process.Start(ps))
{
output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
But is there a simple API to call in order to avoid to parse the output string of the process? Another problem is that I have to call cmd with administrative rights.
UPDATE: I try with WMI Api but with no success, here is my code:
var scope = new ManagementScope(@"root\standardcimv2\embedded");
var uwfClass = new ManagementClass(scope.Path.Path, "UWF_Overlay", null);
foreach (ManagementObject instance in uwfClass.GetInstances())
{
var result = instance.InvokeMethod("AvailableSpace", null);
break;
}
Here is the working code to obtain UWF
AvailableSpace
andOverlayConsumption
.