Get default application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allan Bredahl

    #1

    Get default application

    Hi

    I'm having a little trouble with starting a Process via a filename like:

    Process _process = System.Diagnost ics.Process.Sta rt("c:\test.doc ");


    It works great, but I just cant get the process.Exited event to fire.


    It's just like the process dies and in this case Word is started in annother
    process.


    Therefore I need someway to control the Word process or alternatively
    someway to get the default application in windows for each filetype.


    ".doc" --"C:\Program Files\Microsoft Office\Office12 \winword.exe"
    ".txt" --"C:\Windows\Not epad.exe"

    and so on


    Because if I do this it works :

    Process _process = System.Diagnost ics.Process.Sta rt("C:\Program
    Files\Microsoft Office\Office12 \winword.exe", "c:\test.do c");



    Somebody have a heloing hand here ?

    Thanks in advance

    Allan

  • Family Tree Mike

    #2
    Re: Get default application

    You need to set the EnableRaisinigE vents property to true to be notified of
    ..Exited events. Normally I would do something like this:

    myProcess.Start Info.FileName = "c:\test.do c";
    myProcess.Start Info.Verb = "Open";
    myProcess.Start Info.CreateNoWi ndow = true;
    myProcess.Enabl eRaisingEvents = true;
    myProcess.Exite d += new EventHandler(my Process_Exited) ;
    myProcess.Start ();



    "Allan Bredahl" <allan@bredahl. orgwrote in message
    news:OaSWJZ$JJH A.5904@TK2MSFTN GP02.phx.gbl...
    Hi
    >
    I'm having a little trouble with starting a Process via a filename like:
    >
    Process _process = System.Diagnost ics.Process.Sta rt("c:\test.doc ");
    >
    >
    It works great, but I just cant get the process.Exited event to fire.
    >
    >
    It's just like the process dies and in this case Word is started in
    annother process.
    >
    >
    Therefore I need someway to control the Word process or alternatively
    someway to get the default application in windows for each filetype.
    >
    >
    ".doc" --"C:\Program Files\Microsoft Office\Office12 \winword.exe"
    ".txt" --"C:\Windows\Not epad.exe"
    >
    and so on
    >
    >
    Because if I do this it works :
    >
    Process _process = System.Diagnost ics.Process.Sta rt("C:\Program
    Files\Microsoft Office\Office12 \winword.exe", "c:\test.do c");
    >
    >
    >
    Somebody have a heloing hand here ?
    >
    Thanks in advance
    >
    Allan

    Comment

    • Allan Bredahl

      #3
      Re: Get default application

      Thanks

      But I forgot to write the myProcess.Enabl eRaisingEvents = true; line in my
      example.

      I actually did that.

      It works great with PDF files, jpg files etc. but when opening a doc file in
      Word, the process dies.


      /
      Allan

      "Family Tree Mike" <FamilyTreeMike @ThisOldHouse.c omwrote in message
      news:%23ctzuk$J JHA.3460@TK2MSF TNGP04.phx.gbl. ..
      You need to set the EnableRaisinigE vents property to true to be notified
      of .Exited events. Normally I would do something like this:
      >
      myProcess.Start Info.FileName = "c:\test.do c";
      myProcess.Start Info.Verb = "Open";
      myProcess.Start Info.CreateNoWi ndow = true;
      myProcess.Enabl eRaisingEvents = true;
      myProcess.Exite d += new EventHandler(my Process_Exited) ;
      myProcess.Start ();
      >
      >
      >

      Comment

      • Teme64

        #4
        Re: Get default application

        Allan Bredahl wrote:
        Hi
        >
        I'm having a little trouble with starting a Process via a filename like:
        >
        Process _process = System.Diagnost ics.Process.Sta rt("c:\test.doc ");
        >
        >
        It works great, but I just cant get the process.Exited event to fire.
        >
        >
        It's just like the process dies and in this case Word is started in
        annother process.
        >
        >
        Therefore I need someway to control the Word process or alternatively
        someway to get the default application in windows for each filetype.
        >
        >
        ".doc" --"C:\Program Files\Microsoft Office\Office12 \winword.exe"
        ".txt" --"C:\Windows\Not epad.exe"
        >
        and so on
        >
        >
        Because if I do this it works :
        >
        Process _process = System.Diagnost ics.Process.Sta rt("C:\Program
        Files\Microsoft Office\Office12 \winword.exe", "c:\test.do c");
        >
        >
        >
        Somebody have a heloing hand here ?
        >
        Thanks in advance
        >
        Allan
        Here's a VB.NET code to get default application:
        When you double click a file, Windows Explorer opens it with associated default application. Windows Explorer determines current default app...

        You can convert the code to C# with:
        Free online conversion utility to automatically convert your VB.NET code into C# - and straight back again.

        the result seemed ok to me.

        --

        Teme64 @ http://windevblog.blogspot.com

        Comment

        • Family Tree Mike

          #5
          Re: Get default application

          This code in a button on a form works for me. I don't know what to tell
          you...

          private void button1_Click(o bject sender, EventArgs e)
          {
          System.Diagnost ics.Process p = System.Diagnost ics.Process.Sta rt(@"c:\some
          folder\some.doc ");
          p.EnableRaising Events = true;
          p.Exited += new EventHandler(p_ Exited);
          }

          void p_Exited(object sender, EventArgs e)
          {
          MessageBox.Show ("Woah, Nelly!!!");
          }

          "Allan Bredahl" <allan@bredahl. orgwrote in message
          news:ejqJds$JJH A.1156@TK2MSFTN GP05.phx.gbl...
          Thanks
          >
          But I forgot to write the myProcess.Enabl eRaisingEvents = true; line in my
          example.
          >
          I actually did that.
          >
          It works great with PDF files, jpg files etc. but when opening a doc file
          in Word, the process dies.
          >
          >
          /
          Allan
          >
          "Family Tree Mike" <FamilyTreeMike @ThisOldHouse.c omwrote in message
          news:%23ctzuk$J JHA.3460@TK2MSF TNGP04.phx.gbl. ..
          >You need to set the EnableRaisinigE vents property to true to be notified
          >of .Exited events. Normally I would do something like this:
          >>
          > myProcess.Start Info.FileName = "c:\test.do c";
          > myProcess.Start Info.Verb = "Open";
          > myProcess.Start Info.CreateNoWi ndow = true;
          > myProcess.Enabl eRaisingEvents = true;
          > myProcess.Exite d += new EventHandler(my Process_Exited) ;
          > myProcess.Start ();
          >>
          >>
          >>
          >

          Comment

          Working...