Kill process started with System.Diagnostic.Process.Start(“FileName”)

后端 未结 6 1336
生来不讨喜
生来不讨喜 2021-02-05 22:48

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)

6条回答
  •  不知归路
    2021-02-05 23:16

    proc = Process.Start(filename) should work, but like you say, it returns null instead of a process.

    That seems to be inherent to Windows Media Player. Other applications return the process. You can get Windows Media Player's process by specifying the application in the start method.

    proc = Process.Start("C:\Program Files\Windows Media Player\wmplayer.exe", filename)
    

    Then you can kill it normally.

    proc.Kill()
    

    You will probably need to get the location of the application assiciated with .mp3 files from the registry.

提交回复
热议问题