473,748 Members | 9,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Launch another application from within C# Winforms application

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.Diagnost ics.Process p = new Process();
p.StartInfo.Red irectStandardOu tput=false;
p.StartInfo.Fil eName=fileToLau nch;
p.StartInfo.Use ShellExecute=fa lse;
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
5 32739
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:
ProcessStartInf o procInfo=new ProcessStartInf o("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.Diagnost ics.Process p = new Process();
p.StartInfo.Red irectStandardOu tput=false;
p.StartInfo.Fil eName=fileToLau nch;
p.StartInfo.Use ShellExecute=fa lse;
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
Excellent Rakesh

Thanks for your pointer, I will play with this.

Grant

su************* @hotmail.com (GrantS) wrote in message news:<69******* *************** ****@posting.go ogle.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.Diagnost ics.Process p = new Process();
p.StartInfo.Red irectStandardOu tput=false;
p.StartInfo.Fil eName=fileToLau nch;
p.StartInfo.Use ShellExecute=fa lse;
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
> 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:
ProcessStartInf o procInfo=new ProcessStartInf o("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.Diagnost ics.ProcessStar tInfo notepadLog = new
System.Diagnost ics.ProcessStar tInfo("notepad. exe", "c:\\myLogFile. xml")

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

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

System.Diagnost ics.Process.Sta rt("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 ProcessStartInf o
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:
ProcessStartI nfo procInfo=new ProcessStartInf o("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.Diagnost ics.ProcessStar tInfo notepadLog = new
System.Diagnost ics.ProcessStar tInfo("notepad. exe", "c:\\myLogFile. xml")

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

Application.Run (notpadLog) ?

Nov 16 '05 #5
> System.Diagnost ics.Process.Sta rt("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 ProcessStartInf o
object to the Start method (it has a few overloads). Hope that helps.


That works great! Thanks!

I also tried:

System.Diagnost ics.ProcessStar tInfo notepadLog = new
System.Diagnost ics.ProcessStar tInfo("notepad. exe", "c:\\myLogFile. xml");

System.Diagnost ics.Process.Sta rt(notepadLog);

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

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

Similar topics

2
2085
by: Mahesh Kumar.R | last post by:
I'm into designing an application in winforms but in near future my client may request the same thing in webforms. so (1) what are all the design guidelines and ways are there to migrate easily in future (winforms -> weforms)...? (2) how can i design my application which can be accessed in both winforms and webforms by not writing much of code for the same business logic. ? (3) which is the cost effective method ? Please guide me to...
1
1864
by: Chris | last post by:
Hi Everyone, I have a backup application I'm working on that saves backups with an extension of .ABF. I have figured out how to make the association change with PInvoke/shell32, but would like some advice on how to handle the file passed as an arguement to my WinForms application. I was thinking about changing the application to a console application with
2
1565
by: panuvin | last post by:
Hello all, I'm developing a rather simple Winforms application written in C# using MS Visual Studio.NET. The application uses a MS Access database as the backend database. The application is going to be installed in a variety of different environments; some will have several PCs with the app installed with a centralized database, while others will have a single install with the database residing in the same folder as the application. For...
8
16948
by: Andrus | last post by:
I'm creating C# WinForms client-server database application. This application reads data from PostgreSQL server using npgsql Dataadapter and DataReader classes and stores data mostly in Datasets and sometimes in business object properties. A lot of lookup tables (payment terms, currency list etc) are static. Currently application reads them from server when new window is opened over TCP connection This makes application slow.
3
4682
by: =?Utf-8?B?Y2hlbmRyaWNrcw==?= | last post by:
I have a C# winforms application that makes periodic web service calls in background thread to my web service server. These calls work fine almost all the time but on rare occassions the web service method call will never return and the entire application will freeze, even though the call is being made on its own background thread, not the main UI thread. Does anyone know any reason why a particular web service method call would cause my...
6
5660
by: Paulers | last post by:
Hello, I am trying to manipulate a console based application from another application for example I need to launch the console application, provide it input and take the output from the console application and use it within my application. Is this possible with vb.net? If so could someone point me in the right direction. Thank you :)
4
6354
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
Visual Studio 2005, C# WinForms application: Here’s the question: How can I increase the standard 1 MB stack size of the UI thread in a C# WinForms application? Here’s why I ask: I’ve inherited some code that at the view (User Interface) layer kicks off a background worker thread. At the service layer (think CAB service layer), there’s quite a lot of the following:
4
4690
by: Andrus | last post by:
For winforms application with multiple related forms it is reasonable to create Linq database context object in start of application. Context object is released only when application exits. So connection to database may remain open for all application run time. For such a long time, some routers close connection. This causes Connection is broken error in application. How to fix this ?
1
2290
by: Susan Harris | last post by:
I have a Windows (NT) service developed in .NET 3.5 (VS2008). I want this service to log messages to a WinForms application that will display it's progress to the user. It has to run under Vista, so I can't use an interactive service. The monitoring application will just display a list of these log entries as they arrive. I'd like to use WCF (using it to consume a third party web service already). However, I can't fnd any examples that...
2
2737
by: Johnny Jörgensen | last post by:
OK, I have to do a Winforms application (C# or VB doesn't matter - that's not the important point here) that interacts with a database on a web server using an ASP.NET web service. I've done a lot of WinForms programming, but never Web Services. Got a book about it but that one only talks about how to use the web service from ASP.NET web applications. I assume it's pretty much the same from a windows forms app that I have to add a web...
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.