Tag: 进程

如何在C#中正确设置进程WorkingDirectory

在设置进程时,似乎我没有以正确的方式使用该变量WorkingDirectory。 我得到了错误(有一个问题) ApplicationName =’Test.exe’,CommandLine =’/ d = 1’,CurrentDirectory =’C:\ Users \ mb \ Desktop \ Integration \ Tests \ dailyTest \ dailyTest \ bin \ Debug \ Stress’,Native error =系统不能找到指定的文件。 但是在Stress文件夹中,我确实有Test.exe ..我真的没有得到这个含义。 代码如下(注意我用直接字符串内容替换变量以便更好地理解)。 Process proc = new System.Diagnostics.Process(); proc.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + “\\” + “Stress”); proc.StartInfo.FileName = “Test.exe”; proc.StartInfo.Arguments = “/d=1”; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput […]

如何使用C#更改命令提示符中的目录位置?

我通过以下代码使用C#成功打开了命令提示符窗口。 Process p = new Process(); p.StartInfo.FileName = “cmd.exe”; p.StartInfo.WorkingDirectory = @”d:\pdf2xml”; p.StartInfo.WindowStyle = ProcessWindowStyle.Normal; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardInput = true; p.Start(); p.StandardInput.WriteLine(@”pdftoxml.win32.1.2.7 -annotation “+filename); p.StandardInput.WriteLine(@”cd D:\python-source\ds-xmlStudio-1.0-py27″); p.StandardInput.WriteLine(@”main.py -i example-8.xml -o outp.xml”); p.WaitForExit(); 但是,我也通过命令来更改目录。 问题: 如何更改目录位置? Cmd提示将在打开后始终显示… 请指导我摆脱这些问题……

编码UTF8 C#进程

我有一个处理vbscript并生成输出的应用程序。 private static string processVB(string command, string arguments) { Process Proc = new Process(); Proc.StartInfo.UseShellExecute = false; Proc.StartInfo.RedirectStandardOutput = true; Proc.StartInfo.RedirectStandardError = true; Proc.StartInfo.RedirectStandardInput = true; Proc.StartInfo.StandardOutputEncoding = Encoding.UTF8; Proc.StartInfo.StandardErrorEncoding = Encoding.UTF8; Proc.StartInfo.FileName = command; Proc.StartInfo.Arguments = arguments; Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //prevent console window from popping up Proc.Start(); string output = Proc.StandardOutput.ReadToEnd(); string error = […]

在c#中不断读取控制台流

我想在c#中读取cmd的连续输出流。 我知道我可以重定向标准输出流并读取它。 以下是代码: System.Diagnostics.ProcessStartInfo pi= new System.Diagnostics.ProcessStartInfo(ProgramPATH,Params); pi.RedirectStandardOutput = true; pi.UseShellExecute = false; pi.CreateNoWindow = true; System.Diagnostics.Process proc= new System.Diagnostics.Process(); proc.StartInfo = pi; proc.Start(); string result = proc.StandardOutput.ReadToEnd(); 但这会立即产生整个输出。 如果我用-t参数发出ping命令怎么办? 我如何不断阅读这个流?

选中“性能”选项卡调用Windows任务管理器

我目前正在使用WPF中的单击事件调用Windows任务管理器。 该事件只执行’Process.Start(“taskmgr”)。 我的问题是,有没有办法在流程开始/显示时选择任务管理器中的哪个选项卡? 我希望在引发click事件时自动选择“性能”选项卡。 谢谢您的帮助。

如何从ServiceController确定Windows.Diagnostics.Process

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

启动新流程并终止当前流程

我想从当前执行进程A.exe启动一个新进程B.exe。 一旦B.exe启动,我想杀死A.exe(当前正在执行的进程)。 虽然我可以开始B.exe我无法关闭我当前的过程,即A.exe。 我使用的代码是: //Start the BT Setup Process ProcessStartInfo startInfo = new ProcessStartInfo(@”C:\TEST\B.exe”); Process.Start(startInfo); //Terminate the FSA Process[] myProcess = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName); foreach (Process process in myProcess) { process.CloseMainWindow(); //all the windows messages has to be processed in the msg queue //hence call to Application DoEvents forces the MSG Application.DoEvents(); }

Process.Kill()vs Process.Start(“taskkill”,…)

我有一个小的C#安装程序应用程序,我想杀死一个进程。 使用中是否有任何优点/差异 Process[] procs = Process.GetProcessesByName(“[taskname]”); foreach (Process p in procs) { p.Kill(); } VS Process.Start(“taskkill”, “/F /IM [taskname].exe”); 我在某处读到使用“taskkill”仅在XP(和更高版本)中可用,那么是否会使Process.Kill()成为更安全的选项?

如果我用.Kill()杀死System.Diagnostics.Process,我是否还需要调用.Close()?

使用C#4.0,我创建了一个System.Diagnostics.Process ,我希望它能够花费很短的时间来运行。 如果由于某种原因,该过程在一段时间后没有退出(例如,我已经调用.WaitForExit(timeout)并且返回值为false ),我需要清理。 我已经决定在这种特殊情况下使用.Kill()是安全的(没有数据结构我担心会破坏)。 鉴于此设置,我是否还需要调用Process的.Close()方法? 如果是这样,我应该在.Kill()之前或之后调用.Close() .Kill()吗?

运行没有.exe扩展名的外部应用程序

我知道如何在C# System.Diagnostics.Process.Start(executableName);运行外部应用程序System.Diagnostics.Process.Start(executableName); 但是,如果我想运行的应用程序具有Windows无法识别为可执行文件扩展名的扩展名。 就我而言,它是application.bin 。