Computer Hope
Software => Computer programming => Topic started 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.
-
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:
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 ^^
-
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. :)