Solved

Run .exe from c#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

17 Experts available now in Live!

Get 1:1 Help Now