By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 739 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Launch another application from within C# Winforms application

P: n/a
Hi
I am trying to use ShellExecute to launch an application to display a
certain file.

The variation on the theme is that I need to be able to specify the
application to launch and not simply pass the file name (which will
then result in the application associated with the file extension to
launch). I want to prevent the application registered in the system as
being associated with the file extension from opeing the file.

For instance, if MSPaint is associated with "*.bmp" file on my system
but I want to programatically open a file (also having a "*.bmp"
extension) with, say, Photoshop, how can I achieve this?

So far, I am using:

System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.FileName=fileToLaunch;
p.StartInfo.UseShellExecute=false;
p.Start();
p.WaitForExit();
p.Dispose();

But this does not permit me to nominate the application I wish to use
to display the file.

Hope someone can assist.

Thanks

Grant
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

If you know the application exe name (and in some cases the path) you need
to launch, then it's usually only a case of passing the document to be opened
as an argument to ProcessInfo.
For eg:
ProcessStartInfo procInfo=new ProcessStartInfo("notepad", "c:\\a.txt");

Is this what you are looking for?

HTH,
Rakesh Rajan

"GrantS" wrote:
Hi
I am trying to use ShellExecute to launch an application to display a
certain file.

The variation on the theme is that I need to be able to specify the
application to launch and not simply pass the file name (which will
then result in the application associated with the file extension to
launch). I want to prevent the application registered in the system as
being associated with the file extension from opeing the file.

For instance, if MSPaint is associated with "*.bmp" file on my system
but I want to programatically open a file (also having a "*.bmp"
extension) with, say, Photoshop, how can I achieve this?

So far, I am using:

System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.FileName=fileToLaunch;
p.StartInfo.UseShellExecute=false;
p.Start();
p.WaitForExit();
p.Dispose();

But this does not permit me to nominate the application I wish to use
to display the file.

Hope someone can assist.

Thanks

Grant

Nov 16 '05 #2

P: n/a
Excellent Rakesh

Thanks for your pointer, I will play with this.

Grant

su*************@hotmail.com (GrantS) wrote in message news:<69**************************@posting.google. com>...
Hi
I am trying to use ShellExecute to launch an application to display a
certain file.

The variation on the theme is that I need to be able to specify the
application to launch and not simply pass the file name (which will
then result in the application associated with the file extension to
launch). I want to prevent the application registered in the system as
being associated with the file extension from opeing the file.

For instance, if MSPaint is associated with "*.bmp" file on my system
but I want to programatically open a file (also having a "*.bmp"
extension) with, say, Photoshop, how can I achieve this?

So far, I am using:

System.Diagnostics.Process p = new Process();
p.StartInfo.RedirectStandardOutput=false;
p.StartInfo.FileName=fileToLaunch;
p.StartInfo.UseShellExecute=false;
p.Start();
p.WaitForExit();
p.Dispose();

But this does not permit me to nominate the application I wish to use
to display the file.

Hope someone can assist.

Thanks

Grant

Nov 16 '05 #3

P: n/a
> If you know the application exe name (and in some cases the path) you need
to launch, then it's usually only a case of passing the document to be opened as an argument to ProcessInfo.
For eg:
ProcessStartInfo procInfo=new ProcessStartInfo("notepad", "c:\\a.txt");


I want to let users view an XML log file with notepad, so I tried something
almost identical to your example:

System.Diagnostics.ProcessStartInfo notepadLog = new
System.Diagnostics.ProcessStartInfo("notepad.exe", "c:\\myLogFile.xml")

But nothing happens - am I missing something? .. do I need something like:

Application.Run(notpadLog) ?
Nov 16 '05 #4

P: n/a
Try this:

System.Diagnostics.Process.Start("notepad.exe", "C:\\myLogFile.xml");

That should launch the application for you and return Process object for
you to work with. Then again you can also pass your ProcessStartInfo
object to the Start method (it has a few overloads). Hope that helps.

Have A Better One!

John M Deal, MCP
Necessity Software

deko wrote:
If you know the application exe name (and in some cases the path) you need
to launch, then it's usually only a case of passing the document to be


opened
as an argument to ProcessInfo.
For eg:
ProcessStartInfo procInfo=new ProcessStartInfo("notepad", "c:\\a.txt");

I want to let users view an XML log file with notepad, so I tried something
almost identical to your example:

System.Diagnostics.ProcessStartInfo notepadLog = new
System.Diagnostics.ProcessStartInfo("notepad.exe", "c:\\myLogFile.xml")

But nothing happens - am I missing something? .. do I need something like:

Application.Run(notpadLog) ?

Nov 16 '05 #5

P: n/a
> System.Diagnostics.Process.Start("notepad.exe", "C:\\myLogFile.xml");

That should launch the application for you and return Process object for
you to work with. Then again you can also pass your ProcessStartInfo
object to the Start method (it has a few overloads). Hope that helps.


That works great! Thanks!

I also tried:

System.Diagnostics.ProcessStartInfo notepadLog = new
System.Diagnostics.ProcessStartInfo("notepad.exe", "c:\\myLogFile.xml");

System.Diagnostics.Process.Start(notepadLog);

That works, too - but requires more typing...
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.