我正在尝试将文件从Windows临时文件复制到“Program Files”目录,在我的安装程序中使用C#代码作为自定义操作,但由于权限不足,我不能。
我尝试创建延迟自定义操作,但现在false
会为现有文件返回 [CustomAction]
public static ActionResult Save(Session session) // immediate
{
try
{
string toBackup = = "C:\test.txt";
string backup = Path.ChangeExtension(Path.GetTempFileName(), Path.GetExtension(toBackup));
File.Copy(toBackup, backup);
session["BAK_PATH"] = backup;
return ActionResult.Success;
}
catch(Exception e)
{
return ActionResult.Failure;
}
}
[CustomAction]
public static ActionResult Restore(Session session) // Deferred action
{
try
{
string INSTALLDIR = session["INSTALLDIR"];
string target = Path.Combine(INSTALLDIR, "myfile.txt");
string backup = session.CustomActionData["BakPath"]; // <- correct value
File.Copy(backup, target); // backup doesn't exist
return ActionResult.Success;
}
catch (Exception e)
{
return ActionResult.Failure;
}
}
。我做错了什么?
理想情况下,我希望有2个即时自定义操作...
{{1}}