?
Solved

Run .exe from c#

Posted on 2013-12-29
4
Medium Priority
?
343 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 44

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 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