// Get the full file path
String strfilepath = batpath; // obtain the full path name of the BAT file.
// Create the processinfo object
System. Diagnostics. processstartinfo psi = new system. Diagnostics. processstartinfo ("cmd.exe"); // start cmd.exe
PSI. useshellexecute = false;
PSI. redirectstandardoutput = true;
PSI. redirectstandardinput = true;
PSI. redirectstandarderror = true;
PSI. workingdirectory = "E: \ work" // sets the working directory of cmd.exe.
// Start the process
System. Diagnostics. Process proc = system. Diagnostics. process. Start (PSI); // start
// Open the batch file for reading
System. Io. streamreader STRM = system. Io. file. opentext (strfilepath); // read the BAT file
// Attach the in for writing
System. Io. streamwriter sin = Proc. standardinput;
// Write each line of the batch file to standard input
While (STRM. Peek ()! =-1)
{
Sin. writeline (STRM. Readline (); // write
}
STRM. Close ();
// Exit cmd. exe
Sin. writeline ("Del" + strfilepath); // Delete bat after execution
Sin. writeline ("exit ");
// Close the process
Proc. Close ();
// Close the IO streams;
Sin. Close ();