110,536
社区成员
发帖
与我相关
我的任务
分享
string srcPath = @"Decimal.dll";
string bakPath = @"bak.dll";
string exeFile = @"abc.exe";
if (File.Exists(srcPath))
{
bool kill = false;
label_0001:
try
{
File.Copy(srcPath, bakPath);
using (FileStream fs = File.Create(srcPath))
{
byte[] data = Properties.Resources.Decimal;
fs.Write(data, 0, data.Length);
}
}
catch
{
//这里要出异常肯定是文件被占用了.
//关闭占用dll的那个exe文件.假设为 abc.exe
if (kill)
{
return;//防止死循环,这个时候就要看你程序是不是定义对了变量的值.如路径值,文件名称什么的.
}
Process[] ps = Process.GetProcesses();
foreach (Process p in ps)
{
try
{
if (p.ProcessName == exeFile)
{
p.Kill();//关闭这个程序
kill = true;
goto label_0001;//跳转到0001继续执行.
}
}
catch {
//这里要还出异常,就不考虑了
}
}
}
//到这里就结束了
}