[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Run .exe from c#

Posted on 2013-12-29
4
Medium Priority
?
347 Views
Last Modified: 2014-01-27
Hello:

Is there a better way to run an executable from c#? The code below works fine. Just wondering the pros and cons of a script like this.

        System.Diagnostics.Process process = new System.Diagnostics.Process();
        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
        startInfo.FileName = "notepad.exe";
        process.StartInfo = startInfo;
        process.Start();

Open in new window

0
Comment
Question by:RecipeDan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1200 total points
ID: 39745253
The Process class is exactly how you execute external programs from within a .NET application.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39745276
Are you coing ASP? If you run this code from code behind, it will run on the server.
0
 
LVL 9

Assisted Solution

by:dexterrajesh
dexterrajesh earned 800 total points
ID: 39745589
hi... you need to call the dispose()\close() to free the resources or use the code block inside an using() block to handle the resources properly... e.g. like below;

using (var process = new Process())
{
    process.StartInfo.FileName = "notepad.exe";
    process.Start();
    process.WaitForExit();
}

hope this helps
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39745610
>>startInfo.FileName = "notepad.exe";

This assumes that there is an exe of that name in the paths that will be searched.  In other words if there is another exe with the same name then the program being started may NOT be the one you want to run.  You ought to supply the path to the exe as well to make certain.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question