Solved

How to call external exe from C#?

Posted on 2004-08-06
6
4,172 Views
Last Modified: 2011-09-20
How can I call an external application from C#? I don't necessarily need to know anything about it after I launch it, I just need to launch it (although having the handle would be nice.). In VB6 I would have just used the SHELL command kind of like this:

SHELL("C:\Notepad.exe")

Does C# have an equivalent?
0
Comment
Question by:stat792
6 Comments
 
LVL 69

Expert Comment

by:Callandor
ID: 11738184
It's called Exec(cmdname, commandExecOption, variantIn, variantOut, handled)
0
 
LVL 69

Expert Comment

by:Callandor
ID: 11738187
Parameters
CmdName
The name of the command to execute.
ExecuteOption
A vsCommandExecOption constant specifying the execution options.
VariantIn
A value passed to the command.
VariantOut
A value passed back to the invoker Exec method after the command executes.
handled
True indicates that the command was implemented. False indicates it was not.
0
 
LVL 15

Expert Comment

by:Timbo87
ID: 11738414
using System.Diagnostics;
Process notepad = Process.Start("notepad.exe");

You can then monitor and control the process using the members of the Process class.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassTopic.asp
0
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.

 
LVL 9

Expert Comment

by:s_sansanwal
ID: 11741326
0
 
LVL 19

Expert Comment

by:Desp
ID: 11741975
just call
System.Diagnostics.Process.Start("notepad.exe");
0
 
LVL 7

Accepted Solution

by:
psdavis earned 125 total points
ID: 11754823
I go with the more difficult route.

            Process proc = new Process();

            proc.EnableRaisingEvents = false;
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.FileName = "osql";
            proc.StartInfo.Arguments = "-U sa -P test -d master -i test.sql -o vmsdblog.txt";
            proc.Start();
            proc.WaitForExit();
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

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!
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
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

16 Experts available now in Live!

Get 1:1 Help Now