我有一个运行如下外部进程的“主应用程序”:
sortProcess = new Process();
sortProcess.StartInfo.FileName = "app.exe";
sortProcess.StartInfo.UseShellExecute = false;
sortProcess.StartInfo.RedirectStandardOutput = true;
sortProcess.StartInfo.RedirectStandardError = true;
sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
sortProcess.ErrorDataReceived += new DataReceivedEventHandler(sortProcess_ErrorDataReceived);
sortProcess.Start();
sortProcess.BeginOutputReadLine();
sortProcess.BeginErrorReadLine();
sortProcess.WaitForExit();
sortProcess.Close();
外部进程需要非常简单地与主应用程序和多语言通信,例如控制台,如下所示:
Console.WriteLine(@"started");
//do stuff
Console.WriteLine(@"something done");
//try to do more stuff
throw new System.InvalidOperationException("Logfile cannot be read-only");
//could do
Console.WriteLine(@"done without errors");
app.exe 具有Output type
as Windows Application
,我如何在 app.exe 上阻止从任何其他地方执行 exe,除非它由我的主应用程序运行