reg删除总是在C#中带来提示

时间:2019-01-28 08:35:00

标签: c#

我正在使用命令行执行来运行reg delete / f。现在,当我通过命令行执行此操作时,它可以按预期工作,但是如果我从C#运行它,仍然会提示您。

现在,我想知道erorr位于何处。...尽管使用了/ f参数,为什么当我通过C#调用命令时为什么仍然提示我?

编辑:此处的小信息:.NET Framework是3.5

正在使用的代码如下:

LaunchProcessAndWait(@"cmd",
      @"/c reg delete " + "\"" 
      + @"HKLM\Software\Policies\Microsoft\Internet Explorer\Main"+ "\"" 
      + @" /v DisableFirstRunCustomize /f",
        "");


public static string LaunchProcessAndWaitForOutput(string commandline, string args, bool returnError, bool returnOutput, string workingDir)
        {
            ProcessStartInfo info = new ProcessStartInfo(commandline, args);

            if (workingDir != null)
            {
                info.WorkingDirectory = workingDir;
            }

            info.UseShellExecute = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError = true;
            info.CreateNoWindow = true;

            Process p = Process.Start(info);

            string outStr = "";
            string errStr = "";

            p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
            {
                outStr += e.Data + "\r\n";
            });

            p.ErrorDataReceived += new DataReceivedEventHandler((sender, e) =>
            {
                errStr += e.Data + "\r\n";
            });

            p.BeginOutputReadLine();
            p.BeginErrorReadLine();

            p.WaitForExit();

            p.Close();

            return "" + (returnOutput ? outStr : "") + (returnError ? errStr : "");
        }
    }

0 个答案:

没有答案