473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get default application

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

Oct 6 '08 #1
4 2460
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();

"Allan Bredahl" <al***@bredahl.orgwrote in message
news:Oa**************@TK2MSFTNGP02.phx.gbl...
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
Oct 6 '08 #2
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

"Family Tree Mike" <Fa************@ThisOldHouse.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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();
Oct 6 '08 #3
Allan Bredahl wrote:
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/...indows-xp.html
You can convert the code to C# with:
http://www.developerfusion.com/tools.../vb-to-csharp/
the result seemed ok to me.

--

Teme64 @ http://windevblog.blogspot.com
Oct 7 '08 #4
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!!!");
}

"Allan Bredahl" <al***@bredahl.orgwrote in message
news:ej**************@TK2MSFTNGP05.phx.gbl...
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

"Family Tree Mike" <Fa************@ThisOldHouse.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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();
Oct 7 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Hahn | last post by:
Can someone point me in the right direction to tell windows to run the default email application, create a new message, and let me populate it with subject, body, and attachments? I've been...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
7
by: aDc | last post by:
Hello, I am getting some strange behavior with my ASP.NET application. Anytime I make a request to a page in the application the page_load for that page is fired as expected BUT then the...
2
by: Michael McGuire | last post by:
I have a very strange problem occurring on a couple of servers I have an ASP.NET application written in C# running on IIS 5.0 with Windows 2000 Server. This is the first ASP.NET application...
5
by: Ted Apollo | last post by:
When I develop my ASP.NET 1.1 application locally, the default form is always "WebForm1.aspx." However, when I post the same application to a web server, the default becomes "default.aspx." Why...
4
by: John Scott | last post by:
I want to be able to set some default values in my web application ....like..setting all strings to "" and all integers to int.MinValue....etc... I have a web application object that is based on...
1
by: i8mypnuts | last post by:
Could someone please help? I am using the 'defaultprt.zip' tool provided by Ken Getz to change the default printer via VBA code (code below). My problem is that once the default printer has been...
3
by: Anil Kumar Sharma | last post by:
Hello, I am working on C# using vs.net 2003. I have faced two interesting problems. 1. Dynamically setting Default Button: I created a form and used it in various contexts. On basis of the...
10
by: Brad Baker | last post by:
I have an asp.net/csharp application that requires a particular variable to work properly. This variable is usually passed via a query string in the URL when the application is first run but under...
3
by: LordHog | last post by:
Hello, How would I go about finding the default handler, let's say a text file (*.txt), then launch the default handler with the file as an argument? I had found how to launch an external...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.