杀死进程开始System.Diagnostic.Process.Start("文件名") [英] Kill process started with System.Diagnostic.Process.Start("FileName")

查看:113
本文介绍了杀死进程开始System.Diagnostic.Process.Start("文件名")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个应用程序,将执行操作的具体时间(很像Windows任务调度程序)。我目前使用的Process.Start(们),以启动该任务所需要的文件(或EXE)。

我通过调用一个文件(一个的.mp3)启动一个进程和过程开始WMP(因为它是默认的应用程序)。到目前为止,一切都很好。现在,我要杀死该进程。我知道这是正常行为的的Process.Start(字符串,字符串)返回在这种情况下,没有(空在C#)。

所以,我问我怎么可以关闭WMP,当我通过的Process.Start(字符串,字符串)??把它叫做

编辑:

请注意,我并​​没有直接用的Process.Start(打开WMP),这是我将运行过程中的行:

<大段引用> VB:Me._procs.Add(的Process.Start(Me._procInfo))

C#:this._procs.Add(的Process.Start(this._procInfo))

_procInfo是的ProcessStartInfo实例。 _procInfo.FileName是C:\路径\ myFile.mp3。这就是为什么WMP打开。在任何情况下,所有的启动()方法,除了例如,其中一个返回一个布尔值,返回任何结果(空在C#),因为WMP不能直接创建的过程中(请注意,WMP运行和歌曲确实起到)。

解决方案

不要做这种方式。

目前尚不清楚你的程序的意图是否还是起步与登记的MP3播放器,这可能是,比如,iTunes中。

始终与Windows Media Player推出'

如果你需要WMP,使用的Process.Start的完整路径到Windows Media Player。

如果您需要的临时用户的MP3播放器,你可以找到使用的此处显示的code。再次,启动过程,这个exe文件的路径,传递的MP3作为参数。<​​/ P>

I am trying to create an app that will perform actions on specific times (much like the Windows Task Scheduler). I am currently using Process.Start() to launch the file (or exe) required by the task.

I am initiating a process by calling a file (an .mp3) and the process starts WMP (since it is the default application). So far so good. Now I want to kill that process. I know that it is normal behavior for the Process.Start(string, string) to return nothing (null in C#) in this case.

So I am asking how can I close WMP when I called it through Process.Start(string, string)??

Edit:

Please note that I am not opening WMP directly with Process.Start() and this is the line with which I run the process:

VB: Me._procs.Add(Process.Start(Me._procInfo))

C#: this._procs.Add(Process.Start(this._procInfo))

_procInfo is a ProcessStartInfo instance. _procInfo.FileName is "C:\route\myFile.mp3". That is why WMP opens. In any case, all of the Start() methods, except for the instance-one which returns a boolean, return nothing (null in C#), because WMP is not the process that was directly created (please note that WMP is run and the song does play).

解决方案

Don't do it this way.

It's not clear whether the intent of your program is 'Always launch with Windows Media Player' or 'Launch with the registered MP3 player', which might be, say, iTunes.

If you need WMP, use Process.Start with the full path to windows media player.

If you need the registed MP3 player, you can find out the correct exe using the code shown here. Again, start the process with this exe path, passing the MP3 as a parameter.

这篇关于杀死进程开始System.Diagnostic.Process.Start(&QUOT;文件名&QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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