Computer Hope

Software => Computer programming => Topic started by: jet ved on December 17, 2008, 08:41:37 AM

Title: execute a .cmd file using C#
Post by: jet ved on December 17, 2008, 08:41:37 AM
Hi,
Can someone help me with the script for running a .cmd file using C# code. I know that there is a 'process' object which comes into picture.

Thanks,
jet.
Title: Re: execute a .cmd file using C#
Post by: hibyy on August 24, 2009, 01:07:36 PM
you know you can do more then just make a c# file run a cmd file but you can also make it do  cmd commands.
EXAMPLE:
Code: [Select]
using System.Runtime.InteropServices;
namespace Run
{
public class CMD
{
[DllImport("msvcrt.dll")]
public static extern int system(string cmd);
public static void Main()
{
system("Echo Hello");
system("pause");
}
}
}

If this helped please tell me ^^
Title: Re: execute a .cmd file using C#
Post by: BC_Programmer on August 24, 2009, 02:01:49 PM
Code: [Select]
        static void Main(string[] args)
        {
            System.Diagnostics.Process useprocess;
 
            useprocess = new System.Diagnostics.Process();
            useprocess.StartInfo.FileName="cmd.exe";
            useprocess.Start();

           
                   
        }

change the useprocess.StartInfo.FileName= line to reflect the batch file you want to run. :)