草庐IT

c# - 重定向进程输出 C#

我想将进程的标准输出重定向到一个字符串以供以后解析。我还希望在进程运行时在屏幕上看到输出,而不仅仅是在运行完成时。这可能吗? 最佳答案 使用RedirectStandardOutput.来自MSDN的示例://Startthechildprocess.Processp=newProcess();//Redirecttheoutputstreamofthechildprocess.p.StartInfo.UseShellExecute=false;p.StartInfo.RedirectStandardOutput=true;p.St

c# - Process.Start() 和 PATH 环境变量

我有以下简单的C#应用程序,它只是尝试启动“jconsole.exe”,它在我的机器上位于C:\Programs\jdk16\bin中。usingSystem;usingSystem.Diagnostics;namespacednet{publicclassdnet{staticvoidMain(string[]args){try{Process.Start("jconsole.exe");Console.WriteLine("Success!");}catch(Exceptione){Console.WriteLine("{0}Exceptioncaught.",e);}}}}如果我

c# - 在 Azure Function 中运行 .exe 可执行文件

我有可执行文件abcd.exe(它包含/合并了许多.dll)。是否可以为abcd.exe创建AzureFunctions并在AzureCloudFunctions中运行它?abcd.exe应用程序:System.Diagnostics.Processprocess=newSystem.Diagnostics.Process();System.Diagnostics.ProcessStartInfostartInfo=newSystem.Diagnostics.ProcessStartInfo();startInfo.WindowStyle=System.Diagnostics.Proc

c# - 如何从 ServiceController 确定 Windows.Diagnostics.Process

这是我的第一篇文章,所以让我先打个招呼吧!我正在编写一个Windows服务来监视同一台服务器上许多其他Windows服务的运行状态。我想扩展应用程序以打印服务的一些内存统计信息,但我无法弄清楚如何从特定的ServiceController对象映射到其关联的Diagnostics.Process对象,我认为我需要确定内存状态。我发现了如何从ServiceController映射到原始图像名称,但我正在监视的许多服务都是从同一图像启动的,因此这不足以确定进程。有谁知道如何从给定的ServiceController获取Process对象?也许通过确定服务的PID?或者是否有人对此问题有其他解

c# - Process.Start ("IEXPLORE.EXE") 在启动后立即触发 Exited 事件。为什么?

我在xp中安装IE8时遇到一个奇怪的问题。我试图在c#中使用System.Diagnostics.Process.Start方法启动IE。我需要捕获IE的退出事件并进行一些操作。但我最终遇到了一个相当奇怪的问题,即IE在启动后立即触发exited事件。这是示例代码ProcessobjProcess=Process.Start("IEXPLORE.EXE","http://google.com");if(objProcess!=null){objProcess.EnableRaisingEvents=true;objProcess.Exited+=newEventHandler(myPr

c# - "StandardOut has not been redirected or the process hasn' t started yet”在 C# 中读取控制台命令输出时

感谢@user2526830提供的代码。基于该代码,我在程序中添加了几行,因为我想读取SSH命令的输出。下面是我的代码,它在while行出错StandardOuthasnotbeenredirectedortheprocesshasn'tstartedyet.我想要实现的是,我想将ls的输出读入一个字符串。ProcessStartInfostartinfo=newProcessStartInfo();startinfo.FileName=@"f:\plink.exe";startinfo.Arguments="-sshabc@x.x.x.x-pwabc123";Processproce

c# - Process.Exited 并不总是触发

如果我运行以下代码:ProcessmyProcess=newSystem.Diagnostics.Process();myProcess.StartInfo.FileName="notepad.exe";myProcess.EnableRaisingEvents=true;myProcess.Exited+=newSystem.EventHandler(Process_OnExit);myProcess.Start();publicstaticvoidProcess_OnExit(objectsender,EventArgse){//Deletethefileonexit}当我退出记事

c# - 启动进程的服务不会显示 GUI C#

嘿,我正在尝试获取服务来启动我的程序,但它没有显示GUI。该过程开始但未显示任何内容。我已尝试启用“允许服务与桌面交互”,但仍然无法正常工作。我的程序是一个计算机锁定装置,用于阻止未经授权的用户访问计算机。我正在运行带有64位操作系统的Windows7。这是我的服务代码:protectedoverridevoidOnStart(string[]args){Processp=newProcess();p.StartInfo.FileName="notepad.exe";p.Start();FileStreamfs=newFileStream(@"C:\Users\David\Docume

c# - 获取另一个进程的窗口状态

如何获取正在运行的另一个进程的窗口状态(最大化、最小化)?我试过用这个:Process[]procs=Process.GetProcesses();foreach(Processprocinprocs){if(proc.ProcessName=="notepad"){MessageBox.Show(proc.StartInfo.WindowStyle.ToString());}}但是如果进程是Maximized或Minimized,它会返回Normal。如何解决这个问题? 最佳答案 您需要通过P/Invoke使用Win32来检查另一

c# - 电子邮件删除附件后,错误 "The process cannot access the file because it is being used by another process."

我正在做一个电子邮件表单。电子邮件有附件,并在附加文件后发送电子邮件。接下来需要从服务器删除文件。当我试图获取文件时,它给了我主题错误。我什至在删除文件之前调用了GC.Collect(),但错误仍然存​​在。我删除文件的代码是:privatevoidDeleteFiles(DataTabledt){GC.Collect();String[]sAttachments=newString[dt.Rows.Count];try{sAttachments=newString[dt.Rows.Count];for(Int32J=0;J要将文件附加到电子邮件,我的代码是:oMess.Subject