![](/img/trans.png)
[英]How to get registry and file exclusions from UWF using WMI query in C#
[英]How to get Windows UWF available space in C#
我想在 C# 程序中運行以下 shell 命令:
uwfmgr overlay get-availablespace
一個簡單的解決方案是調用 cmd 進程,如下所示:
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();
}
但是是否有一個簡單的 API 來調用以避免解析進程的 output 字符串? 另一個問題是我必須使用管理權限調用 cmd。
更新:我嘗試使用 WMI Api 但沒有成功,這是我的代碼:
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;
}
這是獲取 UWF AvailableSpace
和OverlayConsumption
的工作代碼。
var scope = new ManagementScope(@"root\standardcimv2\embedded");
var uwfClass = new ManagementClass(scope.Path.Path, "UWF_Overlay", null);
foreach (ManagementObject instance in uwfClass.GetInstances())
{
var availableSpace = Convert.ToInt32(instance.GetPropertyValue("AvailableSpace").ToString());
var overlayConsumption = Convert.ToInt32(instance.GetPropertyValue("OverlayConsumption").ToString());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.