【发布时间】:2013-06-09 21:20:08
【问题描述】:
这个 C# 程序使一个批处理文件运行它,然后应该删除该文件。当我运行程序时,如果最后一个 if 语句不存在,它会生成批处理文件并完美地执行它。但是对于最后一个 if 语句,它会创建文件并将其删除但不进行任何更改。
string batFile;
batFile = genBat(textBox1.Text);
string path = "C:\\Windows\\System32\\drivers\\etc\\blocksite.bat";
using (StreamWriter sw = new StreamWriter(path))
{
sw.WriteLine(@batFile);
sw.Close();
}
Process.Start(path);
if(File.Exists(path))
{
File.Delete(path)
}
【问题讨论】:
-
sw.WriteLine(@batFile); ???
-
batFile = genBat(textBox1.Text);是要写入批处理文件的字符串。 -
这很可爱,但是
@batfile? -
您无法通过代码执行的批处理文件是什么?您可以将以下行添加到批处理文件中:Del %0
-
@FJam:你不需要对像这样的普通变量使用
@运算符。
标签: c# batch-file