Solved

Run .exe from c#

Posted on 2013-12-29
4
328 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 75

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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