Click here to Skip to main content
15,891,828 members
Articles / Programming Languages / C#

How to launch Windows applications (Notepad) / Call Batch files from a C#/.NET console application.

Rate me:
Please Sign up or sign in to vote.
3.88/5 (24 votes)
12 Apr 20052 min read 258.7K   2.2K   55  
How to launch a Windows application (Notepad) / Call Batch files from a C#/.NET console application.
using System;
using System.Diagnostics;

namespace CallBatchFile
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			Process p=null;
			try
			{
				string targetDir;
				targetDir = string.Format(@"C:\Temp\CallBatchFile\BatchFile");
				p= new Process();
				p.StartInfo.WorkingDirectory = targetDir;
				p.StartInfo.FileName = "MyBatchFile.bat";
				
				p.StartInfo.Arguments =  string.Format("C-Sharp Console application");
				p.StartInfo.CreateNoWindow = false;
				p.Start();
				p.WaitForExit();
			}
			catch (Exception ex)
			{
				Console.WriteLine("Exception Occurred :{0},{1}" ,ex.Message,ex.StackTrace.ToString());
			}
		
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Microsoft solution Developer since 1996. Worked on different technolgies including but not limited to Visual Studio .NET , ASP .NET , C# Visual C++ , MFC , COM , DCOM ,OLE.

Expertiesed on different industry sectors of software development such as system softwares (worked for Intel and Microsoft ),application softwares (Manufacturing,Financial,Security,Airline industry, Multimedia)


Site developer for religious community in his spare time http://www.trimbakeshwar.net







Comments and Discussions