Solved

Run .exe from c#

Posted on 2013-12-29
4
323 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
4 Comments
 
LVL 74

Accepted Solution

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

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 200 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now