使用C#代码执行cmd命令时获取奇怪的输出数据

时间:2019-06-29 11:50:13

标签: c# cmd windows-10

Windows10 IOT企业版具有保护驱动器上的写访问的功能。此功能称为UWF“统一写过滤器”。我启用此功能并保护C驱动器上的写访问。现在,我正在寻找一种功能来检查过滤器当前是否启用。知道过滤器状态的Cmd命令为“ uwfmgr.exe get-config”。我已经实现了以下代码来实现此功能

var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(exeName);
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.Verb = "runas";
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C uwfmgr.exe get-config";//Executing command
startInfo.RedirectStandardOutput = true;               
startInfo.CreateNoWindow = false;               
startInfo.UserName = "Administrator";
startInfo.Password = class1.ConvertToSecureString("SRPedm");            

process.StartInfo = startInfo;

process.Start();
string output = process.StandardError.ReadToEnd();
string output1 = process.StandardOutput.ReadToEnd();//here reading the output of command

if (output1.Contains("Filter state:")) 

  lblcmdoutput.Content = "OFF";
else
    lblcmdoutput.Content = "ON";

lblerr.Content = output1;
process.WaitForExit();

我在output1中获得的数据很奇怪。怪异的是我说“那里没有英文字符”。更改命令时给出相同结果的相同代码

0 个答案:

没有答案