如何从 C# 关闭另一个进程
我需要从 C# 应用程序关闭另一个进程(Windows Media Encoder),到目前为止我可以这样做:
Process.GetProcessesByName("wmenc.exe")[0].CloseMainWindow();
但是如果 Media Encoder 应用程序正在流式传输或录制,它会在退出时显示一个对话框:
“您确定要停止编码吗?”
那么有没有办法从代码中回答或单击“是”按钮?
[编辑] 许多用户使用 Process.kill()
进行回答,但这不是一个 Option ,因为 Process.Kill();
将终止 Windows Media Encoder 立即,并且 Windows Media Encoder 将不会最终确定正在写入的文件,这迫使我重新索引视频文件。所以不,我不能使用 Process.Kill();
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();
But if the Media Encoder Application is Streaming or Recording it shows a Dialog on exit:
"Are you sure you want to stop encoding?"
So is there a way to answer or click Yes button from Code?
[Edit]
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
迭代 ProcessModule.filename 触发了“访问被拒绝”异常,但是以下代码工作正常。
Iterating through ProcessModule.filename triggered "Access denied" exception, however the following code worked fine.