[英]Execute windows 10 IOT cmd command from c# code
Windows10 IOT企业版具有保护驱动器上的写访问的功能。 此功能称为UWF“统一写过滤器”。 我启用此功能并保护C驱动器上的写访问。 现在,我正在寻找通过C#代码禁用它的功能。 禁用它的Cmd命令是“ uwfmgr filter disable”。 我实现了下面的代码来执行此命令,但是它不起作用
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C uwfmgr filter disable";
startInfo.UserName = "Administrator";
startInfo.Password = class1.ConvertToSecureString("SRPedm");
process.StartInfo = startInfo;
process.Start();
Process.Start("shutdown","/r /t 0");
执行该代码时不会给出任何错误,但命令不会执行。
您不是在等待过程完成,也不在寻找任何错误。
您需要调用process.WaitForExit
并查看process.StandardError
public static void Main()
{
var p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// To avoid deadlocks, always read the output stream first and then wait.
string output = p.StandardError.ReadToEnd();
p.WaitForExit();
Console.WriteLine($"\nError stream: {output}");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.