Get default application

A

Allan Bredahl

Hi

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

Process _process = System.Diagnostics.Process.Start("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\Notepad.exe"

and so on


Because if I do this it works :

Process _process = System.Diagnostics.Process.Start("C:\Program
Files\Microsoft Office\Office12\winword.exe", "c:\test.doc");



Somebody have a heloing hand here ?

Thanks in advance

Allan
 
F

Family Tree Mike

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

myProcess.StartInfo.FileName = "c:\test.doc";
myProcess.StartInfo.Verb = "Open";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.Start();
 
A

Allan Bredahl

Thanks

But I forgot to write the myProcess.EnableRaisingEvents = 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
 
T

Teme64

Allan said:
Hi

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

Process _process = System.Diagnostics.Process.Start("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\Notepad.exe"

and so on


Because if I do this it works :

Process _process = System.Diagnostics.Process.Start("C:\Program
Files\Microsoft Office\Office12\winword.exe", "c:\test.doc");



Somebody have a heloing hand here ?

Thanks in advance

Allan

Here's a VB.NET code to get default application:
http://windevblog.blogspot.com/2008/09/get-default-application-in-windows-xp.html
You can convert the code to C# with:
http://www.developerfusion.com/tools/convert/vb-to-csharp/
the result seemed ok to me.
 
F

Family Tree Mike

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

private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"c:\some
folder\some.doc");
p.EnableRaisingEvents = true;
p.Exited += new EventHandler(p_Exited);
}

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top