How do I run an external program like Notepad or Calculator via a C# program?
-
4Welcome to Stack Overflow. I think it's safe to assume that English is your second language. To increase your chances of getting an answer, I would re-write the question title to say "How to open an external program from a C# program?". Also is it a Console App, Winforms, Web(hopefully not)? Provide a little more information, and make sure you check out the Stack Overflow FAQ.Marko– Marko2010-07-04 05:09:10 +00:00Commented Jul 4, 2010 at 5:09
-
@Michael I assume hw is simply how.Mathias– Mathias2010-07-04 05:11:18 +00:00Commented Jul 4, 2010 at 5:11
-
2Possible duplicate of How do I start a process from C#?Gustavo Mori– Gustavo Mori2016-11-09 00:27:14 +00:00Commented Nov 9, 2016 at 0:27
Add a comment
|
4 Answers
Maybe it'll help you:
using(System.Diagnostics.Process pProcess = new System.Diagnostics.Process())
{
pProcess.StartInfo.FileName = @"C:\Users\Vitor\ConsoleApplication1.exe";
pProcess.StartInfo.Arguments = "olaa"; //argument
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pProcess.StartInfo.CreateNoWindow = true; //not diplay a windows
pProcess.Start();
string output = pProcess.StandardOutput.ReadToEnd(); //The output result
pProcess.WaitForExit();
}
Comments
Hi this is Sample Console Application to Invoke Notepad.exe ,please check with this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Demo_Console
{
class Program
{
static void Main(string[] args)
{
Process ExternalProcess = new Process();
ExternalProcess.StartInfo.FileName = "Notepad.exe";
ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
ExternalProcess.Start();
ExternalProcess.WaitForExit();
}
}
}