2

If I try to open an image file, or video, or website by calling Process.Start(filepath) directly, then it will typically succeed. However, the return value of Process.Start will sometimes be null. (As discussed here)

I need to know the associated process's id so that I can retrieve it later and close it if necessary. (Use case: User opens an image file using my program, and would like to close it using my program) However, it's kind of hard to retrieve the process id of a process that returns null :P

Any suggestions on how I should go about this, other than maybe specifying directly which program to use for each type of file we may encounter?

Community
  • 1
  • 1
DTI-Matt
  • 2,065
  • 9
  • 35
  • 60
  • 2
    What would you want to do if opening the image/video/whatever didn't start a *new* process, but just opened it in an existing one? I'd be pretty miffed if a long-running process which was still useful with *other* files suddenly closed... – Jon Skeet Aug 22 '12 at 16:56
  • That's not the purpose of this software though. If you're creating an image in this way, it's specifically because you want it opened separate from any other image viewer / process currently running. If you wanted simply to change the image, you could do so directly by interacting with the OS. (Basically, business rules) – DTI-Matt Aug 22 '12 at 17:53

1 Answers1

1

You have to specify directly which program to use to get the id of the process. I can imagine you can ask the os what program to use for each extensions as the os has a list of those.

Orn Kristjansson
  • 3,435
  • 4
  • 26
  • 40
  • Would this depend on Registry Keys? That's all I can seem to find using Google. Otherwise everyone says to just use Process.Start, but they obviously don't need all the same info I do. EDIT: Found this, which I think might solve it, but will be sorta messy. :( http://stackoverflow.com/a/162371/1233949 – DTI-Matt Aug 22 '12 at 17:47