Batch Files in C#

  • Thread starter Thread starter orekinbck
  • Start date Start date
O

orekinbck

Hi There


I have this batch file that I run at the end of each week:


Cleanmgr
Defrag C:
Echo y > y.txt
chkdsk C: /r < y.txt
shutdown -r


I would like to do the above but using C# code. I have been fiddling
around with Process but just cannot get it right, any help (and
examples) would be greatly appreciated.


Thanks In Advance
Bill
 
I would like to do the above but using C# code. I have been fiddling
around with Process but just cannot get it right, any help (and
examples) would be greatly appreciated.

You may write to file .bat (programmatically or by hand). And then run so
prepared file in C#.
**********************************
Process process = new Process();
process.EnableRaisingEvents = true;
process.StartInfo.FileName = "my.bat";
process.StartInfo.UseShellExecute = false;
try
{
process.Start();
process.WaitForExit();
}
catch
{
}
**********************************

HTH

RGDS PSG
 
Why? You have the batch file. You have a built-in task scheduler. There
really isn't a reason to write another program.
 
Why? A learning challenge more than anything else (I am aware of the
task scheduler and use it frequently)

Btw, thanks PSG. It is gr8 to know about process.WaitForExit(); as I
was struggling with processes starting before others had finished.


Cheers
Bill
 
Back
Top