如何关闭从C#又是另一个流程 [英] How to Close another Process from c#

查看:118
本文介绍了如何关闭从C#又是另一个流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从C#应用程序关闭另一个程序(Windows Media编码器),到目前为止,我可以做到这一点:

I need to close another Process (Windows Media Encoder) from a C# Application ,and so far i can do it with:

Process.GetProcessesByName("wmenc.exe")[0].CloseMainWindow();



但是,如果Media Encoder应用程序的流或录制时显示退出对话框:

But if the Media Encoder Application is Streaming or Recording it shows a Dialog on exit:

你确定要停止编码?

那么,有没有办法回答,或从代码点击Yes按钮?

So is there a way to answer or click Yes button from Code?


许多用户都使用过程.kill(),但是这是不是一种选择,因为 Process.Kill(); 将终止 Windows Media编码器立即和 Windows Media编码器才会完成其写入文件,这迫使我重新索引视频文件。所以没有我不能使用Process.Kill();

Many users are answering with Process.kill() ,but that is not an Option ,because Process.Kill(); will Terminate Windows Media Encoder immediately ,and Windows Media Encoder will not Finalize the File which is Writing ,which forces me to Reindex the Video File .So no i cannot use Process.Kill();

推荐答案

下面是一个SO后,询问和解答的如何控制其他应用程序的.NET 的。接受答案仅使用四行代码来获得一个窗口,并发送一个按键在该窗口中的特定按钮。我想,这可能是你最好的选择这里干净关闭应用程序。

Here's an SO post which asks and answers how to control other applications from .NET. The accepted answer uses just four lines of code to get a window and send a key press to a particular button in that window. I think that may be your best bet here for cleanly closing the application.

这篇关于如何关闭从C#又是另一个流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆