C# WinForms 应用程序 (.NET 4)
从组合(下拉)菜单中选择目录路径,然后将其包含在以下命令行语句中。
for %f in ("< path >\*.ocx" "< path >\*.dll") do regsvr32 /s "%f"
其中<path>是目录路径。
这执行得很好。我想检索注册成功消息(或错误),而用户不必在显示的弹出/消息框中单击确定一千次。显然,静音 (/s) 开关摆脱了弹出窗口。
在用户在屏幕上看到任何内容(除了应用程序本身)的情况下,检索结果的最佳方法是什么?
这就是我现在所拥有的,
public void reg_in_source_2()
{
ProcessStartInfo cmdStartInfo = new ProcessStartInfo();
cmdStartInfo.FileName = @"C:\Windows\System32\cmd.exe";
cmdStartInfo.RedirectStandardOutput = true;
cmdStartInfo.RedirectStandardError = true;
cmdStartInfo.RedirectStandardInput = true;
cmdStartInfo.UseShellExecute = false;
cmdStartInfo.CreateNoWindow = true;
Process cmdProcess = new Process();
cmdProcess.StartInfo = cmdStartInfo;
cmdProcess.ErrorDataReceived += cmd_Error;
cmdProcess.OutputDataReceived += cmd_DataReceived;
cmdProcess.EnableRaisingEvents = true;
cmdProcess.Start();
cmdProcess.BeginOutputReadLine();
cmdProcess.BeginErrorReadLine();
cmdProcess.StandardInput.WriteLine(@"for %%f in (""" + reference.source_folder + @"\*.ocx"" " + reference.source_folder + @"\*.dll"") do regsvr32 ""%%f""");
cmdProcess.StandardInput.WriteLine("exit");
cmdProcess.WaitForExit();
}
public void cmd_DataReceived(object sender, DataReceivedEventArgs e)
{
reference.cmd_replies.Add(e.Data);
}
public void cmd_Error(object sender, DataReceivedEventArgs e)
{
reference.cmd_replies_errors.Add(e.Data);
}