110,533
社区成员
发帖
与我相关
我的任务
分享
//生成批处理文件用于重启程序
string bat=Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"update.bat");
if (File.Exists(bat))
File.Delete(bat);
using(StreamWriter sw=new StreamWriter(bat,true))
{
sw.WriteLine("@echo off");
sw.WriteLine(":find");
FileInfo appexe = new FileInfo(Application.ExecutablePath);
sw.WriteLine(string.Format("tasklist|find \"{0}\" ||goto next", appexe.Name));
sw.WriteLine("goto find");
sw.WriteLine(":next");
foreach (string name in okfiles)
{
sw.WriteLine(string.Format("copy update\\{0} {1} /y",name,name));
}
sw.WriteLine("start "+Application.ExecutablePath);
sw.WriteLine("del %0");
sw.WriteLine("exit");
}
System.Diagnostics.Process.Start(bat);
Environment.Exit(0);
System.IO.StreamWriter sw = null;
try
{
sw = new System.IO.StreamWriter(@"d:\data.dat", true);
for (int i = 0; i < 10; i++)
{
sw.WriteLine(String.Format("Item {0}.", i));
}
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw.Close();
sw.Dispose();
}